‎2005 Feb 10 5:14 PM
Hi All,
I am trying to access an internal table's attributes using attribute names generated at runtime. For example,
-
DATA: cnt TYPE n VALUE 1,
new_field TYPE char10.
DO 10 TIMES.
concatenate 'test' cnt into new_field.
write \ itab-new_field.
add 1 to cnt.
ENDDO.
-
But unfortunately, it gives me an error because component itab-new_field doesn't exist. However, component itab-test1, itab-test2, itab-test3 does exist.
Is there a way to refer to table components through dynamic variables rather than component names?
Thanks in advance for your help.
Roman D.
‎2005 Feb 10 5:17 PM
‎2005 Feb 10 5:17 PM
‎2005 Feb 10 5:24 PM
Here is a short sample.
report zrich_0001 .
data: begin of x occurs 0,
test1 type c,
test2 type c,
test3 type c,
end of x.
data: cnt type n value 1,
new_field type char10.
field-symbols: <fs> .
start-of-selection.
x-test1 = '1'.
x-test2 = '2'.
x-test3 = '3'.
append x.
x-test1 = '4'.
x-test2 = '5'.
x-test3 = '6'.
append x.
loop at x.
do 3 times.
concatenate 'x-test' cnt into new_field.
assign (new_field) to <fs>.
write:/ <fs>.
add 1 to cnt.
enddo.
cnt = 1.
endloop.
Regards,
Rich Heilman