Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Generating and accessing table attributes at runtime

Former Member
0 Likes
390

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.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
352

Yes, I believe you can do this thru field symbols.

Regards,

Rich Heilman

2 REPLIES 2
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
353

Yes, I believe you can do this thru field symbols.

Regards,

Rich Heilman

Read only

0 Likes
352

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