SAP BAPI
What is BAPI in SAP: SAP BAPI (Business Application Programming Interface) — A standard interface of the business object models in SAP R/3.
Most of the time, BAPIs are how customer code and third-party applications deal with SAP products. Transnational BAPIs encapsulate the intermediary SAP business object model-layer to ensure that any appropriate business logic, validations or authorization checks are done when we reference a prefix which has been written via your program.
How BAPI works
Implementing them as function modules with API to SAP internal is called BAPI. They could be implemented calling business object models defined using the Business Objects Processing Framework (BOPF), or legacy models defined with programs, tables and function modules.
BAPI Meaning ; BAPIs are standardized interfaces that enable communication between SAP systems and external applications. They are used to perform various business functions, such as creating, updating, or retrieving data from an SAP system
Some Important Features about BAPI
Some of the important points related to SAP BAPI:Â
1) SAP BAPI mustn’t contain call transaction.
2) BAPI mustn’t invoke commit work instead of commit work. We call the BAPI-TRANSACTION_COMMIT function module.
3) BAPI structure mustn’t contains includes.
4) There is o functional dependences between any two BAPI’s.
5) BAPI never calls to terminate the program.
Whenever an error occurred in BAPI it written those errors through written parameter.
6) BAPI must not contain dialogue programs.
7) BAPI mustn’t contain Submit reports.
Steps to create our own custom BAPI:
Best way to learn SAP BAPI Tutorial with complete steps
1. Create the BAPI structure (SE11)
2. Create the BAPI function module (SE37)
1. Which is remote enable.
2. Must contains RETURN parameter
3. All parameters are pass by value
3. Create the object and methods for BAPI function module (SW01)
4. Release the object and method (SW01).
Object: Develop a custom BAPIs to display the purchasing doc number, doc date & vendor number based on the given purchasing doc number.
Steps to create the BAPIs structure:
-> Execute SE11.
-> Select the radio button data type.
-> Provide the BAPI structure name (ZBAPI_STR).
-> Click on create.
-> Select the radio button structure. Enter.
-> Provide short description (BAPI Structure).
-> Provide the component & component type.
EBELN EBELN
BEDAT BEDAT
LIFNR LIFNR
-> Save in own package. Check, activate.
Steps to create function group:
-> Execute SE37.
-> In the menu bar click on goto -> function groups -> create group.
-> Provide the function group name (ZBAPI_FG), short description.
-> Save in our own package.
Steps to activate the function group:
-> In the menu bar click on environment -> inactive objects.
-> Expand the function group under transportable objects.
-> Select the function group. Right click -> activate. Enter.
Steps to create function module:Â
Import
Source code :
Select single ebeln bedat lifnr from ekko into wa_ekko where ebeln = i_ebeln.
-> Save, check, activate.
-> Click on back. In the menu bar click on function module. Release -> Release.
-> Function module is released.
Steps to release the object & method for BAPI function module:
-> Execute SW01.
-> Provide the object name (ZBAPI_OB).
-> Click on create.
-> Provide the same to all. Select the application (M). Enter.
-> Click on enter. Save in our package.
-> Place the cursor on methods. In the menu bar click on utilities. API methods -> Add method.
-> Provide function module name (ZBAPI_FM1). Click on enter.
-> Click on next step (CTRL + SHIFT + F11). Click on next.
-> Click on yes. Click on save.
Steps to release the object & method:
-> Place the cursor on object (ZBAPI_7OB).
-> In the menu bar click on edit -> change release status -> object type ïƒ to modeled
(to implemented, to release also).
-> Select the method. In the menu bar, click on edit -> change release status -> object type component-> to modeled (to implemented, to released also).
-> Click on generate (CTRL + F3).
Steps to check BAPI in SAP is available or not in BOR:
-> Execute BAPI transaction.
Click on alphabetical tab & Observe our BAPI.
Steps to identify the standard BAPIs:
Method 1:
-> Execute ‘SE93’.
-> Provide the related transaction code (ME23N).
-> Click on display.
-> Click on display object list (CTRL + SHIFT + F5) in the application tool bar.
-> Expand the package.
-> Expand the business engineering.
-> Expand the business object types.
-> Double click on our required business object.
-> Expand the method. Double click on our required method (Get details).
-> Click on ABAP tab.
-> Identify the BAPI name (BAPI_PO_GETDETAIL).
Method 2:
By using BAPI methods, we can identify the standard BAPI. Some of the BAPI methods are
1. Get list ()
2. Get details ()
3. Get status ()
4. Existence check ()
5. Create ()
6. Change ()
7. Delete ()
Steps to identify the BAPI based on BAPI method name:
-> Execute ‘SE37’.
-> Provide BAPI *<Method name>. Click on F4.
-> We get the list of BAPIs related to that method & identify our required method.
Note: -When ever we are working with crate, change, delete BAPIs, then we must committed the data base by using ‘BAPI_TRANSACTION_COMMIT’ function module. Other wise the data base isn’t updated.
Steps to create the bank details manually:
-> Execute ‘FI01’.
-> Provide bank country key (IN).
-> Bank key (121516). Enter.
-> Provide the bank name (HDFC Bank).
-> Save.
Object :Create the bank details by using BAPI Programming in SAP.
REPORT ZBBS_T_BAPI2.
PARAMETER P_BCTRY LIKE BAPI1011_KEY-BANK_CTRY.
PARAMETER P_BKEY LIKE BAPI1011_KEY-BANK_KEY.
DATA WA_ADD LIKE BAPI1011_ADDRESS.
DATA WA_RETURN LIKE BAPIRET2.
WA_ADD-BANK_NAME = ‘ICICI BANK’.
WA_ADD-REGION = ’01’.
WA_ADD-STREET = ‘SRNAGAR’.
WA_ADD-CITY = ‘HYD’.
CALL FUNCTION ‘BAPI_BANK_CREATE’
EXPORTING
BANK_CTRY = P_BCTRY
BANK_KEY = P_BKEY
BANK_ADDRESS = WA_ADD
IMPORTING
RETURN = WA_RETURN .
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
IF WA_RETURN IS INITIAL.
WRITE ‘BANK CREATED SUCCESSFULLY’.
ELSE.
WRITE WA_RETURN-MESSAGE.
ENDIF.
Steps to create cost center group manually:Â
-> Execute ‘KSH1’.
-> Provide the Controlling area (6000). Enter.
-> Provide the cost center group name (SPCG1). Enter.
-> Provide short description.
-> Click on cost center in the application tool bar.
-> Provide the from to (1000 – 3000), (5000 – 7000) cost centers. Enter.
-> Click on save.
Object: Create the cost center group by some SAP BAPI examples.
REPORT ZBBSR_T_BAPI3.
PARAMETER P_CAREA LIKE BAPICO_GROUP-CO_AREA.
DATA WA_RETURN LIKE BAPIRET2.
DATA : IT_HNODE LIKE TABLE OF BAPISET_HIER,
WA_HNODE LIKE LINE OF IT_HNODE.
DATA : IT_HVAL LIKE TABLE OF BAPI1112_VALUES,
WA_HVAL LIKE LINE OF IT_HVAL.
WA_HNODE-GROUPNAME = ‘SPCG3’.
WA_HNODE-HIERLEVEL = ‘0’.
WA_HNODE-VALCOUNT = ‘2’.
WA_HNODE-DESCRIPT = ‘BBST Cost center group’.
APPEND WA_HNODE TO IT_HNODE.
WA_HVAL-VALFROM = ‘0000002000’.
WA_HVAL-VALTO = ‘0000003000’.
APPEND WA_HVAL TO IT_HVAL.
WA_HVAL-VALFROM = ‘0000004000’.
WA_HVAL-VALTO = ‘0000005000’.
APPEND WA_HVAL TO IT_HVAL.
CALL FUNCTION ‘BAPI_COSTCENTERGROUP_CREATE’
EXPORTING
CONTROLLINGAREAIMP = P_CAREA
IMPORTING
RETURN = WA_RETURN
TABLES
HIERARCHYNODES = IT_HNODE
HIERARCHYVALUES = IT_HVAL .
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
IF WA_RETURN IS INITIAL.
WRITE ‘Cost center group is created’.
ELSE.
WRITE WA_RETURN-MESSAGE.
ENDIF.
There are 2 types of BAPI’s
1.Instance independent bapi : For which bapi’s, we no need to provide the input thant bapi’s are called instance independent bapi
ex: GETLIST( ) bapi’s are called instance independent bapi
2.Instance dependent bapi : For which bapi’s, we must provide the input than BAPI’s are called instance dependent BAPI
ex : GETDETAIL( ), GETSTATUS( ),…BAPI’s are called instance dependent BAPI.
Object: Update the bank city & street using BAPI.
Steps to update the bank details manually:Â
-> Execute FI02.
-> provide bank country key (IN),
-> bank key (121516). Enter.
-> Provide the street (SR Nagar),
-> city (HYD).
-> Save.
REPORT ZBBSR_T_BAPI4.
PARAMETER : P_BCTRY LIKE BAPI1011_KEY-BANK_CTRY,
P_BKEY LIKE BAPI1011_KEY-BANK_KEY,
P_STREET LIKE BAPI1011_ADDRESS-STREET,
P_CITY LIKE BAPI1011_ADDRESS-CITY.
DATA WA_ADD LIKE BAPI1011_ADDRESS.
DATA WA_ADDX LIKE BAPI1011_ADDRESSX.
DATA WA_RETURN LIKE BAPIRET2.
WA_ADD-STREET = P_STREET.
WA_ADD-CITY = P_CITY.
WA_ADDX-STREET = ‘X’.
WA_ADDX-CITY = ‘X’.
CALL FUNCTION ‘BAPI_BANK_CHANGE’
EXPORTING
BANKCOUNTRY = P_BCTRY
BANKKEY = P_BKEY
BANK_ADDRESS = WA_ADD
BANK_ADDRESSX = WA_ADDX
IMPORTING
RETURN = WA_RETURN .
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
IF WA_RETURN IS INITIAL.
WRITE ‘BANK UPDATED’.
ELSE.
WRITE WA_RETURN-MESSAGE.
ENDIF.
Object :Develop a conversion program to update the bank city & street from flat file to sap system by using BAPI. The flat file contains bank country key, bank key, street & city.: Develop a conversion program to update the bank city & street from flat file to sap system by using BAPI. The flat file contains bank country key, bank key, street & city.
REPORT ZBBSR_T_BAPI5.
TYPES : BEGIN OF TY_BANK,
BCTRY LIKE BAPI1011_KEY-BANK_CTRY,
BKEY LIKE BAPI1011_KEY-BANK_KEY,
STREET LIKE BAPI1011_ADDRESS-STREET,
CITY LIKE BAPI1011_ADDRESS-CITY,
END OF TY_BANK.
DATA WA_BANK TYPE TY_BANK.
DATA IT_BANK TYPE TABLE OF TY_BANK.
DATA WA_ADD LIKE BAPI1011_ADDRESS.
DATA WA_ADDX LIKE BAPI1011_ADDRESSX.
DATA WA_RETURN LIKE BAPIRET2.
CALL FUNCTION ‘UPLOAD’
EXPORTING
FILETYPE = ‘DAT’
TABLES
DATA_TAB = IT_BANK.
LOOP AT IT_BANK INTO WA_BANK.
WA_ADD-STREET = WA_BANK-STREET.
WA_ADD-CITY = WA_BANK-CITY.
WA_ADDX-STREET = ‘X’.
WA_ADDX-CITY = ‘X’.
CALL FUNCTION ‘BAPI_BANK_CHANGE’
EXPORTING
BANKCOUNTRY = WA_BANK-BCTRY
BANKKEY = WA_BANK-BKEY
BANK_ADDRESS = WA_ADD
BANK_ADDRESSX = WA_ADDX
IMPORTING
RETURN = WA_RETURN .
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
IF WA_RETURN IS INITIAL.
WRITE / ‘BANK UPDATED’.
ELSE.
WRITE WA_RETURN-MESSAGE.
ENDIF.
ENDLOOP.
Difference between RFC and BAPI
The main difference between BAPI and RFC is , RFC is used to enable communication between different systems or applications, while BAPI is used to provide a standardized way of accessing and manipulating business object
it is a common SAP BAPI interview questions.Â
Note: -BAPI is used to connecting from SAP to SAP as well as SAP to NON – SAP. Where as RFC is used to connecting from SAP-SAP only.
Â
Differences between BAPI and BDC
How to find BAPI in SAP ABAP
Go to Transaction SE37 This is the tcode which is used to display or manage Function Module.
-> Next Search for BAPIs: Basically in in Function Module enter search term as per your need in BAPIs related like BAPI_NETWORK. Then Press F4 to get a list of function modules .
Here are some specific BAPIs and function modules related to network creation and maintenance:
BAPI_NETWORK_MAINTAIN: Used for maintaining network data.
2002_NETWORK_CREATE: A function module for creating networks.
NETWORK_CREATE: Another function module for creating networks.
NETWORK_ENJOY_CREATE: A user-friendly function module for creating networks.
CNPB_M_NETWORK_CREATE: A function module for creating networks, possibly with additional features or specific use cases.
CO2H_NETWORK_CREATE: A function module for creating networks, potentially with a focus on hierarchical structures.
CO2H_NETWORK_CREATE_STRU: Specifically for creating network structures.
CO2H_NETWORK_CREATE_WITH_REFE: Used for creating networks with reference to existing data.
BAPI SAP Tcode:
There are below some BAPI SAP Tcode which are generally used in Realtime.
- SAP BAPI Browser: SE37
- SAP BAPI Documentation: SE38
- SAP BAPI Test Environment: SE39
- SAP BAPI Development: SE80
- SAP BAPI Interface: SE81
- BAPI SAP Implementation: SE82
- BAPI SAPTesting: SE83
- BAPI SAP Monitoring: SE84
- SAP BAPI Security: SE85
- BAPI SAP Customizing: SE86
RFC in SAP ABAP
RFC stands for Remote Function Call, which is a way to execute functions or methods on a remote SAP system. This allows for seamless integration and communication between different SAP systems.