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

problem in collect stmt

Former Member
0 Likes
723

hi all,

I am doing report in which there is opening stock , closing stock and all movement wise stock.

i am able to do all this for one material but when i am try for more than one material then value of last material is overwrite on other material.

I m using collect stmt to do sum for all movement.

plz help me.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
703

hi Ankita,

while using collect stmt, make sure that any key field is there...

else it will reullt some junk values....

reply back..

With Rgds,

S.BArani

hi all,

I am doing report in which there is opening stock , closing stock and all movement wise stock.

i am able to do all this for one material but when i am try for more than one material then value of last material is overwrite on other material.

I m using collect stmt to do sum for all movement.

plz help me.

5 REPLIES 5
Read only

Former Member
0 Likes
704

hi Ankita,

while using collect stmt, make sure that any key field is there...

else it will reullt some junk values....

reply back..

With Rgds,

S.BArani

Read only

kiran_k8
Active Contributor
0 Likes
703

Ankita,

Just try like this.

LOOP AT itab.

MOVE-CORRESPONDING itab TO it_header.

APPEND it_header.

ENDLOOP.

SORT it_header BY belnr.

LOOP AT it_header.

AT END OF belnr.

READ TABLE it_header INDEX sy-tabix.

SUM. " Summing the Amount for each Vendor Invoice No.

MOVE-CORRESPONDING it_header TO it_temp14.

APPEND it_temp14.

CLEAR it_temp14.

ENDAT.

ENDLOOP.

K.Kiran.

Read only

Former Member
0 Likes
703

Hi,

Better u write code then i will easily sugest and ans.

Rewards points if it is useful.

Read only

0 Likes
703

hi all,

plz see my code look like this :

TABLES : MSEG , MKPF , MAKT , MBEW.

DATA : BEGIN OF ITAB OCCURS 0,

LBKUM LIKE MSEG-LBKUM,

LBKUM1 LIKE MSEG-LBKUM,

MAKTX LIKE MAKT-MAKTX,

LGORT LIKE MSEG-LGORT,

BWART LIKE MSEG-BWART,

ZEILE LIKE MSEG-ZEILE,

MENGE LIKE MSEG-MENGE,

MEINS LIKE MSEG-MEINS,

MATNR LIKE MSEG-MATNR,

WERKS LIKE MSEG-WERKS,

SHKZG LIKE MSEG-SHKZG,

MBLNR LIKE MKPF-MBLNR,

BUDAT LIKE MKPF-BUDAT,

SIGN(2),

101_102 LIKE MSEG-MENGE,

END OF ITAB.

DATA : BEGIN OF ITAB_TOT OCCURS 0,

MATNR LIKE MSEG-MATNR,

LBKUM1 LIKE MSEG-LBKUM,

  • TOTAL1 LIKE MSEG-MENGE,

TOTAL1 TYPE P DECIMALS 3,

CLO TYPE P DECIMALS 3,

101_102 LIKE MSEG-MENGE,

END OF ITAB_TOT.

PARAMETERS : WERKS LIKE MSEG-WERKS DEFAULT 'BRHP' OBLIGATORY.

SELECT-OPTIONS : MATNR FOR MSEG-MATNR OBLIGATORY.

SELECT-OPTIONS: DAT FOR MKPF-BUDAT.

SELECT-OPTIONS: LGORT FOR MSEG-LGORT.

START-OF-SELECTION.

SELECT DISTINCT MSEG~MATNR

MSEG~LGORT

MSEG~BWART

MSEG~ZEILE

MSEG~MENGE

MSEG~MEINS

MSEG~WERKS

  • MSEG~LBKUM

MSEG~SHKZG

MKPF~MBLNR

MKPF~BUDAT

INTO CORRESPONDING FIELDS OF TABLE ITAB

FROM MSEG

INNER JOIN MKPF ON MSEG~MBLNR = MKPF~MBLNR

WHERE MSEG~MATNR IN MATNR

  • AND MSEG~LGORT IN LGORT

AND MSEG~WERKS EQ WERKS

AND mKPF~BUDAT IN DAT

AND MSEG~ZEILE = 1

order by mkpf~MBLNR.

LOOP AT ITAB.

IF ITAB-SHKZG = 'S'.

ITAB-SIGN = '+'.

MODIFY ITAB.

ELSE.

ITAB-SIGN = '-'.

MODIFY ITAB.

ENDIF.

ENDLOOP.

*

SORT ITAB BY MATNR.

LOOP AT ITAB.

IF ITAB-BWART = '121' OR ITAB-BWART = '122' .

SELECT MENGE INTO (ITAB-121_122) FROM MSEG WHERE MATNR =

ITAB-MATNR

AND MBLNR = ITAB-MBLNR

AND LGORT = ITAB-LGORT

AND WERKS = ITAB-WERKS.

AND ZEILE = ITAB-ZEILE.

MODIFY ITAB.

ENDSELECT.

ENDIF.

LOOP AT ITAB.

IF ITAB-SHKZG = 'H'.

ITAB-121_122 = ITAB-121_122 * -1.

MODIFY ITAB.

ELSE.

ITAB-121_122 = ITAB-121_122.

MODIFY ITAB.

ENDIF.

ENDLOOP.

ENDLOOP.

LOOP AT ITAB.

SELECT LBKUM INTO (ITAB-LBKUM) FROM MSEG WHERE MATNR = ITAB-MATNR

and

MBLNR = ITAB-MBLNR AND WERKS = ITAB-WERKS AND ZEILE = 1.

MODIFY ITAB.

ENDSELECT.

ENDLOOP.

SORT ITAB BY matnr mblnr.

LOOP AT ITAB.

IF ITAB[] IS NOT INITIAL.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MATNR .

MOVE ITAB-lBKUM TO ITAB-LBKUM1.

MODIFY ITAB.

*APPEND ITAB_TOT1.

ENDIF.

ENDLOOP.

LOOP AT ITAB .

MOVE-CORRESPONDING ITAB TO ITAB_TOT.

COLLECT ITAB_TOT.

ENDLOOP.

loop at itab_tot.

write : / itab_tot-matnr , itab_tot-121_122 , itab-lbkum.

endloop.

i am not getting correct value of 121_122.

what should i do?

Read only

0 Likes
703

Ankita,

ITAB and ITAB_TOT are of different structures.So,move field by field rather than

move-corresponding itab to itab_tot.

K.Kiran.