Google Search - Blog...........

ABAP - Defining Dynamic Internal Tables Using Method cl_alv_table_create.

REPORT zdynamic.

FIELD-SYMBOLS: TYPE table,
TYPE ANY,
TYPE ANY.

DATA: is_lvc_cat TYPE lvc_s_fcat,
it_lvc_cat TYPE lvc_t_fcat.

DATA: new_table TYPE REF TO data,
new_line TYPE REF TO data.


START-OF-SELECTION.

is_lvc_cat-fieldname = 'KUNNR'.
APPEND is_lvc_cat TO it_lvc_cat.

is_lvc_cat-fieldname = 'NAME1'.
APPEND is_lvc_cat TO it_lvc_cat.

CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_lvc_cat
IMPORTING
ep_table = new_table.

*Create a new Line with the same structure of the table.
ASSIGN new_table->* TO .
CREATE DATA new_line LIKE LINE OF .
ASSIGN new_line->* TO .


DO 2 TIMES.
ASSIGN COMPONENT 'KUNNR' OF STRUCTURE TO .
= sy-index.

ASSIGN COMPONENT 'NAME1' OF STRUCTURE TO .
= 'A'.
INSERT INTO TABLE .
ENDDO.

LOOP AT INTO .
WRITE:/ .
ENDLOOP.

READ TABLE INTO INDEX 2.
+10(2) = 'B'.
MODIFY FROM INDEX 2.


LOOP AT INTO .
WRITE:/ .
ENDLOOP.

No comments:

Post a Comment