0% found this document useful (0 votes)
163 views37 pages

BAPI Creation Guide in SAP ABAP

The document provides step-by-step instructions for creating a BAPI in SAP ABAP. It describes what a BAPI is and its uses. It then outlines the stages and steps to create a BAPI, including creating a structure, function module, and testing the BAPI. The process involves tools like SE11, SE37, and the Business Object Builder.

Uploaded by

saurabh.rai83
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views37 pages

BAPI Creation Guide in SAP ABAP

The document provides step-by-step instructions for creating a BAPI in SAP ABAP. It describes what a BAPI is and its uses. It then outlines the stages and steps to create a BAPI, including creating a structure, function module, and testing the BAPI. The process involves tools like SE11, SE37, and the Business Object Builder.

Uploaded by

saurabh.rai83
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Creating a Structure
  • Introduction to BAPI
  • Creating a Function Module
  • Writing the Code
  • Completing the BAPI
  • Testing the BAPI
  • Releasing the BAPI

SAP ABAP on HANA

Step by Step Guide to Create BAPI In ABAP


Step By Step Guide
[Link] to Create BAPI in ABAP

SAP S/4HANA BAPI Tutorial –

What is BAPI?
Business Application Programming Interface(BAPI) are standardized programming interfaces (methods)
enabling external applications to access business processes and data in the SAP System.

They provide stable and standardized methods to achieve seamless integration between the SAP
System and external applications, legacy systems and add-ons.

BAPIs are defined in the BOR(Business object repository) as methods of SAP business object types that
carry out specific business functions. They are implemented as RFC-enabled function modules and are
created in the Function Builder of the ABAP Workbench.

Some BAPIs and methods provide basic functions and can be used for most SAP Business Objects.
These are called STANDARDIZED BAPI’s.

List of Standardized BAPIs:

• BAPIs for Reading Data – GetList() , GetDetail() , GetStatus() , ExistenceCheck()


• BAPIs for Creating or Changing Data- Create() ,Change(),Delete() and Undelete() ,
• BAPIs for Mass Processing -ChangeMultiple(), CreateMultiple(), DeleteMultiple().

Stage1: Creating a structure in SE11


Step 1: Go to transaction SE11 and create a structure as shown or as per your requirement.

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
1
[Link]

Do not forget to save it in a package. Check the structure (ctrl + F2) and activate (ctrl + F3) the
structure.

Stage2: Creating the function module in SE37


Step 2: Go to transaction SE37 where you create function modules.

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
3
In the attributes tab, make the processing type as ‘Remote-Enabled Module’.
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
5
[Link]

FUNCTION ZBAPI_CROSS_SELLING .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(PV_KSCHL) TYPE ZBAPIVB41-KSCHL DEFAULT 'CS01'
*" VALUE(PV_KOTABNR) TYPE ZBAPIVB41-KOTABNR DEFAULT '011'
*" VALUE(PV_MATWA) TYPE ZBAPIVB41-MATWA DEFAULT ' '
*" VALUE(PV_SMATN) TYPE ZBAPIVB41-SMATN DEFAULT ' '
*" VALUE(PV_MEINS) TYPE ZBAPIVB41-MEINS DEFAULT ' '
*" VALUE(PV_SUGRD) TYPE ZBAPIVB41-SUGRD DEFAULT ' '
*" VALUE(PV_DATAB) TYPE ZBAPIVB41-DATAB DEFAULT SY-DATUM
*" VALUE(PV_DATBI) TYPE ZBAPIVB41-DATBI DEFAULT '99991231'
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRET2
*" TABLES
*" ZBAPIVB41 STRUCTURE ZBAPIVB41
*"----------------------------------------------------------------------

INCLUDE Z_MME_CROSS_SELLING_TOP.

XVAKE-VAKEY = PV_MATWA.
XKONDD-SMATN = PV_SMATN.
TIME_VAKE_KEY-KAPPL = 'VS'.
TIME_VAKE_KEY-KVEWE = 'D'.
TIME_VAKE_KEY-KOTABNR = PV_KOTABNR.
TIME_VAKE_KEY-KSCHL = 'CS01'. "PV_KSCHL.
TIME_VAKE_KEY-VAKEY = XVAKE-VAKEY.

