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

Data Declaration

former_member426550
Participant
0 Likes
702

hi experts..

is it possible to declare a Internal table/variable with dynamic name?

do 10 times.

concatenate 'table' sy-tabix into lv_name.

data (lv_name) type i.

enddo.

thanks,

6 REPLIES 6
Read only

Former Member
0 Likes
671

HI

Read only

former_member386202
Active Contributor
0 Likes
671

Hi,

yes you can but dont use bracket

do 10 times.

data lv_name type i.

concatenate 'table' sy-tabix into lv_name.

enddo.

Regards,

PRashant

Read only

former_member426550
Participant
0 Likes
671

any update experts?

Read only

0 Likes
671

try this.

do 10 times.

data lv_name(8) type c.

concatenate 'table' sy-tabix into lv_name.

enddo.

Read only

matt
Active Contributor
0 Likes
671

You can obviously do it through dynamic program generation. And depending on your version, you might have to. You can't however, do it directly.

This sample program, which works in 700 (and make work in earlier versions), creates a ten-times table.

TYPES: my_table_type TYPE STANDARD TABLE OF i WITH NON-UNIQUE KEY table_line.

DATA: t_ref     TYPE STANDARD TABLE OF REF TO data WITH NON-UNIQUE KEY table_line,
      p_data    TYPE REF TO data,
      v_count   TYPE i,
      v_mult    TYPE i,
      v_product TYPE i.

FIELD-SYMBOLS: <mytab> TYPE my_table_type,
               <ref>   TYPE REF TO data,
               <val>   TYPE i.

DO 10  TIMES.

  CREATE DATA p_data TYPE my_table_type.
  INSERT p_data INTO TABLE t_ref.
  ASSIGN p_data->* TO <mytab>.

  ADD 1 TO v_count.

  v_mult = 0.
  DO 10 TIMES.
    ADD 1 TO v_mult.
    v_product = v_mult * v_count.
    INSERT v_product INTO TABLE <mytab>.
  ENDDO.

ENDDO.

v_count = 0.

LOOP AT t_ref ASSIGNING <ref>.
  ADD 1 TO v_count.
  WRITE: / 'Table', v_count.
  ULINE.
  ASSIGN <ref>->* TO <mytab>.
  LOOP AT <mytab> ASSIGNING <val>.
    WRITE <val>.
  ENDLOOP.
  ULINE.
ENDLOOP.

What you are doing is creating references to tables, and storing those in an internal table. When you need to handle the tables, you then dereference them into a field symbol, and use them as normal.

If the type of the tables varies, you can use the same principle, but it is more complex, and requires RTTS.

matt

Read only

0 Likes
671

hi...

thank u for ur reply..

my requirement is to save the data in dynamic variale/table...

i already generated the table structure and assign the data to temp structure..

i want to create a variable with dynamic name and assign the data to the dynamic variable created inside the loop statement...

loop at gt_pricing.

concatenate 'A' 906' into lv_tablename.

data lv_tablename(8) type c.

*---my requirement is to assign the data from temp structure to lv_tablename(A906)

endloop.