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: 

Data allocation for internal table rows Dynamically

praveen_hannu
Contributor
0 Kudos

Hi Friends

I have requirement like below:

I have one internal table with 400 amounts columns, I will get the value from another program

that indicates to which column I have to add the values. I dont want to write the case statement

because I need to write 400 WHEN statements.

Is there any alternative way dynamically I can choose the internal table column and assign the value which

I am getting from external program.

Please help on this as soon as possible.

Points will be rewarded

Thanks

Praveen

1 ACCEPTED SOLUTION

Clemenss
Active Contributor
0 Kudos

Hi Praveen,

you may use the ASSIGN COMPONENT ... OF STRUCTURE ... statement.

It allows to assign the field by name or by sequence.

Assume you columns have names like amount_001 to amount_999 and are fields of structure ls_amounts. The do as decribed here roughly:


data:
  lv_fieldseq type NUMC_3,
  lv_fieldname type fieldname,
  lv_amount type (???).
fieldsymbols:
  <amount> type any.
* fetch amount and field sequence from external data into  lv_amount and lv_fieldseq 
concatenate 'AMOUNT_' lv_fieldseq into lv_fieldname.
* <amount> is something like a pointer
assign component (lv_fieldname) of structure ls_amounts to <amount>.
add lv_amount  to <amount>.  

if you are sure you have the correct position of the amount field in the structure stored in variable lv_position, you may use

 
assign component lv_position of structure ls_amounts to <amount>.

I prefer the ASSIGN (fieldname) for reasons of more transparency and less danger in case of structural changes.

Regards,

Clemens

Regards,

Clemens

3 REPLIES 3

Former Member
0 Kudos

Hi

You can do one thing

read table itab index <value which you get from another program>

now add the value

modift itab index sy-tabix.

(I believe you have 400 rows)

Regards

Aditya

0 Kudos

Hi Aditya

Thanks for your reply, but I am having 400 columns, not rows.

Clemenss
Active Contributor
0 Kudos

Hi Praveen,

you may use the ASSIGN COMPONENT ... OF STRUCTURE ... statement.

It allows to assign the field by name or by sequence.

Assume you columns have names like amount_001 to amount_999 and are fields of structure ls_amounts. The do as decribed here roughly:


data:
  lv_fieldseq type NUMC_3,
  lv_fieldname type fieldname,
  lv_amount type (???).
fieldsymbols:
  <amount> type any.
* fetch amount and field sequence from external data into  lv_amount and lv_fieldseq 
concatenate 'AMOUNT_' lv_fieldseq into lv_fieldname.
* <amount> is something like a pointer
assign component (lv_fieldname) of structure ls_amounts to <amount>.
add lv_amount  to <amount>.  

if you are sure you have the correct position of the amount field in the structure stored in variable lv_position, you may use

 
assign component lv_position of structure ls_amounts to <amount>.

I prefer the ASSIGN (fieldname) for reasons of more transparency and less danger in case of structural changes.

Regards,

Clemens

Regards,

Clemens