IF PV_DATAB IS INITIAL.
LV_DATAB = SY-DATUM.
ELSE.
LV_DATAB = PV_DATAB.
ENDIF.

*Material
CLEAR LS_VAKEDB.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_VAKEDB
FROM KOTD011
WHERE KAPPL EQ TIME_VAKE_KEY-KAPPL
AND KSCHL EQ TIME_VAKE_KEY-KSCHL
AND MATNR EQ PV_MATWA
AND DATBI GE LV_DATAB
AND DATAB LE LV_DATAB.

IF SY-SUBRC = 0.

SELECT SINGLE * FROM KONDD WHERE KNUMH = NV_NEW_NUMBER AND SMATN = PV_SMATN.

IF SY-SUBRC = 0.
EXIT.
ELSE.
NV_NEW_NUMBER = LS_VAKEDB-KNUMH.
ENDIF.

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
7
ELSE.

CALL FUNCTION 'NUMBER_GET_NEXT'


EXPORTING
NR_RANGE_NR = '01'
OBJECT = NUMMERVORG
IMPORTING
NUMBER = NV_NEW_NUMBER.

ENDIF.

*Variable Key for Condition Maintenance: Internal Structure


XVAKE-KVEWE = TIME_VAKE_KEY-KVEWE.
XVAKE-KOTABNR = TIME_VAKE_KEY-KOTABNR .
XVAKE-KAPPL = TIME_VAKE_KEY-KAPPL.
XVAKE-KSCHL = TIME_VAKE_KEY-KSCHL.
XVAKE-DATBI = PV_DATBI.
XVAKE-DATAB = PV_DATAB.
XVAKE-KNUMH = NV_NEW_NUMBER.
XVAKE-UPDKZ = 'I'.
APPEND XVAKE.

*Condition Tables: Update Structure


MOVE-CORRESPONDING XVAKE TO TIME_VAKE_DB.
TIME_VAKE_DB-XXSTATE = 'I'.
TIME_VAKE_DB-XXPROCINFO = 'U'.
TIME_VAKE_DB-XXDBACTION = 'I'.
APPEND TIME_VAKE_DB.

*Change Document Structure; Generated by RSSCD000


*Condition Record: Old and New Validity Periods
XKONDAT-KNUMH = NV_NEW_NUMBER.
XKONDAT-DATAN = SY-DATUM.
XKONDAT-DATAB = PV_DATAB.
XKONDAT-DATBI = PV_DATBI.
XKONDAT-KZ = 'U'.
APPEND XKONDAT.

*Change Document Structure; Generated by RSSCD000


*Condition Record: Old and New Validity Periods
YKONDAT-KNUMH = NV_NEW_NUMBER.
YKONDAT-DATAN = PV_DATBI.
YKONDAT-KZ = 'U'.
APPEND YKONDAT.

*Material Substitution - Posting Structure


XKONDD-MANDT = SYST-MANDT.
XKONDD-KNUMH = NV_NEW_NUMBER.
IF LS_VAKEDB-KNUMH IS INITIAL.
XKONDD-UPDKZ = 'I'.
ELSE.
XKONDD-UPDKZ = ' '.
ENDIF.
APPEND XKONDD.

*Conditions: Additional [Link] [Link] - Posting


XKONDDP-MANDT = SYST-MANDT.
[Link]

XKONDDP-KPOSN = 1.
XKONDDP-KNUMH = NV_NEW_NUMBER.
XKONDDP-SMATN = XKONDD-SMATN.
IF LS_VAKEDB-KNUMH IS INITIAL.
XKONDDP-UPDKZ = ' '.
XKONDDP-KPOSN = 1.
ELSE.
CLEAR LV_COUNT.
SELECT COUNT(*) INTO LV_COUNT FROM KONDD WHERE KNUMH = NV_NEW_NUMBER.
XKONDDP-UPDKZ = 'I'.
XKONDDP-KPOSN = LV_COUNT + 1.
CLEAR : TIME_VAKE_DB, XKONDAT, YKONDAT.
ENDIF.
APPEND XKONDDP.

