Application Development 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: 

Dynamic Field-Symbols

0 Kudos

Hi.

Currently I have the following code:


field-symbols: <it1> type table.
field-symbols: <it2> type table.
field-symbols: <it3> type table.
..
field-symbols: <it10> type table.

loop at it...assign <fs>
   case counter.
    when '1'.
       assign <fs>-table->* to <it1>
       wa_table-name = '<it1>'.
    when '2'.
       assign <fs>-table->* to <it2>
       wa_table-name = '<it2>'.

    when '3'.
..
..
    when '10'.

endloop.

  • How can I do the same dynamically?*

I don't want to specify the FIELD-SYMBOLS command explicity, only when needed.

I wanted to do something like the following:



data: fs_name type string.
fs_name = '<it >'.
loop..
  write sy-index to fs_name+3(1).
  field-symbols (fs_name) type table.
   assign <fs>-table->* to (fs_name).

endloop.


Thanks

Ariel

  • I have a solution, more like a workaround using INSERT REPORT and there I can build as I wish...

6 REPLIES 6

MarcinPciak
Active Contributor
0 Kudos

All these field symbols are generic


field-symbols: <it1> type table.
field-symbols: <it2> type table.
field-symbols: <it3> type table.

which means you can use any of them to assign different tables to it. The type will be inherited from the dereferenced object. So the generic approach would be


field-symbols: <it> type table.
 
loop at it...assign <fs>
  assign <fs>-table->* to <it>. 
  "here you work with <it> no matter if it is table 1,2 or 10
  "the content and strcutre will be relevant to currently "pointed" table
endloop.

Regards

Marcin

0 Kudos

Hi..

I need to address all these tables in one command line:


export it1 = <it1> it2 = <it2> ...

That is why I need a different Fielld-symbol for each table.

Thanks

Ariel

0 Kudos

So, I am afraid you won't be able to address them all at once. You will need 10 field symbols defined explicitly as the field symbol can't be defined dynamicly itself. It can only "point" to some data generic data.

You can however address export statement dynamically like below


data: begin of it_dyn_exp occurs 0,
            exp_par type string,
            exp_data type string,
         end of it_dyn_exp.

field-symbols: <it> type table.
 
loop at it...assign <fs>
  assign <fs>-table->* to <it>. 
  
  concatenate 'IT' counter into it_dyn_exp-exp_par.  "EXPORT parameter name
  it_dyn_exp-exp_data = '<IT>'.  "data name
  append it_dyn_exp.

 export (it_dyn_exp[]) to memory id 'SOME_ID'. "export i.e IT1 = <IT>
 refresh it_dyn_exp.
endloop.

Regards

Marcin

0 Kudos

I used this concept together with insert report thus created the field-symbols "dynamically", Since the report was dynamically created in the generated code,

Thanks

Ariel

0 Kudos

Hello Ariel,

Good info from this post. However now I have a requirement where the field symbols need to be created dynamically. Could you please let me know in more detailed way how to do this.

Regards,

Bala.

Former Member
0 Kudos

Hi Ariel Fisher Sir,

I have the same requirement consisting of about 10 field symbols, and I cannot be declaring them as it is. Please share the coding of which you have created field-symbols dynamically. I can better understand your logic then. I am unable to deduce how you have achieved the same using "INSERT REPORT". Please help in this regard. Thanks. -Tom Jerry.