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: 

help with the code

Former Member
0 Kudos

Hi all,

i have records like in internal table itab

id amount

101 1 1.00

101 2 2.00

102 1 1.00

102 2 2.50

102 3 3.00

103 2 1.50

i want the output like like this internal table itab1

101 3.00

102 6.50

103 1.50

clear : wa_zoritem ,price.

total= 0.00

loop at itab into wa_itab.

on change of wa_itab1-id.

clear total.

total= total + wa_itab1-amount.

wa_itab1-id = wa_itab_copy-id.

wa_itab1-total= wa_itab_copy-total.

append wa_itab1 to itab1.

endon.

*MODIFY TABLE i_FINAL FROM wa_FINAL

  • TRANSPORTING COST.

*MODIFY wa_final to i_final.

wa_itab_copy = wa_itab.

clear : wa_itab.

endloop.

This works fine when i have multiple records

but this doesn't work when i have the follwwing record in itab

id amount

101 1 1.00

Thanks

1 ACCEPTED SOLUTION

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

clear : wa_zoritem ,price.

total= 0.00

loop at itab into wa_itab.

total= total + wa_itab-amount.

wa_itab1-id = wa_itab-id.

wa_itab1-total= wa_itab-total.

on change of wa_itab-id.

append wa_itab1 to itab1.

clear total.

total= total + wa_itab-amount.

endon.

clear : wa_itab.

endloop.

Message was edited by:

Jayanthi Jayaraman

5 REPLIES 5

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

clear : wa_zoritem ,price.

total= 0.00

loop at itab into wa_itab.

total= total + wa_itab-amount.

wa_itab1-id = wa_itab-id.

wa_itab1-total= wa_itab-total.

on change of wa_itab-id.

append wa_itab1 to itab1.

clear total.

total= total + wa_itab-amount.

endon.

clear : wa_itab.

endloop.

Message was edited by:

Jayanthi Jayaraman

Former Member
0 Kudos

Hi Kajol,

Try this

loop at itab into wa_itab.

<b>if sy-tabix = 1.

total= total + wa_itab1-amount.

endif.</b>

on change of wa_itab1-id.

clear total.

total= total + wa_itab1-amount.

Regards,

Atish

Former Member
0 Kudos

hi,

*suppose the data is avialble in the internal table ITAB.
[code]
sort ITAB by ID amount.
delete adjacent duplicates from ITAB comparing ID.

*Now thw ITAB conatins only the records.

*101 3.00

*102 6.50

*103 1.50[/code]

Regards

Reshma

kesavadas_thekkillath
Active Contributor
0 Kudos

data: itab2 like table of itab1 with header line.

loop at itab1.

move:; <col1> to itab2-<col1>

move: <col2> to itab2-<col2>

collect itab2.

clear itab2.

endloop.

or u can collect the itab1 itself but the values in the second field will get summed up.

if its not a probs u can do the same method in itab1.

dev_parbutteea
Active Contributor
0 Kudos

Hi,

Either use collect statement

or

loop at itab

if id is same as previous

add the two id's and delete record from table.

Regards,

Sooness