IF LS_VAKEDB-KNUMH IS INITIAL.
* Condition Maintenance - General
CALL FUNCTION 'RV_KONDITION_SICHERN' IN UPDATE TASK
TABLES
VAKEDB_TAB = TIME_VAKE_DB.
ENDIF.

BOOLE_T = 'X'.

*Material substitution - update function


CALL FUNCTION 'RV_MAT_SUB_SAVE' IN UPDATE TASK
IMPORTING
USE_OUTBOUND_CALL = BOOLE_T
CD_KVEWE = TIME_VAKE_KEY-KVEWE
CD_KOTABNR = TIME_VAKE_KEY-KOTABNR
CD_KAPPL = TIME_VAKE_KEY-KAPPL
CD_KSCHL = TIME_VAKE_KEY-KSCHL
TABLES
X_KONDDVB = XKONDD
Y_KONDDVB = YKONDD
X_KONDDPVB = XKONDDP
Y_KONDDPVB = YKONDDP
X_KONDATVB = XKONDAT
Y_KONDATVB = YKONDAT
DB_TIME = TIME_VAKE_DB
DB_XVAKE = XVAKE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'


* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.

*Material Substitution - Data Division


SELECT SINGLE * FROM KONDD WHERE KNUMH = NV_NEW_NUMBER AND SMATN = PV_SMATN.

ENDFUNCTION.

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
9
[Link]

How to create a BAPI

Step [Link] to transaction swo1 (Tools->Business Framework -> BAPI Development ->Business Object
builder ) .Select the business object, according to the functional requirement for which the BAPI is
being created.

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
11
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
13
[Link]

[Link] the business object in change mode. Then Select Utilities ->API Methods ->Add method.
Then enter the name of the function module and select Continue.

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
15
Step [Link] the next dialog box, following information needs to be specified :

• Method : Suggest an appropriate name for the method,


• Texts : Enter description for the BAPI,
• Radio buttons : Dialog, Synchronous, Instance-independent . BAPI ‘s are usually implemented
synchronously.
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
17
[Link]

[Link] create the method select Yes in the next dialog box.

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
19
[Link]

Step5. After the program has been generated and executed, check the program in the method just
created. Thus , a BAPI is created.

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
21
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
23
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
25
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
27
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
29
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
31
Testing the BAPI
You can test the BAPI by Testing the individual method of the Business Object in the Business Object
Builder. .
[Link]

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
33
[Link]

Releasing and freezing the BAPI

• To release the BAPI , first release the function module (using transaction se37 ) .

• Set the status of the method to ‘released’ in the Business Object Builder ( using transaction
SWo1 – Edit-> change status-> released. )

MICKAEL QUESNOT © [Link]


SAP S/4HANA CONSULTANT / SAP HELPER
35
You can also use the BAPI Explorer (Transaction code BAPI) for 360′ view on BAPI

Common questions

Powered by AI

Defining a BAPI method in the Business Object Builder involves several key steps: first, access the Business Object Builder via transaction SWO1 and open the relevant business object. Next, set the object to change mode and navigate to Utilities -> API Methods -> Add method. Here, you specify the name of the function module. In the following dialog, provide details such as a methodological name, a descriptive text, and choose between dialog, synchronous, or instance-independent settings, with BAPIs typically being synchronous. The method is then created and its program is generated and executed for final verification, thus completing the BAPI creation process .

The 'BAPI_TRANSACTION_COMMIT' function is used in BAPI development to ensure that all changes made during the transaction are saved to the database. This is critical because BAPIs typically operate on business-critical data, necessitating a reliable process to commit all changes once the operations are successfully executed. If the changes are not committed, data integrity could be compromised, leading to incomplete transactions or loss of important information .

Testing a BAPI using the Business Object Builder allows developers to evaluate the BAPI's functionality and reliability in a controlled environment before it is deployed in a production setting. This testing ensures that the BAPI performs the intended business operations correctly and efficiently. It helps verify that the BAPI interfaces effectively with business objects as expected and validates the logic to handle possible scenarios, contributing to its robustness and reducing any potential for errors during actual use .

