Home > ABAP > Dynamic Internal Table

Dynamic Internal Table

February 27th, 2009

REPORT YVERA_DYNAMICTABLE .

DATA: D_REF TYPE REF TO DATA,
D_REF2 TYPE REF TO DATA ,
I_ALV_CAT TYPE TABLE OF LVC_S_FCAT,
LS_ALV_CAT LIKE LINE OF I_ALV_CAT.

TYPES TABNAME LIKE DCOBJDEF-NAME .
PARAMETER: P_TABLEN TYPE TABNAME.

DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE DNTAB.
DATA: END OF ITAB.

FIELD-SYMBOLS : <F_FS> TYPE TABLE,
<F_FS1> TYPE TABLE,
<F_FS2> TYPE ANY,
<F_FS3> TYPE TABLE.

REFRESH ITAB.
CALL FUNCTION ‘NAMETAB_GET’
EXPORTING
LANGU          = SY-LANGU
TABNAME        = P_TABLEN
TABLES
NAMETAB        = ITAB
EXCEPTIONS
NO_TEXTS_FOUND = 1.
LOOP AT ITAB .
LS_ALV_CAT-FIELDNAME = ITAB-FIELDNAME.
LS_ALV_CAT-REF_TABLE = P_TABLEN.
LS_ALV_CAT-REF_FIELD = ITAB-FIELDNAME.
APPEND LS_ALV_CAT TO I_ALV_CAT.
ENDLOOP.
* internal table build
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING IT_FIELDCATALOG = I_ALV_CAT
IMPORTING EP_TABLE = D_REF .
ASSIGN D_REF->* TO <F_FS>.

SELECT * FROM (P_TABLEN) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.

LOOP AT <F_FS> ASSIGNING <F_FS2>.
write:/ <f_fs2>.
*your code goes here.
ENDLOOP.

vera ABAP

  1. No comments yet.
  1. No trackbacks yet.