Free SAP Training & Tutorial A Free SAP Functional And Technical Tutorial And Training For ABAP, SAP QUERY, ALV, SMARTFORMS, SD, PP, MM, QM, FICO
02.08.2010 | Author: | Posted in ABAP 

Today I want to teach you how to display ALV grid using a dynamic internal table, in this program sample, you will create one input parameter for the transparent table that you want to show in the ALV grid.

Now execute tcode SE38 and just create an ABAP program called Z_DYNAMIC_ALV_GRID_TABLE.

Copy this ABAP code below.


REPORT  Z_DYNAMIC_ALV_GRID_TABLE.

* Display ALV Grid Using Dynamic Internal Table
* www.freesaptutorial.com

TYPE-POOLS: SLIS.

DATA:
LD_ST_TABLE   TYPE REF TO DATA,
ITAB    TYPE REF TO DATA,
ST_DESC   TYPE REF TO CL_ABAP_STRUCTDESCR,
IS_LAYOUT   TYPE SLIS_LAYOUT_ALV,
L_FIELDCAT  TYPE LVC_S_FCAT,
T_FIELDCAT  TYPE LVC_T_FCAT,
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

*Declare ALV Grid Tilte
DATA :
Title1(30),
Title2(10),
Title3(50).

*Declare Field Symbols
FIELD-SYMBOLS :
  <IT_TABLE>    TYPE STANDARD TABLE,
  <DYN_STR>         TYPE ANY,
  <STR_COMP> TYPE ABAP_COMPDESCR.

*The parameter selection where we put the transparent
*table name

PARAMETERS :
P_ITAB LIKE DD02L-TABNAME.

INITIALIZATION.

START-OF-SELECTION.

*texts for grid title
  Title1 = 'Dynamic ALV Grid Table'.
  Title2 = P_ITAB.

  CONCATENATE Title1 Title2 INTO Title3 SEPARATED BY SPACE.

* Create structure for dynamic table
  CREATE DATA LD_ST_TABLE TYPE (P_ITAB).
  ASSIGN LD_ST_TABLE->* TO <DYN_STR>.

* Dynamic table Fields Structure
  ST_DESC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <DYN_STR> ).

  LOOP AT ST_DESC->COMPONENTS ASSIGNING <STR_COMP>.
*   Build the Fieldcatalog
    L_FIELDCAT-FIELDNAME = <STR_COMP>-NAME.
    L_FIELDCAT-REF_TABLE = P_ITAB.
    APPEND L_FIELDCAT TO T_FIELDCAT.
*   Build the Fieldcatalog
    LS_FIELDCAT-FIELDNAME = <STR_COMP>-NAME.
    LS_FIELDCAT-REF_TABNAME = P_ITAB.
    APPEND LS_FIELDCAT TO LT_FIELDCAT.
  ENDLOOP.

* ALV Layout
  IS_LAYOUT-ZEBRA = 'X'.
  IS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  IS_LAYOUT-WINDOW_TITLEBAR = Title3.

* Here we create the dynamic table
  CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
    EXPORTING
      IT_FIELDCATALOG = T_FIELDCAT
    IMPORTING
      EP_TABLE        = ITAB.

  ASSIGN ITAB->* TO <IT_TABLE>.

* Read data from the table selected.

  SELECT * FROM (P_ITAB)
    INTO CORRESPONDING FIELDS OF TABLE <IT_TABLE>.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      is_layout     = IS_LAYOUT
      IT_FIELDCAT   = LT_FIELDCAT
      i_bypassing_buffer = 'X'
      i_callback_program = sy-repid
      i_save             = 'A'
    TABLES
      t_outtab           = <IT_TABLE>. "internal table

      IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

Click F8 to test the program. Now just type in any transparent table in the input box and click EXECUTE (F8)

dit02-01

Here’s the ALV GRID display using a dynamic internal table.

dit02-02

Popularity: 4% [?]

 


 
 

Related Tutorial " ABAP" 

  •  
     
    Recent Tutorials
    Create Table Maintenance Display In SAP Create table display to maintain tables values using SM30
    Create Table Maintenance Generator In SAP Maintaining SAP Transparent table values using maintenance generator
    Table Relationship In SAP Learn How To Find Tables Relationships in SAP
    Convert Number To words Using ABAP Find out how to convert numbers into words Using ABAP
    How To Maintain Long Text Object in SAP Maintain long text object in SAP
    How To Know What TCODE Used In ABAP Program Find TCODE For your ABAP Program Report
    How does CRM Work? Learn how CRM system works to run your business
    Why SAP CRM is the Best Choice? The reasons why CRM application is the best choice
    Difference Between CRM System and CRM Strategy What's the difference between CRM system and its strategy
    CRM for a Better Customer Service Learn how CRM could make your customer service much better
    Costs of Implementing CRM Software Learn the how much cost you need to prepare when implementing CRM
     
    Popular Tutorials
  • (none)
  •  
    Categories
    ABAP   Basis & Configuration  
    ALV SAP BW (Business Warehouse)
    BAPI   SAP Interview Questions
    SAP Tables   SAP Overview
    Transaction Codes FI SAP Query
      MM SAP Script  
      PP SAP Tutorial FI Module
      QM   MM Module
      SD   PM Module
    SAP Functional MM   PP Module
      SD   QM Module
    White Papers     SD Module
    Uncategorized   SmartForms  
      User-Exits  
     
     

     

    Home | About | Contribute | Privacy

    Copyright 2011 freesaptutorial.com.

    Free SAP Tutorial is not associated with SAP AG in Germany or in any other country.

    SAP is a registered trade mark of SAP AG.