Classical Report of Multiple Tables


After creating a classic report for single table it's time to create a report which will contain multiple tables.
I’m created a report which contains multiple tables like EKPO and EKKO. The EKPO table contain Purchasing Document Item details and EKKO tables Purchasing Document Header details.

Coding of the classical report:-


REPORT ZPURCHASING_DETAILS.

*-------Declaring database tables---------------------*
tables: EKPO , EKKO.

*-----Declaring work areas & internal tables----------*
types: begin of itab,
      ebeln type ekpo-ebeln,
      ebelp type ekpo-ebelp,
      matnr type ekpo-matnr,
      bukrs type ekko-bukrs,
      ernam type ekko-ernam,
    end of itab.

DATA: it_itab TYPE TABLE OF itab WITH HEADER LINE,
      wa_itab TYPE itab.

data: Prog_name TYPE sy-repid, "Program name
      Date TYPE sy-datum, "Current date
      Time TYPE sy-uzeit. "Current time

*------Event initialization---------------------------*
INITIALIZATION.
  Prog_name = sy-repid.
  Date      = sy-datum.
  Time      = sy-uzeit.

*-----------Declaring selection screen with select option for input----*

selection-screen begin of block block1 with frame title text-001.
select-options: EBELN FOR EKPO-EBELN.
parameter       p_bukrs like ekpo-bukrs.
selection-screen end of block block1.

*-----Event start of selection-----------------------------------------*
START-OF-SELECTION.
  PERFORM get_data.

*---Event end of selection---------------------------------------------*
END-OF-SELECTION.
  PERFORM display.
  PERFORM get_output.


*---Event top of page--------------------------------------------------*
TOP-OF-PAGE.
  PERFORM top_of_page.

*&---------------------------------------------------------------------*
*&      Form  GET_TAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_data .
  IF EBELN IS NOT INITIAL.
   SELECT
    ekpo~EBELN
    ekpo~ebelp
    ekpo~matnr
    ekko~bukrs
    ekko~ernam
     INTO TABLE it_itab from ekpo
     inner join ekko on ekpo~EBELN = ekko~EBELN
      where ekpo~EBELN in EBELN and
            ekko~bukrs = p_bukrs.

    IF sy-subrc = 0.
      SORT it_itab BY EBELN.
    ELSE.
      MESSAGE 'Document Number doesn''t exist' TYPE 'I'.
    ENDIF.
  ENDIF.


endform.
*&---------------------------------------------------------------------*
*&      Form  GET_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_output .

  LOOP AT IT_ITAB INTO WA_ITAB.
      WRITE:/ WA_ITAB-EBELN, 18 sy-vline,
              WA_ITAB-EBELP, 38 sy-vline,
              WA_ITAB-MATNR, 56 sy-vline,
              WA_ITAB-BUKRS, 75 sy-vline,
              WA_ITAB-ERNAM.

    ENDLOOP.

endform.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display .

write: 'Document Number' COLOR ,
    20 'Item Numbe' COLOR ,
    40 'Material' COLOR ,
    57 'Company Code' COLOR ,
    78 'Name of Person' COLOR 5.
uline.

endform.
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form top_of_page .
write: / Prog_name,
       / Date DD/MM/YYYY,
       / Time .
ULINE.
endform.

Selection Screen
























OUTPUT SCREEN