Developing a Interactive report in SAP ABAP

Developing a interactive report to display materials and material plants in SAP ABAP

+ -
Requirement: Develop an interactive report to display material basic details in basic list, material plant details in secondary list for a material type input and display header and footer for primary and secondary list.

Requirement Analysis: In the above requirement, we have to get material details for a material type input (Parameter input for MTART field), whenever the user double clicks on any record of basic list, it will go to the second screen and display list plants for that material, display page header and footer for the report.

SAP Tables to be used are: MARA(Material Master), MARC(Material Plants).

Step1: Define report heading.

Go to SE38, create a program ZSAPN_INTERACTIVE_REPORT.In order to display footer information we have to provide some space for the footer, it can be defined in the report definition(First line of the report), to provide space for footer we use below syntax.
REPORT ZSAPN_INTERACTIVE_REPORT LINE-COUNT 34(2) NO STANDARD PAGE HEADING. "Leave some pages for footer and hide standard heading
In the above deceleration we have provided 34 lines for report and 2 lines for footer i:e 34(2), we don`t need a standard page heading so we used NO STANDARD PAGE HEADING.

Step2:Data decelerations and Selection screen.

Declare the required internal tables, work areas, variables etc. and add selection screen element parameter for material type input.
DATA : IT_MARA TYPE TABLE OF MARA, "mara internal table
       WA_MARA TYPE MARA, "mara work area
       IT_MARC TYPE TABLE OF MARC, "marc internal table
       WA_MARC TYPE MARC. "marc work area

PARAMETERS P_MTART TYPE MARA-MTART. "Selection screen element input field

Step3: Add code to get material basic details.

Add logic to get materials for the material type input under START-OF-SELECTION event.
START-OF-SELECTION.
  SELECT * FROM MARA
    INTO TABLE IT_MARA
    WHERE MTART = P_MTART.

Display materials and use HIDE technique

Display materials and use HIDE technique( HIDE area) to store line data.
  LOOP AT IT_MARA INTO WA_MARA.
    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MBRSH.
    HIDE WA_MARA. "store line details in HIDE area
  ENDLOOP.

Step4: Get plant details using hide area

Get material plants from MARC table based on HIDE area storage under AT LINE-SELECTION event.
AT LINE-SELECTION.
  SELECT * FROM MARC
    INTO TABLE IT_MARC
    WHERE MATNR = WA_MARA-MATNR.

Step5: Display plant data

Display material plant data.
  LOOP AT IT_MARC INTO WA_MARC.
    WRITE :/ WA_MARC-MATNR, WA_MARC-WERKS.
  ENDLOOP.

Step6:Display top of page for basic list and secondary list

Display page heading for basic list under TOP-OF-PAGE event and display secondary list heading under TOP-OF-PAGE DURING LINE-SELECTION event.
TOP-OF-PAGE.
  WRITE : 'Material Basic Details' COLOR 5.
TOP-OF-PAGE DURING LINE-SELECTION.
  WRITE: 'List of Plants for material:', WA_MARA-MATNR COLOR 6.

Step7: Display footer for basic list

Display footer information for basic material list.
  WRITE: 'Report Generated at:', SY-DATUM COLOR 1.

Final report after modularization is below

REPORT ZSAPN_INTERACTIVE_REPORT LINE-COUNT 33(3) NO STANDARD PAGE HEADING. "leave some pages for footer and hide standard heading
DATA : IT_MARA TYPE TABLE OF MARA, "mara internal table
       WA_MARA TYPE MARA, "mara work area
       IT_MARC TYPE TABLE OF MARC, "marc internal table
       WA_MARC TYPE MARC. "marc work area

PARAMETERS P_MTART TYPE MARA-MTART. "selection screen element input field

INITIALIZATION. "initialization event

AT SELECTION-SCREEN. "at selection screen event to validate inputs
  PERFORM VALIDATE_INPUT. "Subroutine to validate input

START-OF-SELECTION.
  PERFORM GET_MATERIAL_DATA.
  PERFORM DISPLAY_MATERIALS.

TOP-OF-PAGE.
  PERFORM DISPLAY_HEADER.

END-OF-PAGE.
  PERFORM DISPLAY_FOOTER.

AT LINE-SELECTION.
  PERFORM GET_PLANT_DATA.
  PERFORM DISPLAY_PLANT_DATA.

TOP-OF-PAGE DURING LINE-SELECTION.
  PERFORM DISPLAY_LIST_HEADER.
FORM VALIDATE_INPUT .
  IF P_MTART IS INITIAL.
    MESSAGE 'Please enter input' TYPE 'E'.
  ENDIF.
ENDFORM.                    " VALIDATE_INPUT

FORM GET_MATERIAL_DATA .
  SELECT * FROM MARA
    INTO TABLE IT_MARA
    UP TO 50 ROWS
    WHERE MTART = P_MTART .
ENDFORM.                    " GET_MATERIAL_DATA
FORM DISPLAY_MATERIALS .
  LOOP AT IT_MARA INTO WA_MARA.
    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MBRSH.
    HIDE WA_MARA. "store line details in HIDE area
  ENDLOOP.
ENDFORM.                    " DISPLAY_MATERIALS
FORM DISPLAY_HEADER .
  WRITE : 'Material Basic Details' COLOR 5.
ENDFORM.                    " DISPLAY_HEADER

FORM DISPLAY_FOOTER .
  WRITE: 'Report Generated at:', SY-DATUM COLOR 1.
ENDFORM.                    " DISPLAY_FOOTER
FORM GET_PLANT_DATA .
  SELECT * FROM MARC
    INTO TABLE IT_MARC
    WHERE MATNR = WA_MARA-MATNR.
ENDFORM.                    " GET_PLANT_DATA
FORM DISPLAY_PLANT_DATA .
  LOOP AT IT_MARC INTO WA_MARC.
    WRITE :/ WA_MARC-MATNR, WA_MARC-WERKS.
  ENDLOOP.
ENDFORM.                    " DISPLAY_PLANT_DATA

FORM DISPLAY_LIST_HEADER .
  WRITE: 'List of Plants for material:', WA_MARA-MATNR COLOR 6.
ENDFORM.                    " DISPLAY_LIST_HEADER

Unit Testing

To test the above report go to MARA table(SE11-MARA-DISPLAY-CONTENETS), get a material type ex: FERT, HALB etc, execute the report, provide material type and execute. The list of materials will be displayed, double click on any record, the corresponding material plants will be displayed in secondary list.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 48 People out of 51 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →