Objective
The objective of this document is to show how to crate a BAdI from its definition to its implementation and how to use it as an
enhancement through a sample program using the flight model tables.
We´ll create a BAdI definition, its implementation class and a report to be enhanced.
This BAdI enhancement allows the user in a report to double-click a row from a list of flights and access its detailed list.
BAdI Definition
Create the following interface with the method 'lineselection' with the corresponding parameters:
Then create the classic BAdI Definition in SE18 according to the screen below:
BAdI Implementation
In SE19 create the BAdI implementation as follows:
Assign the class name ZCL_IM_BC425_IM and the code for lineselection method:
Activate your implementation.
Report
Finally, use the code below for creating the report:
REPORT ZSAPBC425_BADI.
DATA: wa_spfli TYPE spfli,
it_spfli TYPE TABLE OF spfli WITH KEY carrid connid.
*reference variable for BAdI
DATA: exit_ref TYPE REF TO zif_ex_bc425.
*selection screen
SELECTION-SCREEN BEGIN OF BLOCK carrier WITH FRAME TITLE text-car.
SELECT-OPTIONS: so_carr FOR wa_spfli-carrid.
SELECTION-SCREEN END OF BLOCK carrier.
START-OF-SELECTION.
CALL METHOD cl_exithandler=>get_instance
CHANGING
instance = exit_ref.
SELECT *
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE it_spfli
WHERE carrid IN so_carr.
END-OF-SELECTION.
LOOP AT it_spfli INTO wa_spfli.
WRITE: / wa_spfli-carrid,
wa_spfli-connid,
wa_spfli-countryfr,
wa_spfli-cityfrom,
wa_spfli-countryto,
wa_spfli-cityto,
wa_spfli-deptime,
wa_spfli-arrtime.
HIDE: wa_spfli-carrid,
wa_spfli-connid.
ENDLOOP.
AT LINE-SELECTION.
CHECK NOT wa_spfli-carrid IS INITIAL.
CALL METHOD exit_ref->lineselection
EXPORTING
i_carrid = wa_spfli-carrid
i_connid = wa_spfli-connid.
CLEAR wa_spfli.
Results