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

prog logic

former_member611341
Participant
0 Likes
750

Hello....

i have ainternal table with 4 fields....

material quantity field3 field4

auv123 100 xxxxx xxxx

auv123 200 xxxxx xxxx

auv111 100 xxxxx xxxx

auv123 400 xxxxx xxxx

auv111 200 xxxxx xxxx

auv222 100 xxxxx xxxx

i nedd a simple logic to get a o/p table like:

o/p result:

auv123 700 xxxxx xxxx

auv111 300 xxxxx xxxx

auv222 100 xxxxx xxxx

i.e I nedd to add QUANITY when MATERIAL number is same...and delete the extra rows...

<b>data types:</b>

material field is char

quantity fields is quan

other 2 fields( field 3 and field 4) in internal table are char and date type..

i need a simple logic for it...

it may sound bit silly for you ...

thanks....

1 ACCEPTED SOLUTION
Read only

suresh_datti
Active Contributor
0 Likes
700

use COLLECT instead of APPEND when filling the itab..

~Suresh

8 REPLIES 8
Read only

suresh_datti
Active Contributor
0 Likes
701

use COLLECT instead of APPEND when filling the itab..

~Suresh

Read only

Former Member
0 Likes
700

Hi,

You can use collect statement and make sure you sort the internal table first.


SORT ITAB1.

LOOP AT ITAB1.
  MOVE-CORRESPONDING ITAB1 TO ITAB2.
  COLLECT ITAB2.
ENDLOOP.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
700

Hi Aday,

Use <b>COLLECT</b> statement to meet your requirement.

COLLECT statement will sum up all numeric fields when all other non-numeric fields are same.

Thanks,

Vinay

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
700

In order to get a sum of the materials, you need to have another internal table with just Material and qty.

data: begin of isum,
        matnr type mara-matnr,
        qty type mseg-menge,
        end of isum.

clear isum.  refresh isum.

loop at itab.
   isum-matnr = itab-matnr.
   isum-qty    = itab-qty.
   collect isum.
endloop.

Regards,

Rich Heilman

Read only

former_member611341
Participant
0 Likes
700

thanks for your quick responses...

here i have two other fields in the internal table...which are type DATE and CHAR..

im gettin problem when im using COLLECT statement..

im using R/3 620 release...

thanks..

Read only

0 Likes
700

then use SUM ie..


sort itab.
loop at itab.
at new matnr.
sum.
write: / itab-fld1,itab-fld2,itabfld3,itab-fld4.
endat.
endloop.

~Suresh

Read only

0 Likes
700

Right, you should try summing using another internal table, loop at the first and COLLECT into the second, the second internal table will only have material and qty, then when you want to know the total for material, you can simply read the ISUM internal table using the READ statement.

Regards,

Rich Heilman

Read only

0 Likes
700

thanks guys for all your quick replies....

i declared another table with only two fields...and used COLLECT statement...

then read the quantity and modified my original table after deleting adjacent duplicates..( as rich advised)...

once again thanks...

points will be awarded...