SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Create customer using FM 'SD_CUSTOMER_MAINTAIN_ALL'



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Thu Sep 18, 2008 11:19 am    Post subject: Create customer using FM 'SD_CUSTOMER_MAINTAIN_ALL' Reply with quote

Code:
FUNCTION z_bapi_customer_create.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" VALUE(I_KNA1) LIKE KNA1 STRUCTURE KNA1 OPTIONAL
*" VALUE(I_KNB1) LIKE KNB1 STRUCTURE KNB1 OPTIONAL
*" VALUE(I_KNVV) LIKE KNVV STRUCTURE KNVV OPTIONAL
*" EXPORTING
*" VALUE(E_KUNNR) LIKE KNA1-KUNNR
*" REFERENCE(O_KNA1) LIKE KNA1 STRUCTURE KNA1
*" REFERENCE(RETURN) LIKE BAPIRETURN1 STRUCTURE BAPIRETURN1
*" TABLES
*" T_XKNVI STRUCTURE FKNVI OPTIONAL
*" T_XKNB5 STRUCTURE FKNB5 OPTIONAL
*"----------------------------------------------------------------------
*
*-(1) initial routines ------------------------------------------------*
*
* (i) data declaration: fields, items, tables:
*

  DATA: subrc LIKE sy-subrc,
  credit_control_flag LIKE bapikna108-x_flag VALUE 'X',
  postflag LIKE wdl_flag-xflag.
*
* (ii) reset exporting data and sy-subrc
*
  CLEAR: return,
  sy-subrc.
*
* (iii) fill temporary interface data i_bapikna1_0x, i_bapikna10x
* (in the following: importing data unchanged, work only with
* temporary interface data)
*

*
* (iv) reset data of function kernel
*

  CLEAR: i_kna1,
  i_knb1,
  i_knvv.
  REFRESH:
* t_xknbk,
  t_xknvi,
* t_xknvk,
* t_xknvp,
  t_xknb5.
  .
*
*-(2) work routines ---------------------------------------------------*
*
* (i) call "check function"
*
*
* (ii) fill exporting data of "kernel function"
*
*
* (iii) call "kernel function" post synchron (postflag = X)
*

  i_kna1-land1 = 'BR'.
  i_kna1-name1 = 'Nome'.
  i_kna1-ort01 = 'Abaetetuba'.
  i_kna1-pstlz = '099999999'.
  i_kna1-regio = 'PA'.
  i_kna1-sortl = 'Conceito'.
  i_kna1-stras = 'Rua'.
  i_kna1-mcod1 = 'Nome'.
  i_kna1-mcod2 = 'Abaetetuba'.
  i_kna1-mcod3 = 'Sr.'.
  i_kna1-brsch = '01'.
  i_kna1-ktokd = '0021'.
  i_kna1-spras = 'P'.
  i_kna1-stcd2 = '999'.
  i_kna1-lzone = 'AC00000001'.
  i_kna1-stkzn = 'X'.
  i_kna1-txjcd = 'NN'.
  i_kna1-duefl = 'X'.
  i_kna1-civve = 'X'.
  i_kna1-brsch = 'AG05'.
  i_kna1-anred = 'Sr.'.

  i_knvv-vkorg = 'MY01'.
  i_knvv-vtweg = 'Z5'.
  i_knvv-spart = 'Z7'.
  i_knvv-versg = '1'.
  i_knvv-kalks = '1'.
  i_knvv-kdgrp = '02'.
  i_knvv-bzirk = 'CLIE'.
  i_knvv-pltyp = '02'.
  i_knvv-awahr = '100'.
  i_knvv-antlf = '9'.
  i_knvv-kzazu = 'X'.
  i_knvv-vsbed = '01'.
  i_knvv-perfk = '01'.
  i_knvv-waers = 'BRL'.
  i_knvv-ktgrd = '01'.
  i_knvv-vwerk = 'MY01'.
  i_knvv-vkgrp = 'LDA'.
  i_knvv-vkbur = 'MSOY'.
  i_knvv-kurst = '001S'.
  i_knvv-kabss = '0001'.
  i_knvv-kkber = 'SE01'.

  i_knb1-bukrs = '4169'.
  i_knb1-akont = '0011411000'.
  i_knb1-akont = '9999999999'.
  i_knb1-zwels = 'C'.
  i_knb1-zterm = '7001'.
  i_knb1-vzskz = '02'.
  i_knb1-fdgrv = 'C1'.
  i_knb1-xzver = 'X'.
  i_knb1-knrze = '0000935002'.

  t_xknvi-aland = 'BR'.
  t_xknvi-tatyp = 'IBRX'.
  t_xknvi-taxkd = '1'.
  APPEND t_xknvi.

  t_xknb5-bukrs = i_knb1-bukrs.
  t_xknb5-mahna = '0001'.
  APPEND t_xknb5.

  postflag = 'X'.
  CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
  EXPORTING
  i_kna1 = i_kna1
  i_knb1 = i_knb1
  i_knvv = i_knvv
