Here is a program by which Purchase Order Header and Item are displayed separately by classic report format. We are taking proper Purchase Order (EBELN) from Selection Screen with Select Options and displaying the output by using two separated class and object.
*&---------------------------------------------------------------------* *& Report ZSR_TEST *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zsr_test. TABLES: ekko, ekpo. INITIALIZATION. 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. *----------------------------------------------------------------------* * CLASS cls1 DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cls1 DEFINITION. PUBLIC SECTION. TYPES: BEGIN OF ty_ekko, ebeln TYPE ekko-ebeln, bukrs TYPE ekko-bukrs, bstyp TYPE ekko-bstyp, bsart TYPE ekko-bsart, aedat TYPE ekko-aedat, lifnr TYPE ekko-lifnr, END OF ty_ekko, BEGIN OF ty_t161t, spras TYPE t161t-spras, bsart TYPE t161t-bsart, bstyp TYPE t161t-bstyp, batxt TYPE t161t-batxt, END OF ty_t161t, BEGIN OF ty_out1, ebeln TYPE ekko-ebeln, bukrs TYPE ekko-bukrs, bsart TYPE ekko-bsart, aedat TYPE ekko-aedat, lifnr TYPE ekko-lifnr, batxt TYPE t161t-batxt, END OF ty_out1. DATA: wa_ekko TYPE ty_ekko, it_ekko TYPE STANDARD TABLE OF ty_ekko, wa_t161t TYPE ty_t161t, it_t161t TYPE STANDARD TABLE OF ty_t161t, wa_out1 TYPE ty_out1, it_out1 TYPE STANDARD TABLE OF ty_out1. METHODS: m_ekko, m_t161t, m_out1, m_header. PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. "cls1 DEFINITION *----------------------------------------------------------------------* * CLASS cls2 DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cls2 DEFINITION. PUBLIC SECTION. TYPES: BEGIN OF ty_ekpo, ebeln TYPE ekpo-ebeln, ebelp TYPE ekpo-ebelp, matnr TYPE ekpo-matnr, werks TYPE ekpo-werks, lgort TYPE ekpo-lgort, matkl TYPE ekpo-matkl, menge TYPE ekpo-menge, meins TYPE ekpo-meins, END OF ty_ekpo. DATA: wa_ekpo TYPE ty_ekpo, it_ekpo TYPE STANDARD TABLE OF ty_ekpo. METHODS: m_ekpo, m_item. PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. "cls2 DEFINITION *----------------------------------------------------------------------* * CLASS cls1 IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cls1 IMPLEMENTATION. METHOD m_ekko. SELECT ebeln bukrs bstyp bsart aedat 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'. ENDIF. ENDMETHOD. "m_ekko METHOD m_t161t. IF it_ekko IS NOT INITIAL. SELECT spras bsart bstyp batxt FROM t161t INTO TABLE it_t161t FOR ALL ENTRIES IN it_ekko WHERE spras = sy-langu AND bsart = it_ekko-bsart AND bstyp = it_ekko-bstyp. IF sy-subrc = 0. SORT it_t161t BY bsart bstyp. ENDIF. ENDIF. ENDMETHOD. "m_t161t METHOD m_out1. IF it_ekko IS NOT INITIAL. LOOP AT it_ekko INTO wa_ekko. wa_out1-ebeln = wa_ekko-ebeln. wa_out1-bukrs = wa_ekko-bukrs. wa_out1-bsart = wa_ekko-bsart. wa_out1-aedat = wa_ekko-aedat. wa_out1-lifnr = wa_ekko-lifnr. READ TABLE it_t161t INTO wa_t161t WITH KEY bsart = wa_ekko-bsart bstyp = wa_ekko-bstyp BINARY SEARCH. IF sy-subrc = 0. wa_out1-batxt = wa_t161t-batxt. ENDIF. APPEND wa_out1 TO it_out1. CLEAR: wa_out1, wa_ekko, wa_t161t. ENDLOOP. ENDIF. ENDMETHOD. "m_out1 METHOD m_header. IF it_out1 IS NOT INITIAL. LOOP AT it_out1 INTO wa_out1. AT FIRST. WRITE: /1 'Purchase Order', 15 'Company Code', 30 'PO Type', 40 'Date', 55 'Vendor', 70 'PO Info'. ULINE. SKIP. ENDAT. WRITE: / wa_out1-ebeln, 15 wa_out1-bukrs, 30 wa_out1-bsart, 40 wa_out1-aedat, 55 wa_out1-lifnr, 70 wa_out1-batxt. ENDLOOP. ULINE. SKIP. ELSE. MESSAGE 'Internal Error' TYPE 'I'. ENDIF. ENDMETHOD. "m_header ENDCLASS. "cls1 IMPLEMENTATION *----------------------------------------------------------------------* * CLASS cls2 IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cls2 IMPLEMENTATION. METHOD m_ekpo. SELECT ebeln ebelp matnr werks lgort matkl menge meins FROM ekpo INTO TABLE it_ekpo WHERE ebeln IN s_ebeln. IF sy-subrc = 0. SORT it_ekpo BY ebeln. ENDIF. ENDMETHOD. "m_ekpo METHOD m_item. IF it_ekpo IS NOT INITIAL. LOOP AT it_ekpo INTO wa_ekpo. AT FIRST. WRITE: /1 'Purchase Order', 15 'PO Item', 25 'Material', 45 'Plant', 55 'Storage Location', 75 'Material Group', 90 'Quantity', 105 'Unit'. ULINE. SKIP. ENDAT. WRITE: / wa_ekpo-ebeln, 15 wa_ekpo-ebelp, 25 wa_ekpo-matnr, 45 wa_ekpo-werks, 55 wa_ekpo-lgort, 75 wa_ekpo-matkl, 90 wa_ekpo-menge, 105 wa_ekpo-meins. ENDLOOP. ULINE. SKIP. ENDIF. ENDMETHOD. "m_item ENDCLASS. "cls2 IMPLEMENTATION START-OF-SELECTION. DATA: obj1 TYPE REF TO cls1, obj2 TYPE REF TO cls2. CREATE OBJECT: obj1, obj2. CALL METHOD: obj1->m_ekko, obj1->m_t161t, obj1->m_out1, obj1->m_header. CALL METHOD: obj2->m_ekpo, obj2->m_item.
Selection Screen:
The output is as follows:
This requirement can be done by using Inheritance functionality. Here we are calling the Methods of Header information inside the Item information method defined in the child class. The output is same as already mentioned. Below is the program.
*&---------------------------------------------------------------------* *& Report ZSR_TEST *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zsr_test. TABLES: ekko, ekpo. INITIALIZATION. 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. *----------------------------------------------------------------------* * CLASS cls1 DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cls1 DEFINITION. PUBLIC SECTION. TYPES: BEGIN OF ty_ekko, ebeln TYPE ekko-ebeln, bukrs TYPE ekko-bukrs, bstyp TYPE ekko-bstyp, bsart TYPE ekko-bsart, aedat TYPE ekko-aedat, lifnr TYPE ekko-lifnr, END OF ty_ekko, BEGIN OF ty_t161t, spras TYPE t161t-spras, bsart TYPE t161t-bsart, bstyp TYPE t161t-bstyp, batxt TYPE t161t-batxt, END OF ty_t161t, BEGIN OF ty_out1, ebeln TYPE ekko-ebeln, bukrs TYPE ekko-bukrs, bsart TYPE ekko-bsart, aedat TYPE ekko-aedat, lifnr TYPE ekko-lifnr, batxt TYPE t161t-batxt, END OF ty_out1. DATA: wa_ekko TYPE ty_ekko, it_ekko TYPE STANDARD TABLE OF ty_ekko, wa_t161t TYPE ty_t161t, it_t161t TYPE STANDARD TABLE OF ty_t161t, wa_out1 TYPE ty_out1, it_out1 TYPE STANDARD TABLE OF ty_out1. METHODS: m_ekko, m_t161t, m_out1, m_header. PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. "cls1 DEFINITION *----------------------------------------------------------------------* * CLASS cls2 DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cls2 DEFINITION INHERITING FROM cls1. PUBLIC SECTION. TYPES: BEGIN OF ty_ekpo, ebeln TYPE ekpo-ebeln, ebelp TYPE ekpo-ebelp, matnr TYPE ekpo-matnr, werks TYPE ekpo-werks, lgort TYPE ekpo-lgort, matkl TYPE ekpo-matkl, menge TYPE ekpo-menge, meins TYPE ekpo-meins, END OF ty_ekpo. DATA: wa_ekpo TYPE ty_ekpo, it_ekpo TYPE STANDARD TABLE OF ty_ekpo. METHODS: m_ekpo, m_item. PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. "cls2 DEFINITION *----------------------------------------------------------------------* * CLASS cls1 IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cls1 IMPLEMENTATION. METHOD m_ekko. SELECT ebeln bukrs bstyp bsart aedat 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'. ENDIF. ENDMETHOD. "m_ekko METHOD m_t161t. IF it_ekko IS NOT INITIAL. SELECT spras bsart bstyp batxt FROM t161t INTO TABLE it_t161t FOR ALL ENTRIES IN it_ekko WHERE spras = sy-langu AND bsart = it_ekko-bsart AND bstyp = it_ekko-bstyp. IF sy-subrc = 0. SORT it_t161t BY bsart bstyp. ENDIF. ENDIF. ENDMETHOD. "m_t161t METHOD m_out1. IF it_ekko IS NOT INITIAL. LOOP AT it_ekko INTO wa_ekko. wa_out1-ebeln = wa_ekko-ebeln. wa_out1-bukrs = wa_ekko-bukrs. wa_out1-bsart = wa_ekko-bsart. wa_out1-aedat = wa_ekko-aedat. wa_out1-lifnr = wa_ekko-lifnr. READ TABLE it_t161t INTO wa_t161t WITH KEY bsart = wa_ekko-bsart bstyp = wa_ekko-bstyp BINARY SEARCH. IF sy-subrc = 0. wa_out1-batxt = wa_t161t-batxt. ENDIF. APPEND wa_out1 TO it_out1. CLEAR: wa_out1, wa_ekko, wa_t161t. ENDLOOP. ENDIF. ENDMETHOD. "m_out1 METHOD m_header. IF it_out1 IS NOT INITIAL. LOOP AT it_out1 INTO wa_out1. AT FIRST. WRITE: /1 'Purchase Order', 15 'Company Code', 30 'PO Type', 40 'Date', 55 'Vendor', 70 'PO Info'. ULINE. SKIP. ENDAT. WRITE: / wa_out1-ebeln, 15 wa_out1-bukrs, 30 wa_out1-bsart, 40 wa_out1-aedat, 55 wa_out1-lifnr, 70 wa_out1-batxt. ENDLOOP. ULINE. SKIP. ELSE. MESSAGE 'Internal Error' TYPE 'I'. ENDIF. ENDMETHOD. "m_header ENDCLASS. "cls1 IMPLEMENTATION *----------------------------------------------------------------------* * CLASS cls2 IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS cls2 IMPLEMENTATION. METHOD m_ekpo. CALL METHOD m_ekko. CALL METHOD m_t161t. CALL METHOD m_out1. CALL METHOD m_header. IF it_ekko IS NOT INITIAL. SELECT ebeln ebelp matnr werks lgort matkl menge meins 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. ENDIF. ENDIF. ENDMETHOD. "m_ekpo METHOD m_item. IF it_ekpo IS NOT INITIAL. LOOP AT it_ekpo INTO wa_ekpo. AT FIRST. WRITE: /1 'Purchase Order', 15 'PO Item', 25 'Material', 45 'Plant', 55 'Storage Location', 75 'Material Group', 90 'Quantity', 105 'Unit'. ULINE. SKIP. ENDAT. WRITE: / wa_ekpo-ebeln, 15 wa_ekpo-ebelp, 25 wa_ekpo-matnr, 45 wa_ekpo-werks, 55 wa_ekpo-lgort, 75 wa_ekpo-matkl, 90 wa_ekpo-menge, 105 wa_ekpo-meins. ENDLOOP. ULINE. SKIP. ENDIF. ENDMETHOD. "m_item ENDCLASS. "cls2 IMPLEMENTATION START-OF-SELECTION. DATA: obj2 TYPE REF TO cls2. CREATE OBJECT: obj2. CALL METHOD: obj2->m_ekpo, obj2->m_item.