2013 Mar 25 1:33 PM
Hi All,
I have an lt_itab which has, let's say four fields a,b,c,d. field a is unique, field b and c are numeric fields, field d is a % field which = 100 * (b/c).
Since b and c have to be accumulated by same a . so I used "collect ls_itab into lt_itab in the loop". After I collected all the data, I have to calculate the field d. Can anybody tell me how I can do it without another loop? Can I mass modify that field like "modify dbtable set d= 100 * (b/c)"?
Thanks,
Charles
Hi All,
I have an lt_itab which has, let's say four fields a,b,c,d. field a is unique, field b and c are numeric fields, field d is a % field which = 100 * (b/c).
Since b and c have to be accumulated by same a . so I used "collect ls_itab into lt_itab in the loop". After I collected all the data, I have to calculate the field d. Can anybody tell me how I can do it without another loop? Can I mass modify that field like "modify dbtable set d= 100 * (b/c)"?
Thanks,
Charles
2013 Mar 25 3:21 PM
Hi Charles,
If A is unique, how can you have more than one record for A?
But the solution should be something like the one below.
Sort the table by field A.
After collecting B and C based on unique A, use the option AT END OF A. This will get executed for the last record of A. There you can calculate D.
Vikram.M
2013 Mar 25 4:51 PM
I don't think Charles meant that he would have more than record for the same value of A after he has done the 'collection'. I think what he asked is if there is a way to calculate and update D without looping over the 'collected' internal table. And, I can't think of such a way. Perhaps his best bet is to loop but using a field symbol so that he doesn't have to use a MODIFY.
2013 Mar 25 5:27 PM
Hi Charles,
Somewhere somehow you are populating the internal table lt_itab. So you can just put the logic for getting the results in D in that loop only. Lets suppose there is a internal table A (or putting directly) from where you are putting the values in lt_itab so your final code will be like that.
loop at A into a.
loop at lt_itab into wa_itab.
wa_itab-A = a-A.
wa_itab-B = a-B.
wa_itab-C = a-C.
D = % calculation of a-B/a-C.
wa_itab-D = D.
append wa_itab into lt_itab.
clear wa_itab.
endloop.
clear a.
endloop.
2013 Mar 25 4:09 PM
2013 Mar 26 4:45 AM
Try out like this. After a collect statement the sy-tabix holds the row collected.
loop at it into wa.
collect wa into it2.
read table it2 assigning <fs> index sy-tabix.
if sy-subrc = 0.
d = 100 * ( b/ c ).
endif.
endloop.
2013 Mar 26 4:48 AM
Dear Charles,
Do not use collect statement, try to use different logic to add and modify same data to all
b,c and d on base of c.
with regards
vikas pandey
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |