2008 Mar 25 7:18 AM
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
2008 Mar 25 7:39 AM
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
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
2008 Mar 25 7:24 AM
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
2008 Mar 25 7:29 AM
Hi Aditya
Thanks for your reply, but I am having 400 columns, not rows.
2008 Mar 25 7:39 AM
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
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |