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: 

Re: Custom bapi

Former Member
0 Kudos

HI all,

I want to create a custom bapi , I dont know how to create it, Can anyone explain , \[removed by moderator\]

regards,

Sasi

Edited by: Jan Stallkamp on Jul 24, 2008 12:43 PM

1 ACCEPTED SOLUTION
5 REPLIES 5

Former Member
0 Kudos

hi,

Check out the below related thread

Regards,

Santosh

Former Member
0 Kudos

Hi sashi,

BAPIs (Business Application Programming Interfaces) are the standard SAP interfaces. They play an important role in the technical integration and in the exchange of business data between SAP components, and between SAP and non-SAP components. BAPIs enable you to integrate these components and are therefore an important part of developing integration scenarios where multiple components are connected to each other, either on a local network or on the Internet.

BAPIs allow integration at the business level, not the technical level. This provides for greater stability of the linkage and independence from the underlying communication technology.

BAPI is a Remote enabled function module.

Just follow this simple procedure or steps to create a BAPI.

1. Defining BAPI Data structures in SE11

2. Program a RFC enabled BAPI function module for each method

3. Create a Business object for the BAPI in the BOR

4. Documentation the BAPI

5. Generate ALE interface for asynchronous BAPIs

6. Generate and release

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.

Scenario: Step-by-step creation of a BAPI to retrieve fields from table T001.

Procedure: Go to transaction SE11 and create a structure as shown or as per your requirement.

Give the name in the Data type field and click create.

In the pop-up that comes up, select the radio button u201C structureu201D.

In the components tab of the structure, give the different fields and their corresponding field types and press enter to check the compatibility and corrective ness.

Do not forget to save it in a package. You can even save it as a local object. For my example, I save it in a package.

Check the structure (ctrl + F2) and activate (ctrl + F3) the structure.

Now we are done with the creation of a Structure.

Go to transaction SE37 where you create function modules. Click on create after you enter the name of the Function module.

A screen as shown above would pop-up where you mention the function group to save the function module and also provide some short text describing your function module.

In the next pop-up that follows, click on continue as shown above.

The function module screen would look like the one above.

Go to the Attributes tab and select the radio button reading u201Cremote-enabled moduleu201D. Come back to the imports tab and provide the import parameters as shown or as per your requirement.

Now in the Export tab, provide the export parameters as shown or as per your requirement.

In the tables tab, provide the information as shown or as per your requirement.

The next screen you visit is the source code. It would look like this.

In the source code tab, write the following code in order to pick the data based on the input you provide.

Now, save and check the code and activate the function module.

award if found helpful

with thanks & regards,

Sravani yendru.