Create BAPI
Create BAPI
BAPI's are very useful in SAP to perform some business function as well as to exchange data /
interact between different SAP systems or Non SAP systems as well. Though SAP provides a
whole bunch of ready to use BAPI's, one can create there own BAPI(s) easily if required.
Now add the bapi import structure we created in import tab. Always remember to tick Pass by
value since BAPI FM which is a RFC enabled FM cannot use pass by reference.
In the export tab we will put BAPI return parameters. BAPIRETURN is a standard BAPI return
structure. In the source code of the program we need to make use of this parameter to show
success or failure status along with messages.
In the tables we will use our BAPI export table structure we created. We always use LIKE for
tables.
4) Source code:
Add the logic of the FM here.
FUNCTION ZBAPI_GET_WERKS.
*"---------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
VALUE(MATNR) TYPE ZBAPI_ADIIMPORT-MATNR
*" EXPORTING
*"
VALUE(RETURN) TYPE BAPIRETURN
*" TABLES
*"
ZTABLE STRUCTURE ZBAPI_ADIEXPORT
*"---------------------------------------------------------------------select matnr werks from marc
into TABLE ztable
where matnr eq matnr.
if sy-subrc eq 0.
"Update BAPI return table accordingly to show success here
else.
"Update BAPI return table accordingly to show failure here
ENDIF.
ENDFUNCTION.
Logic of our BAPI is simple; it fetches matnr and werks value from marc table based on input
matnr values and fills the BAPI table. Lets test the FM, click execute and input a test data
ZTABLE will be filled with values from marc table corresponding to input matnr value
5 ) Place this Function Module in to BOR(Business object repository) using the T-code SWO1.
Provide the name of the object and press create button.
Add our Custom BAPI FM using Utilities = > API Method = >Add Method
Press next and it will ask you that method has not been implemented, and will ask for
confirmation to generate a template. Press Yes