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

Mass modify a itab field

Former Member
0 Likes
1,008

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

6 REPLIES 6
Read only

Former Member
0 Likes
958

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

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
958

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.

Read only

0 Likes
958

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.

Read only

Former Member
0 Likes
958

This message was moderated.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
958

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.

Read only

Former Member
0 Likes
958

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