Thursday, 3 July 2014

Develop a ALV report to display material details with all fields from MARA table for a material range input(Select-Options input).

+ -
Requirement: Develop a ALV report to display material details with all fields from MARA table for a material range input(Select-Options input).
In this requirement we have to display all fields from MARA (Material master table) in ALV format. We use REUSE_ALV_GRID_DISPLAY Function module to display ALV report.

Steps to create ALV Report with Structure .

Step1: Declare Internal table for MARA table.
Step2: Print Select-Options.
Step3: Get data from database using select statements.
Step4: Call Function Module REUSE_ALV_GRID_DISPLAY and pass structure name, program name and itab name.
TABLES : MARA. "DECLARE TABLE FOR SELECT-OPTIONS
DATA : IT_MARA TYPE TABLE OF MARA. "DECLARE INTERNAL TABLE FOR MARA
DATA : WA_MARA TYPE MARA.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR. "PRINT SELECT-OPTIONS FOR MATNR
START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE IT_MARA
                   WHERE MATNR IN S_MATNR .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' "CALL FUNCTION MODULE TO DISPLAY ALV GRID
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID "SY-REPID IS A SYSTEM VARIABLE WHICH STORES CURRENT PROGRAM NAME
I_STRUCTURE_NAME = 'MARA'
TABLES
T_OUTTAB = IT_MARA. "PASS INTERNAL TABLE TO DISPLAY ALV FORMAT
The above report after modularization
The below one is full report after using modularization techniques.
*&---------------------------------------------------------------------*
*& Report  ZALV_STR
*&
*&---------------------------------------------------------------------*

REPORT  ZALV_STR.
TABLES: MARA.
DATA : IT_MARA TYPE TABLE OF MARA .


SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.

START-OF-SELECTION .
  PERFORM GET_MARA_DATA . "Double click to create below form

END-OF-SELECTION .
  PERFORM DISP_MARA_ALV . "Double click to create below form

*&---------------------------------------------------------------------*
*&      Form  GET_MARA_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_MARA_DATA .
  SELECT * FROM MARA
      INTO TABLE IT_MARA 
      WHERE MATNR IN S_MATNR
       .
ENDFORM.                    " GET__MARA_DATA
*&---------------------------------------------------------------------*
*&      Form  DISP_MARA_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISP_MARA_ALV .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      I_STRUCTURE_NAME   = 'MARA'
    TABLES
      T_OUTTAB           = IT_MARA.

ENDFORM.                    " DISP_MARA_ALV

1 comment:

  1. Thanks for using resource from https://www.sapnuts.com/courses/core-abap/alv-reports/alv-structure.html

    Some broken links are there please update

    ReplyDelete