BAPI (Business Application Programmer Interfaces), are the interfaces provided by SAP. BAPIs can be used for the following.
1) Integrating SAP to Non SAP systems using .NET Connector and Java Connector for example Visual Basic (Microsoft), or with Visual Age for Java (IBM) 2) Creating a Web Based interface to SAP 3) Uploading Data to SAP 4) Posting Data to SAP from within SAP 5) Creating an interface between various SAP Systems
Related Transaction Codes
BAPI SE37
Please refer the diagram below.
SAP ABAP BAPIs
The Business Application Programming Interfaces allow object-oriented access to the SAP system through methods for the business object types. Together with the business object types, BAPIs define and document the interface standard at the business level.
Benefits of using BAPIs
BAPIs allow integration at the Business Level, as each BAPI is built around a Business Object
BAPIs are well defined and are internally consistent
For a BAPI access is through a object-oriented interface and connectors such as .Net and Java Connector are available for building an interface with Non SAP Systems
Stability is not affected because they are upward compatible and all the BAPI interfaces will survive an R/3 Upgrade.
SAP ABAP Tutorial: Module Pool Programming. Part 1
Related Transaction Codes:
SE51: Screen Painter Initial Screen SE41: Menu Painter Initial Screen SE38: ABAP Editor Initial Screen SE80: Object Navigator In this tutorial we will explore module pool programming. We will create a sales order. We will combine the Initial screen and the Overview Screen of Transaction VA01Create Standard Order into one screen.
We will use the following BAPI to create the Sales Order
BAPI_SALESORDER_CREATEFROMDAT1
The following fields will be updated.
Order Type OR Sales Org 1000 Dsitribution Channel 10 Division 00
Sold-to Party 7777 Ship-to Party 7777 Purch Ord No 15493 Material y-351 Order Quantity 10 We will now proceed and create the main program. Run Transaction SE80 and create a program 'ZSALESORDSCREEN'. First just create this program save and activate.
To do so in the dropdown box select Program and type the name 'ZSALESORDSCREEN' in the filed below and hit enter. You will see a prompt that says 'Program does not exist' do you want to create a new object?
We saw in the earlier example as to how to create a sales order from the SE37 interface. Now we need to create a program and call the BAPI to create sales orders. Later we will discuss ways to call a BAPI from a non-sap system.
Given an appropriate name to the program. Please follow the naming conventions as per your company. ABAP programs should always start with a 'Z' or a 'Y'.
Enter suitable description.
Create a $tmp objects or create a transport request. Transport requests would be covered in the later tutorials.
Follow the menu path EDIT----->Pattern
Enter the name of the BAPI as shown below.
The inserted BAPI is shown below.
We now need to get the import parameters, export parameters and the tables. Note: Take care that the data declaration in the program for the above mentioned parameters matches exactly as given in the BAPI. To ensure that please open the BAPI using transaction SE37 and copy the exact names of the parameters from the BAPI structure.
If this is not followed your program will give an 'ABAP DUMP'.
Check the Import parameters
The following figure shows the import parameter BAPISHEAD and we need to declare a structure in our ABAP program as follows.
Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data
Similarly for tables pick up the names from the function module.
Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data ta_BAPIITEMIN like BAPIITEMIN occurs 0 with header line, " Ln item ta_BAPIPARTNR like BAPIPARTNR occurs 0 with header line, " Partner d_BAPIRETURN1 like BAPIRETURN1, " Bapi return msg d_vbeln like bapivbeln-VBELN. " Sales Order Number
The complete program is given below. Please make sure that you use the data specific to your system. In the following some of the values are hard coded. You need to use variables and pick up the values.
Please note in the following program, sold to party (SP) has been entered as 'AG' and ship to party (SH) as 'RG'.
SP--------AG SH--------RG
Order type 'OR' as 'TA'
Please use TA instead of OR
Also if you set the * CONVERT_PARVW_AUART = 'X' parameter to 'X' you can use sold to party as SP and ship to party as SH. REPORT ZEX_BAPISALESORDCRT .
*-------------------------Data Declaration-----------------------------* Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data ta_BAPIITEMIN like BAPIITEMIN occurs 0 with header line, " Ln item ta_BAPIPARTNR like BAPIPARTNR occurs 0 with header line, " Partner d_BAPIRETURN1 like BAPIRETURN1, " Bapi return msg d_vbeln like bapivbeln-VBELN. " Sales Order Number
* Move the data to create sales order in the repective parameters------* move: 'TA' to st_BAPISDHEAD-DOC_TYPE, " Sales document type '15493' to st_BAPISDHEAD-PURCH_NO_C, '00010' to ta_BAPIITEMIN-ITM_NUMBER, 'Y-351' to ta_BAPIITEMIN-MATERIAL, '1100' to ta_BAPIITEMIN-PLANT, '1' to ta_BAPIITEMIN-REQ_QTY, 'AG' to ta_BAPIPARTNR-PARTN_ROLE, " Sold to Party '0000007777' to ta_BAPIPARTNR-PARTN_NUMB. * Append the internal tables-------------------------------------------* append ta_BAPIPARTNR. clear ta_BAPIPARTNR. append ta_BAPIITEMIN. clear ta_BAPIITEMIN. * Move ship to party---------------------------------------------------* move: 'RG' to ta_BAPIPARTNR-PARTN_ROLE, " Ship to party '0000007777' to ta_BAPIPARTNR-PARTN_NUMB. * Append the internal tables-------------------------------------------* append ta_BAPIPARTNR. clear ta_BAPIPARTNR.
We will see the functionality of BAPI_SALESORDER_CREATEFROMDAT1.
As shown below, run transaction SE37.
and enter the name of the BAPI BAPI_SALESORDER_CREATEFROMDAT1.
Press F8 or click on execute. First we need to enter the header data.
Click on the single entry Icon as shown below.
Enter doc type and purchase order number. This will depend on your requirement and the data will vary from system to system.
Order type ---------- 'OR'
Once the header data is entered we need to enter the line item data. Please note that in this example we would be entering minimum data required just to create a sample sales order. In real life scenario you need to enter all the fields as per the companies requirement.
Enter the following fields.
Item Number ---- 000010 Material----------y-351 Plant-------------1100 Required quantity 1 Purchase Order number 15393
Please not that all the above data is system specific and you need to enter the values available in your system. You can refer to an existing sales order with the help of transaction VA03.
Need to enter the Partner Data. Namely Sold to Party and Ship to Party.
Enter Sold to Party indicator 'SP' Ship to Party as 'SH' Enter the sold to and ship to party number as 7777
Go back and Save the data. This will help you to create another sales order just by retrieving the values again by clicking on Test Data button. Or in case you make a mistake then you can just change the erroneous data.
Once you save the data. Press F8 or click on execute. As you can see below. Sales Order 7708 is created. Again this number will be different in your system.
Now you need to check the newly created Sales Order. Type /NVA02 or /NVA03 as the transaction code.
Always use Pretty Printer and Extended Program Check before releasing the code.
Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive.