Simple Reporting Using ALV ( ABAP List Viewer ) with Dinamic Structure






This is the simple report using one of SAP reporting method, ALV ( ABAP List Viewer ).
There are  two types of output displayed after program executing. Grid and List.
Here we created a grid report,displaying data from standard table or customized table.


We able to define the table we need to display, and how many record we require to shown in report as below result.



Here the code:


REPORT YLISTTABLE.



* Type pools declaration for ALV

TYPE-POOLSSLIS.


* Declarations for ALV
DATAG_DYNTABLE  TYPE REF TO DATA,
      LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      IS_LAYOUT   TYPE SLIS_LAYOUT_ALV.

* Field symbols declarations for dynamic table
FIELD-SYMBOLS <FT_TABLE> TYPE STANDARD TABLE.

* Input the name of the table
PARAMETERSP_TABLE TYPE DD02L-TABNAME OBLIGATORY,
            P_ROW   TYPE NUM10 DEFAULT '10'.

* Start of Selection event
START-OF-SELECTION.

  " Create internal table of dynamic type
  CREATE DATA G_DYNTABLE TYPE STANDARD TABLE OF (P_TABLEWITH NON-UNIQUE DEFAULT KEY.
  ASSIGN G_DYNTABLE->TO <FT_TABLE>.
  " Select Database
  SELECT INTO CORRESPONDING FIELDS OF TABLE <FT_TABLE> FROM (P_TABLEUP TO P_ROW ROWS.

  "  Construct Fields
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME         SY-REPID
      I_STRUCTURE_NAME       P_TABLE
    CHANGING
      CT_FIELDCAT            LT_FIELDCAT
    EXCEPTIONS
      INCONSISTENT_INTERFACE 1
      PROGRAM_ERROR          2
      OTHERS                 3.
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.


  IS_LAYOUT-ZEBRA 'X'.
  IS_LAYOUT-NO_COLHEAD ' '.
  IS_LAYOUT-COLWIDTH_OPTIMIZE ='X'.
  IS_LAYOUT-WINDOW_TITLEBAR | Display table{ P_TABLE }|.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      IS_LAYOUT     IS_LAYOUT
      IT_FIELDCAT   LT_FIELDCAT
    TABLES
      T_OUTTAB      <FT_TABLE>
    EXCEPTIONS
      PROGRAM_ERROR 1
      OTHERS        2.
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.



Comments

Popular posts from this blog

Using Cursor in ABAP

Call ABAP Webdynpro Application from a R/3 Transaction