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

Passing internal table field dynamically in a LOOP

stefan_kolev4
Participant
0 Likes
2,740

Hi All,

I have an interanl table ( gt_table ) which records are as follows:

fldname|spos|epos

fld1          0     10

fld2          10     15

fld3          15     12

Of course this is an example

I need to pass an internal table field dynamically to the work area that I will append to other internal table.

For example:

     LOOP AT gt_table INTO wa_table.

          wa_final_table-<dynamic field> = wa_table-value.

          APPEND wa_final_table TO gt_final_table.

     ENDLOOP.

    

In the above example <dynamic_field> wil be wa_table-fldname.

How can I pass/assign that fieldname to the structure wa_final_table ?

Please advise !

Thanks,

Stefan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,621

Hi Stefan,

Use this.

field-symbols : <final_value> TYPE any,

                      <wa_final> TYPE wa.

     LOOP AT gt_table INTO wa_table.

     ASSIGN COMPONENT "FIELDNAME" OF STRUCTURE <wa_final> to <final_value>.

          <final_value> = wa_table-value.

          APPEND <wa_final> TO gt_final_table.

     ENDLOOP

Thanks,

Shambu

8 REPLIES 8
Read only

Former Member
0 Likes
1,622

Hi Stefan,

Use this.

field-symbols : <final_value> TYPE any,

                      <wa_final> TYPE wa.

     LOOP AT gt_table INTO wa_table.

     ASSIGN COMPONENT "FIELDNAME" OF STRUCTURE <wa_final> to <final_value>.

          <final_value> = wa_table-value.

          APPEND <wa_final> TO gt_final_table.

     ENDLOOP

Thanks,

Shambu

Read only

0 Likes
1,621

Thanks Shambu !

It is not enough clear

Let me clarify.

I have an int.table and it has the following structure and records

fldname|spos|epos

fld1          0     10

fld2                  10   15

fld3          15   12

I am trying to achive at run-time the following:

LOOP AT gt_table INTO wa_table.

* on first record

          wa_final_table-fld1 = wa_table-spos.

* on second record

          wa_final_table-fld2 = wa_table-spos

* on the thitd record

          wa_final_table-fld3 = wa_table-value..

          APPEND wa_final_table TO gt_final_table.

ENDLOOP.

Can you please explain more with an example ?

Thanks in advance !

Stefan

Read only

0 Likes
1,621

Still the requirement is not clear.

     LOOP AT gt_table INTO wa_table.

     ASSIGN COMPONENT wa_table-fldname OF STRUCTURE <wa_final> to <final_value>.

IF sy-subrc = 0.

          <final_value> = wa_table-spos.

endif.

          APPEND <wa_final> TO gt_final_table.

     ENDLOOP

Is this what you want?

Thanks,

Shambu

Read only

0 Likes
1,621

Thanks Shambu,

After carefull reading your reply andafter minor modifications it is working now.

Thanks,

Stefan

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,621

Replace

wa_final_table-<dynamic field> = wa_table-value.

with

ASSIGN COMPONENT fieldname OF STRUCTURE wa_final_table TO <fs>.

<fs> = wa_table-value.

Regards,

Raymond

Read only

Former Member
0 Likes
1,621

Hi,

use the Field symbol for dynamic data passing.

regards,

venkat.

Read only

former_member16553
Active Participant
0 Likes
1,621

Hi

    Write code in this way...

  Loop at gt_table into wa_table.

move corresponding wa_table to wa_final_table.

append wa_final_table to gt_final.

endloop.

Read only

Former Member
0 Likes
1,621

Hi Stefan,

Not geeting your requirment,,,,,,,,,,,,may be this will help,,,,,,

field-symbols : <final_value> TYPE any,

                      <wa_final> TYPE wa.

     LOOP AT gt_table INTO wa_table.

     ASSIGN COMPONENT sy-tabix OF STRUCTURE wa_table to <final_value>.  "for field1

     wa_final-field1 = <final_value> .

        ASSIGN COMPONENT sy-tabix + 1  OF STRUCTURE wa_table to <final_value>.

            wa_final-field2 = <final_value>.

          APPEND <wa_final> TO gt_final_table.

     ENDLOOP

Thanks,

Lingaraj