BAPIs facilitate mass processing by providing standardized methods that allow multiple data entries to be created, changed, or deleted in bulk, thereby improving efficiency and reducing processing time. This capability is essential for handling large volumes of data that need simultaneous updates or processing. Examples of such BAPIs include ChangeMultiple(), CreateMultiple(), and DeleteMultiple(), which allow batch operations on data to ensure consistent and rapid updates across the system .

Implementing a synchronous BAPI presents challenges such as managing system load, ensuring real-time data processing, and maintaining system responsiveness. Synchronous BAPIs require immediate execution and confirmation of operations, which can burden the system if multiple calls are made simultaneously, potentially affecting performance. Developers need to consider system capacity, response times, and possible bottlenecks in data processing. These aspects require optimization to maintain efficient system performance and minimize any adverse impact on other operations being conducted on the SAP platform at the same time .

Standardized BAPIs ensure consistent interaction with SAP business objects by providing pre-defined, stable methods that support common operations across different scenarios. These BAPIs simplify integration and reduce development time by enforcing a uniform approach to data access and manipulation. Examples of standardized BAPIs include GetList(), GetDetail(), GetStatus(), Create(), Change(), Delete(), and several methods for mass processing like ChangeMultiple() and CreateMultiple(). These methods cater to tasks like reading data, creating or updating records, and handling batch operations .

Designating the processing type of a function module as a 'Remote-Enabled Module' in SE37 is crucial for enabling BAPI functionality. This setting allows the function module to be accessible from external systems, which is necessary for integrating external applications with SAP. The remote-enabled status ensures that the function module can be invoked by remote calls, thus facilitating cross-system communication and enabling BAPIs to execute their intended business processes remotely and efficiently .

BAPIs (Business Application Programming Interfaces) are designed to enable seamless integration between external applications and SAP systems by providing stable, standardized programming interfaces. These interfaces allow external applications to access SAP business processes and data. BAPIs are defined in the Business Object Repository (BOR) as methods linked to SAP business object types that perform specific business functions. Technically, they are implemented as RFC-enabled function modules and are created using the Function Builder in the ABAP Workbench .

Creating a structure in SE11 is a crucial initial step in the development of a BAPI in SAP. This involves defining a structure that organizes and formats the data that the BAPI will handle. In SE11, you create a structure according to the specific needs of the BAPI, save it within a package, check its integrity, and activate it. This structure serves as a blueprint for the data fields that the BAPI will interact with, ensuring that all necessary elements are predefined before the function module creation begins .

Setting a BAPI’s status to ‘released’ signifies that it is ready for use and deployment beyond the development environment. It affects deployment by allowing external applications to employ the BAPI for interfacing with SAP systems. This status change, performed via Business Object Builder (transaction SWO1), involves releasing the accompanying function module and freezing its development. A BAPI that is not released remains inaccessible for integration, thus making this a crucial final step in the deployment process .

SAP ABAP on HANA
Step by Step Guide to Create BAPI In ABAP
https://www.linkedin.com/in/mickaelquesnot/ 
 
MICKAEL QUESNOT © https://www.linkedin.com/in/mickaelquesnot/ 
SAP S/4HANA CON
https://www.linkedin.com/in/mickaelquesnot/ 
 
MICKAEL QUESNOT © https://www.linkedin.com/in/mickaelquesnot/ 
SAP S/4HANA CON
 
In the attributes tab, make the processing type as ‘Remote-Enabled Module’.
https://www.linkedin.com/in/mickaelquesnot/ 
 
MICKAEL QUESNOT © https://www.linkedin.com/in/mickaelquesnot/ 
SAP S/4HANA CON
https://www.linkedin.com/in/mickaelquesnot/ 
 
MICKAEL QUESNOT © https://www.linkedin.com/in/mickaelquesnot/ 
SAP S/4HANA CON
ELSE. 
 
    CALL FUNCTION 'NUMBER_GET_NEXT' 
      EXPORTING 
        NR_RANGE_NR = '01' 
        OBJECT      = NUMMERVORG
https://www.linkedin.com/in/mickaelquesnot/ 
 
MICKAEL QUESNOT © https://www.linkedin.com/in/mickaelquesnot/ 
SAP S/4HANA CON

You might also like