Ads

How to Create BAPI in SAP ABAP

How to Create BAPI in SAP ABAP

What is a BAPI
Business Application Programming Interface(BAPI) is a interface providing us access to SAP and Non-SAP systems to process data from the remote systems. BAPI's are API methods which are stored in the Business Object Repository (BOR). BAPI is implemented as a function module which connects the New R/3 components, Information Warehouse (BW),Non-SAP software,Legacy systems,Isolating components within the R/3 System in the context of Business Framework,Distributed R/3 scenarios with asynchronous connections using Application Link Enabling (ALE) and Connecting R/3 Systems to the Internet using Internet Application Components (IACs).

Business Application Programming Interface's(BAPI's) are standardized programming interfaces which enable external applications to access business processes and data in the R/3 System. BAPI provides us  seamless integration between the R/3 System and external applications and BAPI's defined as methods of SAP business object types that are used for different business functions. BAPI's are implemented as RFC-enabled function modules created in the Function Builder of the ABAP Workbench.

Difference between RFC and BAPI

BAPI is  a RFC enabled function module. The main difference between RFC enabled function module and BAPI is business objects. We create business objects which we  registered in  BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA languages. For this we  only define the business object and its method from external system. In BAPI, there is no direct system call, while RFC are direct system call. Some BAPIs provide basic functions which can be used for SAP business object types.

We need five main steps to create a BAPI

 1.Defining structure in SE11
 2. Defining function module in SE37
 3.Defining business object in SWO1
 4.Checking  the created BAPI in BAPI Explorer
 5.Testing  BAPI

1: Defining a structure in SE11 for BAPI


Go to transaction SE11 and create a structure .
How to Create BAPI in SAP ABAP



2: Defining the function module in SE37 for BAPI


Go to transaction SE37 where create function module.

Click on create after you enter the name of the function module. Enter the function group and short text. Now click on save button.
How to Create BAPI in SAP ABAP


A message will be displayed ‘Function module name is reserved for SAP’.  click continue. 
How to Create BAPI in SAP ABAP


 In the attributes tab, make the processing type as ‘Remote-Enabled Module’.
How to Create BAPI in SAP ABAP


Now go to the Import tab and enter the details 
How to Create BAPI in SAP ABAP



In the export tab enter the details as below. 

How to Create BAPI in SAP ABAP

 In the Tables tab enter the details as below.
How to Create BAPI in SAP ABAP

Now go to source code tab and enter the code as shown below.

How to Create BAPI in SAP ABAP

Next we have to release the function module by Function Module>Release>Release.

How to Create BAPI in SAP ABAP


3.Defining the business object in SWO1 for BAPI


Go to transaction SWO1 and enter the name of the BAPI .



How to Create BAPI in SAP ABAP



 Now select ‘Add Method’ from Utilities > API Methods > Add Method.

How to Create BAPI in SAP ABAP

Provide the function module name that we just created in the previous stage and click on the continue icon. In the coming pop-up, click the next step icon. 
How to Create BAPI in SAP ABAP



Just click on the “next” icon.  

How to Create BAPI in SAP ABAP


A popup will be displayed as below.
How to Create BAPI in SAP ABAP



Click on Yes. 
 Select & Double click on the API method.
Go to Tab: ABAP Check 'API Function' as shown below.


How to Create BAPI in SAP ABAP
Select the Radio button reading “API Function” as already said above.
Now select the Object “ZBAPI_SRI” 
How to Create BAPI in SAP ABAP


Now Go to : Edit > Change Release Status > Object type > To Modeled. 
How to Create BAPI in SAP ABAP


 Click on yes.

How to Create BAPI in SAP ABAP
Message shows, The object type status set to modeled. 
Now go to: Edit > Change Release Status > Object type >To Implemented. We can see a message reading “Object type status set to implemented” .

Now, go to: Edit > Change Release Status > Object > To Released.  Click continue on the Pop Ups. 
Keep the cursor on the 'Method'. Now go to: Edit > Change Release Status > Object type component > To Modeled. . 
How to Create BAPI in SAP ABAP

Now, go to: Edit > Change Release Status > Object type component > To Implemented. “ status for method ‘zbapifmt002’ set to implemented”. 

Now go to: Edit > Change Releasse Status > Object type component > To Released. You can see the message reading “ status for method ‘zbapifmt002’ set to Released”. 
Click on ‘Generate’ from Object Type as shown below.

How to Create BAPI in SAP ABAP

After clicking on the generate button, you can see the message reading “Object type 'ZBAPI_ABY' generated successfully”. Now we are done with the creation of a BAPI.

4: Checking the created BAPI in BAPI Explorer

Go to BAPI Explorer (BAPI) there we can find the BAPI (our BAPI). 
How to Create BAPI in SAP ABAP

 
5: Testing a BAPI

Enter the name of your BAPI in the transaction SWO1 and click on ‘Test’. 
How to Create BAPI in SAP ABAP

   
Click on the Execute icon against the BAPI .

How to Create BAPI in SAP ABAP
We  would require entering the data against the empty input fields.
How to Create BAPI in SAP ABAP
  
Give the input and  click the execute button. 

How to Create BAPI in SAP ABAP
Output screen is displayed below
How to Create BAPI in SAP ABAP
  
Final output looking below image.
How to Create BAPI in SAP ABAP
Finally,we have completed the creating a BAPI and its steps .


    

Comments

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced