Skip to Content
0
Jan 12, 2016 at 03:31 AM

ALV with variable number of columns

25 Views

Hi Gurus,

I want to print alv in a dynamic manner, like below, field should increase dynamically. I tried below

Input

Group Text1 Field1 Field2

25 Iron abc def

25 Iron sss mmm

46 Copper Jack Ran

46 copper Rob Jim

46 copper Sarn Debr

Output

Group Text1 field1 field2 field1 field2 field1 field2

25 Iron abc def sss mmm

46 Copper jack ran rob jim sarn debr

I tried below method, but i dont know how to proceed. Please help.

LOOP AT git_output INTO gwa_output.

READ TABLE <gfs_dyn_table> INTO <gfs_line1> WITH KEY ('PLNNR') = gwa_output-plnnr.

IF sy-subrc = 0.

CONTINUE.

ENDIF.

count = 2.

ASSIGN COMPONENT 'PLNNR' OF STRUCTURE <gfs_line> TO <fs1>.

<fs1> = gwa_output-plnnr.

UNASSIGN <fs1>.

ASSIGN COMPONENT 'PLNAL' OF STRUCTURE <gfs_line> TO <fs1>.

<fs1> = gwa_output-plnal.

UNASSIGN <fs1>.

Endloop.

Then loop again same gt_output to fetch remaining column in dynamic manner,

case wa_flname.

ASSIGN COMPONENT gwa_dyn_fcat-fieldname OF STRUCTURE <gfs_line> TO <fs1>.

ASSIGN COMPONENT wa_flname OF STRUCTURE <gfs_line> TO <fs1>.

if lv_num = 'FIELD9'."WA_FLNAME."

<fs1> = lv_vornr.

UNASSIGN <fs1>.

ELSEif lv_num = 'FIELD10'.

<fs1> = lv_steus.

UNASSIGN <fs1>.

ELSEif lv_num = 'FIELD11'.

<fs1> = lv_ltxa1.

UNASSIGN <fs1>.

ELSEif lv_num = 'FIELD12'.

<fs1> = lv_arbid.

UNASSIGN <fs1>.

endloop.

APPEND <gfs_line> TO <gfs_dyn_table>.

CLEAR: <gfs_line>.

I'm new to this dynamic concept. If anyone tried like this, kindly help on. TIA.

Message was edited by: Matthew Billingham