SAP ABAP BAPI Example with Flights

Posted on Posted in Uncategorized

What is BAPI:

BAPIs ( Business Application Programming Interface) are specific methods for SAP business objects, which are stored in the Business Object Repository (BOR) of the SAP system and are used for carrying out particular business tasks.

In the SAP system, BAPIs are stored as RFC-capable function modules in the ABAP Workbench Function Builder. BAPIs have standard business interfaces that enable external applications (with the help of SAP business objects) to access SAP processes, functions and data.

Source: https://help.sap.com/saphelp_nw73ehp1/helpdata/en/c2/0da27f769e4c7d99f119110f6a24f4/frameset.htm
Example of using a BAPI:

First question you have to make is: What is the function am I looking for? And instead of starting coding this function, we gonna search in transaction BAPI, and check if there is already a BAPI for this.

Let’s assume we want details from flights:

Ok, we found the Function Module BAPI_FLIGHT_GETDETAIL.

Before implemente, you can test in SE37, check the input parameter and so on. Also in the Documentation tab, you can get more importante information about the BAPI.

Result:

Implementing BAPI in a example, with ABAP OO:

 

*&———————————————————————*
*& Report  Z_TEST_RBAPI
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT z_test_rbapi.

CLASS flight DEFINITION.

PUBLIC SECTION.

METHODSgetflidetails IMPORTING airid  TYPE bapisflkeyairlineid
connid TYPE bapisflkeyconnectid
fldate TYPE bapisflkeyflightdate.

PRIVATE SECTION.

DATAit_fldata TYPE bapisfldat.
DATAit_return TYPE STANDARD TABLE OF bapiret2.

ENDCLASS.

CLASS flight IMPLEMENTATION.

METHODgetflidetails.

CALL FUNCTION ‘BAPI_FLIGHT_GETDETAIL’
EXPORTING
airlineid    airid
connectionid connid
flightdate   fldate
IMPORTING
flight_data  it_fldata
*       ADDITIONAL_INFO       =
*       AVAILIBILITY =
TABLES
*       EXTENSION_IN =
*       EXTENSION_OUT         =
return       it_return.

WRITE‘Company: ‘it_fldataairline‘ From: ‘it_fldatacityfrom‘ To: ‘it_fldatacityto.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

* Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text001.
PARAMETERSp_airid   TYPE bapisflkeyairlineid,
p_connid  TYPE bapisflkeyconnectid,
p_fldate  TYPE bapisflkeyflightdate.
SELECTION-SCREEN END OF BLOCK b1.

* Create object and execute Function Module.
DATAoflight TYPE REF TO flight.
CREATE OBJECT oflight.

oflight->getflidetailsairid p_airid connid p_connid fldate p_fldate ).

 
Result:

Total Views: 327 ,

Leave a Reply

Your email address will not be published. Required fields are marked *