Skip to Content
author's profile photo Former Member
Former Member

Generating and accessing table attributes at runtime

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Feb 10, 2005 at 05:17 PM

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

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.