Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Customer using BAPI

Former Member
0 Kudos

Hi experts,

I am using BAPI_CUSTOMER_CREATEFROMDATA1 to create customers from portal.

We are using Search Term 1 and 2 fields in the transaction VD01 while creating customers from SAP GUI.

But I couldnt find these fields in any of the structures in this BAPI.

Is there any standard BAPI which can solve this issue?

Can anyone help me out?

Thanks alot in Advance

Shobin

2 REPLIES 2

Former Member
0 Kudos

Hi Shobin

try this hope it will help you.

reward if help.

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 -


*

  • 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 -


*

  • 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.

Former Member
0 Kudos

Try following FModule

SD_CUSTOMER_MAINTAIN_ALL

anya