* I_BAPIADDR1 =
* I_BAPIADDR2 =
* I_MAINTAIN_ADDRESS_BY_KNA1 = ' '
  pi_postflag = postflag
  IMPORTING
  e_kunnr = e_kunnr
  o_kna1 = o_kna1
  TABLES
* T_XKNAS =
* T_XKNBK =
  t_xknb5 = t_xknb5
* T_XKNEX =
* T_XKNVA =
* T_XKNVD =
  t_xknvi = t_xknvi
* T_XKNVK =
* T_XKNVL =
* T_XKNVP =
* T_XKNZA =
  EXCEPTIONS
  client_error = 1
  kna1_incomplete = 2
  knb1_incomplete = 3
  knb5_incomplete = 4
  knvv_incomplete = 5
  kunnr_not_unique = 6
  sales_area_not_unique = 7
  sales_area_not_valid = 8
  insert_update_conflict = 9
  number_assignment_error = 10
  number_not_in_range = 11
  number_range_not_extern = 12
  number_range_not_intern = 13
  account_group_not_valid = 14
  parnr_invalid = 15
  bank_address_invalid = 16
  tax_data_not_valid = 17
  no_authority = 18
  company_code_not_unique = 19
  dunning_data_not_valid = 20
  knb1_reference_invalid = 21
  cam_error = 22
  OTHERS = 23
  .

*
* (iv) insert the credit control data
*
  IF credit_control_flag = 'X'
  AND sy-subrc = 0.
* CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_KNKA_K'
* EXPORTING
* PI_REF_CUSTOMER = E_KUNNR
* PI_CUSTOMER = E_KUNNR
* EXCEPTIONS
* KNKA_INSERT_ERROR = 23
* KNKK_INSERT_ERROR = 24.

    CALL FUNCTION 'CREDITCONTROL_INSERT_DEFAULT' IN UPDATE TASK
         EXPORTING
              kunnr = e_kunnr
              kkber = i_knvv-kkber
              knrze = i_knb1-knrze.


  ENDIF.
*
* (v) return-value "kernel function"
*
* (1) reset data of function kernel
*
  CLEAR: i_kna1,
  i_knb1,
  i_knvv.
* I_BAPIADDR1_01,
* I_BAPIADDR2_01.
*
* (2) error-handling
* return value sy-subrc, only in case sy-subrc = 0
* the exporting data customer_number (customerno)
* will be changed
*
  subrc = sy-subrc.
  CLEAR sy-subrc.
*
*-(3) set return values and leave the function ------------------------*
* customerno (key-field of BO KNA1), pe_customer, return
*


  PERFORM returnsubrc_1
  USING subrc
  e_kunnr
  CHANGING e_kunnr
  return.
  IF subrc = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  ENDIF.

ENDFUNCTION.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.