Challenging & interesting question: assign value to dyna
hi there,
Is there any simple way to move value to a dynamice field in a internal table?
eg.
tab1 contains 3 fields,
row column text
1 2 50.00
1 3 33.00
2 1 66.00
2 4 73.00
tab2 has 4 fields:
f1 f2 f3 f4
I wanna:
move tab1's text '50.00' into tab2-f2.
tab1's text '33.00' into tab2-f3.
append tab2.
move tab1's text '66.00' into tab2-f1.
tab1's text '73.00' into tab2-f4.
append tab2.
now tab2 looks like:
f1 f2 f3 f4
50.00 33.00
66.00 73.00
Hi !!
You can use Fields Symbols to achieve this.
Heres a pseudo code to explain the process...
data : begin of itab occurs 0,
row type i,
col type i,
text(10),
end of itab.
data : begin of jtab occurs 0,
col01(10),
col02(10),
col03(10),
col04(10),
end of jtab.
field-symbols <fs> type any.
data : begin of wa,
f1(8),
f2(2) type n,
end of wa.
move : 1 to itab-row, 2 to itab-col, 'Sudhir' to itab-text.
append itab.
move : 1 to itab-row, 3 to itab-col, 'Akram' to itab-text.
append itab.
move : 2 to itab-row, 1 to itab-col, 'Sudhir' to itab-text.
append itab.
move : 2 to itab-row, 4 to itab-col, 'Sudhir' to itab-text.
append itab.
move : 'JTAB-COL' to wa-f1.
loop at itab.
move : itab-col to wa-f2.
assign (wa) to <fs>.
move : itab-text to <fs>.
at end of row.
append jtab.clear jtab.
endat.
endloop.
loop at jtab.
write:/ jtab.
endloop.
Regards,
Sudhir/Mohit
Dear Laufish:
Rather than by name, I would assign the field by component (F1 on ASSIGN). But what do you do, if table1 contains:
1 2 50.00
1 3 33.00
8 1 66.00
Do you need to insert six blank lines?
Regards,
Wolfgang