[SAP ABAP] BAPI
BAPI
BAPI is a standard interface that is available in every SAP system. This interface has been designed to access data from the third system (SAP ERP, SAP CRM, other systems). BAPI is a remotely activated function module and can be called by applications that are implemented, for example, in Java. Additionally, the BAPI architecture allows the use of business logic, validation, and checking permissions, which are available in the business object level. BAPI is registered in the Business Object Repository (BOR).
BAPI is relatively easy to implement. However, the programmer must remember some important rules when creating the interface. We will describe these rules next.
The first step of implementing BAPI is to create a function module in
SE37
Tcode (transaction code ). To do this, navigate to Function module
|
Attributes
, and select the options that are displayed in the following screenshot:
If a user requires input data for the correct operation of business logic, then the developer can add it in the
Import
tab:
An example of an import table is shown in the preceding screenshot.
BAPIRET2
is a standard structure that is available in every SAP system. A structure could include warning and error messages—this helps us find the cause of the error. On the other hand, it can be used to get success information to confirm the accuracy of program results as follows:
A developer must declare what data will be returned by the BAPI module. In this example, it will be a table, as demonstrated in the following screenshot:
Note
To be able to declare an output table, its type must always start with
ZBAPI
. This rule is, by default, not validated at this step, but it will be verified later, preventing the successful creation of BAPI.
In the
Source code
tab, we implement the appropriate code. An example code is shown in the following code snippet. The user also has the option of using modern techniques based on object-oriented programming:FUNCTION zbapi_demo.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(CARRID) TYPE ZBAPISFLIGHT-PLANETYPE
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRET2
*" TABLES
*" ZSFLIGHT STRUCTURE ZBAPISFLIGHT
*"----------------------------------------------------------------------
CLEAR zsflight .
SELECT planetype seatsmax_b seatsocc_b seatsmax_f seatsocc_f
FROM sflight INTO TABLE zsflight
WHERE carrid EQ carrid.
IF sy-subrc NE 0.
CLEAR zsflight .
ENDIF.
ENDFUNCTION.
Enabling
Release
will make it possible for you to use the function module in BAPI. To do this, you must pass the following path (Function Module
| Release
| Release
):
In the resulting screen, click on the
Utilities
drop-down menu and check what methods are provided by default. There should be two methods that are available when creating the BAPI. Next, navigate to Utilities
| API Methods
| Add Method
:
Then, set
Object Type
to the To implemented
status, as demonstrated in the following screenshot:
Finally, generate a BAPI that will be visible to external sites, as demonstrated in the following screenshot:
Comments
Post a Comment