Saturday, October 13, 2012

How to create a BAPI (Step by Step Explanation

 The steps Involved in creating a BAPI are:

1)Creating the BAPI structure/structures as needed.
2)Creating the Remote function module for the BAPI(Only remote function modules can be used for BAPI)
3)Linking the Remote function module with BOR(Business Object Repository)
4)Implement ,Generate and Release the BAPI for usage.

We can demonstrate the creation of BAPI with the following example.
a.Construct a structure as shown below and activate the same.It has only one field EBELN.
b.Construct another structure ZBAPI_TABLE which is to later embedded in function module

c.Construct a remote function module ZLEARN_BAPI in SE37.Make sure to make the rfc enabled by clicking the radio button in attribute  section as shown in screenshot.

 Provide the import parameter as the first structure created.The export parameter should be BAPIRET2.Older versions of BAPIs can use  BAPIRETURN & BAPIRET1.BAPIRET2 is the latest version of BAPI return parameter provided by SAP.

 Tables are obsolete as of ECC.But in case you need to use them, you need o define it as shown in below screenshots.Please note that you should be using "LIKE" instead of "TYPE" as depicted below.

 As a good programming practice, you can add the documentation of the BAPI by clicking the function module documentation button.
 The function module we have created picks up the EBELN values and provides them as output.

 d.Once the function module is activated,goto Transaction SWO1 and provide a  name for the BAPI interface and hit create button.

 Add the API method and provide the function module we have created.
Give a name for the BAPI method to be used.You can define the attributes of the method as needed like synchronous,instance dependent or dialog over here.
 This screen is automatically generated , once the ok button is clicked.
 On reaching this screen, click Yes to add the method to BOR.
 e.Now Implement, Generate and then Release the BAPI as shown in the below screens.Once BAPI is released its good to be used in SAP system.

f. Now,let us test the BAPI interface.We can do this directly in SW01.Expand method of BAPI and provide the test data as shown below.

 And the output is provided which is follows:

No comments:

Post a Comment