How to create ALV Interactive Report in SAP ABAP

What is SAP ALV? 


ALV stands for ABAP List Viewer. ALV gives us a standard List format and user interface to all our ABAP reports. ALV is created by a set of standard function modules provided by SAP.

ALV provides a lot of inbuilt functions to our reports and some of the functions  are listed below.

Sorting of records
Filtering of records
Totals and Sub-totals
Download the report output to Excel/HTML
Changing the order of the columns in the report
Hide the unwanted columns  from the report
Because of the above functions, ALV substantially decreases the report development time. ALV takes care of rendering the list and we can concentrate only on the data retrieval part.

Some of the function modules used to create ALV reports are listed below.

Function Module                         Description
REUSE_ALV_LIST_DISPLAY Display an ALV list
REUSE_ALV_GRID_DISPLAY Display an ALV grid
REUSE_ALV_COMMENTARY_WRITE Output List header information
REUSE_ALV_VARIANT_F4 Display variant selection dialog box
REUSE_ALV_VARIANT_EXISTENCE Checks whether a variant exists
REUSE_ALV_FIELDCATALOG_MERGE Create field catalog from dictionary structure or internal table

How to create ALV Interactive Report in SAP ABAP


*&---------------------------------------------------------------------*
*& Report  ZDEMO_PROGRAM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZDEMO_PROGRAM.
*report program started


TYPE-POOLSslis.  " SLIS contains all the ALV data types



TYPES BEGIN OF TY_MARA,  "User defined internal table type
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.

DATA IT_MARA TYPE TABLE OF TY_MARA ."internal table
DATA WA_MARA TYPE TY_MARA "work area

DATA IT_FCAT TYPE SLIS_T_FIELDCAT_ALV "field catalog table
DATA WA_FCAT LIKE LINE OF IT_FCAT "field catalog work area
PARAMETERS P_MTART TYPE MARA-MTART"material type input

START-OF-SELECTION.
**get table data
  SELECT MATNR MTART MBRSH MEINS FROM MARA "get data from MARA
      INTO TABLE IT_MARA UP TO 50 ROWS
      WHERE MTART P_MTART.
*** generate field catalogue
  WA_FCAT-COL_POS '1' "column position
  WA_FCAT-FIELDNAME 'MATNR' "column name
  WA_FCAT-TABNAME 'IT_MARA' "table
  WA_FCAT-SELTEXT_M 'Material' "Column label
  WA_FCAT-KEY 'X' "is a key field
  WA_FCAT-HOTSPOT 'X' "Set hotspot for matnr
  APPEND WA_FCAT TO IT_FCAT "append to fcat
  CLEAR WA_FCAT .
  WA_FCAT-COL_POS '2' .
  WA_FCAT-FIELDNAME 'MBRSH' .
  WA_FCAT-TABNAME 'IT_MARA' .
  WA_FCAT-SELTEXT_M 'Industry Sec' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .

  WA_FCAT-COL_POS '3' .
  WA_FCAT-FIELDNAME 'MTART' .
  WA_FCAT-TABNAME 'IT_MARA' .
  WA_FCAT-SELTEXT_M 'Material Type' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .

  WA_FCAT-COL_POS '4' .
  WA_FCAT-FIELDNAME 'MEINS' .
  WA_FCAT-TABNAME 'IT_MARA' .
  WA_FCAT-SELTEXT_M 'Base.Unit' .
  WA_FCAT-REF_TABNAME 'MARA' .
  APPEND WA_FCAT TO IT_FCAT .
  CLEAR WA_FCAT .
**display ALV
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM      SY-REPID
      I_CALLBACK_USER_COMMAND 'USER_COMMAND' "user command form
      IT_FIELDCAT             IT_FCAT "PASS FIELD CATALOG TO ALV
    TABLES
      T_OUTTAB                IT_MARA"output table

**for to handle user command
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                        RS_SELFIELD TYPE SLIS_SELFIELD.
  CASE R_UCOMM.
    WHEN '&IC1'"standard Function code for doubel click
      READ TABLE IT_MARA INTO WA_MARA INDEX RS_SELFIELD-TABINDEX.
      IF SY-SUBRC 0.
        SET PARAMETER ID 'MAT' FIELD WA_MARA-MATNR"set parameter id
        CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN"call transaction
      ENDIF.
  ENDCASE.
ENDFORM.                    "user_command


Input screen:
How to create ALV Interactive Report in SAP ABAP
Primary Ouput:
How to create ALV Interactive Report in SAP ABAP
Now click on the material value,we will get the secondary output list:
How to create ALV Interactive Report in SAP ABAP


Popular posts from this blog

How to create Interactive Report in SAP ABAP

BDC Call Transaction Method Program