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

doubt on control break statements

Former Member
0 Likes
939

i have a internal table like

material quantity

aa 10

aa 20

aa 10

ab 10

ab 20

ca 30

now i have add all these quatities and modify the same interanl table as

aa 40

ab 30

ca 30.... how to put these contents into the same internal table

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
915
SORT ITAB BY MATNR.
LOOP AT ITAB.
  AT END OF MATNR.
    SUM.
   ITAB2-MATNR = ITAB-MATNR.
   ITAB2-QUANTITY = ITAB-QUANTITY.
   <b>APPEND ITAB2.</b>
  ENDAT.
ENDLOOP.

Message was edited by: Srikanth Kidambi

Message was edited by: Srikanth Kidambi

i have a internal table like

material quantity

aa 10

aa 20

aa 10

ab 10

ab 20

ca 30

now i have add all these quatities and modify the same interanl table as

aa 40

ab 30

ca 30.... how to put these contents into the same internal table

9 REPLIES 9
Read only

Former Member
0 Likes
915

You can use the <b>COLLECT</b> statement for this purpose

Read only

Former Member
0 Likes
915

Hi lokesh,

1. for this, no need to use control-break logic.

2. instead use COLLECT

3. do these steps.

a) create a new internal table STAB

(with two fields, of the same name as original ITAB)

b) LOOP AT ITAB.

STAB = ITAB.

COLLECT STAB.

ENDLOOP.

4. Now your STAB will have total as u require.

<b>Note : If ITAB and STAB have different number of fields,

then use MOVE-CORRESPONDING ITAB TO STAB

instead of STAB = ITAB.</b>

regards,

amit m.

Read only

Former Member
0 Likes
915

HI,

data itab1 like itab occurs 0 with header line.

loop at itab.

itab1= itab.

collect itab1.

endloop.

free itab.

itab[] = itab1[]

itab will have

aa 40

ab 30

ca 30....

Regards

amole

Read only

Former Member
0 Likes
916
SORT ITAB BY MATNR.
LOOP AT ITAB.
  AT END OF MATNR.
    SUM.
   ITAB2-MATNR = ITAB-MATNR.
   ITAB2-QUANTITY = ITAB-QUANTITY.
   <b>APPEND ITAB2.</b>
  ENDAT.
ENDLOOP.

Message was edited by: Srikanth Kidambi

Message was edited by: Srikanth Kidambi

Read only

Former Member
0 Likes
915

If you need to put the information in the same table it is better to handle it while you are getting the information into the internal table.

Basically using COLLECT statement instead of APPEND or MODIFY would give you your result.

SELECT * from vbap.

itab-matnr = vbap-matnr.

itab-menge = vbap-menge.

collect itab.

Endselect.

Here the itab would have the data as you required total quantity for each material. Please note that the all C,N type of fields are considered as key in the COLLECT statement.

Message was edited by: Anurag Bankley

Read only

Former Member
0 Likes
915

Hi

Loop on your internal table and use collect stmnt to collect data into another internal table.

Regards,

Raj

Eg:

loop at itab1.

move-corresponding itab1 into itab2.

collect itab2.

endloop.

Result in itab2.

Read only

Former Member
0 Likes
915
REPORT  ZSRIM_TEMP14.

data : begin of itab occurs 0,
        matnr type mara-matnr,
        quan  type i,
       end of itab.

data : itab2 like itab occurs 0 with header line.

itab-matnr = '1'.
itab-quan = 2.
append itab.

itab-matnr = '2'.
itab-quan = 2.
append itab.


itab-matnr = '1'.
itab-quan = 2.
append itab.


itab-matnr = '2'.
itab-quan = 2.
append itab.

itab-matnr = '1'.
itab-quan = 2.
append itab.

itab-matnr = '2'.
itab-quan = 2.
append itab.

sort itab by matnr.
BREAK-POINT.
LOOP AT ITAB.
  AT END OF MATNR.
    SUM.
   ITAB2-MATNR = ITAB-MATNR.
   ITAB2-QUAN = ITAB-QUAN.
   APPEND ITAB2.
  ENDAT.
ENDLOOP.

LOOP AT ITAB2.
  WRITE :/ ITAB2-MATNR, ITAB2-QUAN.
ENDLOOP.

<b>second method.</b>
instead of LOOP and AT END ..block,you can use COLLECT
LOOP AT ITAB.
  ITAB2-MATNR = ITAB-MATNR.
  ITAB2-QUAN = ITAB-QUAN.
  COLLECT ITAB2.
ENDLOOP.

regards

Srikanth

Message was edited by: Srikanth Kidambi

Read only

Former Member
0 Likes
915

Hi,

You can loop at your internal table and use

loop at itab.

AT NEW material.

SUM.

endloop.

Read only

Former Member
0 Likes
915

THANKS A LOT TO ALL