We can create nested Interface by declaring one Interface in another Interface. We know to declare Interface in the class. The same syntax is followed here. In the class we only have to declare the Final Interface in public section.
The following program contains Interface it1 and it2. It2 declares it1 inside. In the it1 we have two methods mit1 and mit2. Similarly in the it2 we have two methods mit1 and mit2. Now in mit1 of it1 we Select from EKKO and mit2 of it1 we Select from EKPO for all entries in internal table it_ekko. Next we have mit1 in it2 and mit2 in it2. In mit1 we are preparing the final output table whereas in mit2 we are preparing the Output. After all these in start of selection we create an object obj referenced to class cls. Next we call method mit1 and mit2 of it1 and mit1 and mit2 of it2 by object obj.
*&---------------------------------------------------------------------*
*& Report ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsr_test.
TABLES: ekko, ekpo.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* INTERFACE it1
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE it1.
METHODS: mit1, mit2.
ENDINTERFACE. "it1
*----------------------------------------------------------------------*
* INTERFACE it2
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE it2.
METHODS: mit1, mit2.
INTERFACES it1.
ENDINTERFACE. "it2
*----------------------------------------------------------------------*
* CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
lifnr TYPE ekko-lifnr,
END OF ty_ekko,
BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
END OF ty_ekpo,
BEGIN OF ty_out,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
bukrs TYPE ekko-bukrs,
lifnr TYPE ekko-lifnr,
END OF ty_out.
DATA: wa_ekko TYPE ty_ekko,
wa_ekpo TYPE ty_ekpo,
wa_out TYPE ty_out,
it_ekko TYPE STANDARD TABLE OF ty_ekko,
it_ekpo TYPE STANDARD TABLE OF ty_ekpo,
it_out TYPE STANDARD TABLE OF ty_out.
INTERFACES it2.
ENDCLASS. "cls DEFINITION
*----------------------------------------------------------------------*
* CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls IMPLEMENTATION.
METHOD it1~mit1.
SELECT ebeln bukrs lifnr FROM ekko INTO TABLE it_ekko
WHERE ebeln IN s_ebeln.
IF sy-subrc = 0.
SORT it_ekko BY ebeln.
ELSE.
MESSAGE 'Purchase Order Doesn''t Exist' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDMETHOD. "it1~mit1
METHOD it1~mit2.
SELECT ebeln ebelp matnr werks lgort
FROM ekpo INTO TABLE it_ekpo
FOR ALL ENTRIES IN it_ekko
WHERE ebeln = it_ekko-ebeln.
IF sy-subrc = 0.
SORT it_ekpo BY ebeln ebelp.
ENDIF.
ENDMETHOD. "it1~mit2
METHOD it2~mit1.
IF it_ekpo IS NOT INITIAL.
LOOP AT it_ekpo INTO wa_ekpo.
wa_out-ebeln = wa_ekpo-ebeln.
wa_out-ebelp = wa_ekpo-ebelp.
wa_out-matnr = wa_ekpo-matnr.
wa_out-werks = wa_ekpo-werks.
wa_out-lgort = wa_ekpo-lgort.
READ TABLE it_ekko INTO wa_ekko
WITH KEY ebeln = wa_ekpo-ebeln BINARY SEARCH.
IF sy-subrc = 0.
wa_out-bukrs = wa_ekko-bukrs.
wa_out-lifnr = wa_ekko-lifnr.
ENDIF.
APPEND wa_out TO it_out.
CLEAR: wa_out, wa_ekko, wa_ekpo.
ENDLOOP.
ENDIF.
ENDMETHOD. "it2~mit1
METHOD it2~mit2.
IF it_out IS NOT INITIAL.
LOOP AT it_out INTO wa_out.
AT FIRST.
WRITE: / 'Purchase Order',
18 'Item',
26 'Material',
48 'Plant',
55 'Storage',
65 'Company',
75 'Vendor'.
ULINE.
SKIP.
ENDAT.
WRITE: / wa_out-ebeln,
18 wa_out-ebelp,
26 wa_out-matnr,
48 wa_out-werks,
55 wa_out-lgort,
65 wa_out-bukrs,
75 wa_out-lifnr.
ENDLOOP.
ENDIF.
ENDMETHOD. "it2~mit2
ENDCLASS. "cls IMPLEMENTATION
START-OF-SELECTION.
DATA obj TYPE REF TO cls.
CREATE OBJECT obj.
CALL METHOD: obj->it1~mit1,
obj->it1~mit2,
obj->it2~mit1,
obj->it2~mit2.
Below is the Output:
Output:
2 comments:
Thanks for the great information in your blog SAP Success FactorsTraining in Chennai
Thank you provide valuable information and i am searching same information's,and saved my time
sap hr apap training
Post a Comment