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.

Former Member
0 Likes
864

Hi all ,

I m using following code for collect.

SELECT MSEG~MATNR

MSEG~LGORT

MSEG~BWART

MSEG~ZEILE

MSEG~MENGE

MSEG~MEINS

MSEG~WERKS

MSEG~SHKZG

mkpf~mblnr

MKPF~MBLNR

MKPF~BUDAT

INTO CORRESPONDING FIELDS OF TABLE ITAB

FROM MSEG

INNER JOIN MKPF ON MSEGMBLNR = MKPFMBLNR

WHERE MSEG~MATNR EQ MATNR

AND MSEG~LGORT IN LGORT

AND MSEG~WERKS EQ WERKS

AND mKPF~BUDAT IN DAT

order by mkpf~MBLNR.

LOOP AT ITAB.

IF ITAB-BWART = '701' OR ITAB-BWART = '702' .

SELECT MENGE INTO (ITAB-701_702) 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-701_702 = ITAB-701_702 * -1.

MODIFY ITAB.

ELSE.

ITAB-701_702 = ITAB-701_702.

MODIFY ITAB.

ENDIF.

ENDLOOP.

ENDLOOP.

LOOP AT ITAB .

MOVE-CORRESPONDING ITAB TO ITAB_TOT.

COLLECT ITAB_TOT.

ENDLOOP.

I want total based on movement type.

here i got right total only for first movement type.

where is error plz tell me and help me.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
844

Hi Ankita

LOOP AT ITAB.

IF ITAB-BWART = '701' OR ITAB-BWART = '702' .

SELECT MENGE INTO (ITAB-701_702) FROM MSEG WHERE MATNR =

ITAB-MATNR

AND MBLNR = ITAB-MBLNR

    • AND LGORT = ITAB-LGORT

AND WERKS = ITAB-WERKS.

  • AND ZEILE = ITAB-ZEILE.

MODIFY ITAB index sy-tabix.

ENDSELECT.

ENDIF.

LOOP AT ITAB.

IF ITAB-SHKZG = 'H'.

ITAB-701_702 = ITAB-701_702 * -1.

MODIFY ITAB index sy-tabix.

ELSE.

ITAB-701_702 = ITAB-701_702.

MODIFY ITAB index sy-tabix.

ENDIF.

ENDLOOP.

ENDLOOP.

LOOP AT ITAB .

MOVE-CORRESPONDING ITAB TO ITAB_TOT.

COLLECT ITAB_TOT.

clear itab,itab_tot.

ENDLOOP.

reward points to all helpful answers

kiran.M

Hi Ankita,

Use AT NEW event in the loop of itab. when ever the new movement comes into the picture seperate those values and sum. Finally you will find all the sums bases on Movement types.

Reward if useful.

all the best.

kishore

6 REPLIES 6
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
844

Hi,

In your ITAB decleration give WITH KEY <movement type field>.

COLLECT will compare the KEY fields of the internal table when summing up the values.

SO make movement type as your TABKE KEY of the internal table.

Show us your ITAB declaration.

Regards,

Sesh

Read only

0 Likes
844

hi Sesh,

my itab declaration is like:

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,

121_122 LIKE MSEG-MENGE,

123_124 LIKE MSEG-MENGE,

201_202 LIKE MSEG-MENGE,

261_262 LIKE MSEG-MENGE,

301_302 LIKE MSEG-MENGE,

303_304 LIKE MSEG-MENGE,

309_310 LIKE MSEG-MENGE,

311_312 LIKE MSEG-MENGE,

321_322 LIKE MSEG-MENGE,

325_326 LIKE MSEG-MENGE,

343_344 LIKE MSEG-MENGE,

349_350 LIKE MSEG-MENGE,

453_454 LIKE MSEG-MENGE,

459_460 LIKE MSEG-MENGE,

511_512 LIKE MSEG-MENGE,

531_532 LIKE MSEG-MENGE,

541_542 LIKE MSEG-MENGE,

543_544 LIKE MSEG-MENGE,

551_552 LIKE MSEG-MENGE,

561_562 LIKE MSEG-MENGE,

601_602 LIKE MSEG-MENGE,

603_604 LIKE MSEG-MENGE,

641_642 LIKE MSEG-MENGE,

651_652 LIKE MSEG-MENGE,

653_654 LIKE MSEG-MENGE,

671_672 LIKE MSEG-MENGE,

701_702 LIKE MSEG-MENGE,

end of itab.

can i send u code for report which i have done as my requirement.

Read only

0 Likes
844

Hi Ankita

can u show ur internal table declaration of ITAB_TOT.

Read only

0 Likes
844

Hi,

Try like this

TYPES : BEGIN OF ITAB_TYPE ,

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,

121_122 LIKE MSEG-MENGE,

123_124 LIKE MSEG-MENGE,

201_202 LIKE MSEG-MENGE,

261_262 LIKE MSEG-MENGE,

301_302 LIKE MSEG-MENGE,

303_304 LIKE MSEG-MENGE,

309_310 LIKE MSEG-MENGE,

311_312 LIKE MSEG-MENGE,

321_322 LIKE MSEG-MENGE,

325_326 LIKE MSEG-MENGE,

343_344 LIKE MSEG-MENGE,

349_350 LIKE MSEG-MENGE,

453_454 LIKE MSEG-MENGE,

459_460 LIKE MSEG-MENGE,

511_512 LIKE MSEG-MENGE,

531_532 LIKE MSEG-MENGE,

541_542 LIKE MSEG-MENGE,

543_544 LIKE MSEG-MENGE,

551_552 LIKE MSEG-MENGE,

561_562 LIKE MSEG-MENGE,

601_602 LIKE MSEG-MENGE,

603_604 LIKE MSEG-MENGE,

641_642 LIKE MSEG-MENGE,

651_652 LIKE MSEG-MENGE,

653_654 LIKE MSEG-MENGE,

671_672 LIKE MSEG-MENGE,

701_702 LIKE MSEG-MENGE,

end of ITAB_TYPE.

DATA: <b>ITAB_TOT</b> type table of ITAB_TYPE WITH KEY BWART WITH HEADER LINE.

Replace your ITAB_TOT decleration like this.

Regards,

Sesh

Read only

Former Member
0 Likes
845

Hi Ankita

LOOP AT ITAB.

IF ITAB-BWART = '701' OR ITAB-BWART = '702' .

SELECT MENGE INTO (ITAB-701_702) FROM MSEG WHERE MATNR =

ITAB-MATNR

AND MBLNR = ITAB-MBLNR

    • AND LGORT = ITAB-LGORT

AND WERKS = ITAB-WERKS.

  • AND ZEILE = ITAB-ZEILE.

MODIFY ITAB index sy-tabix.

ENDSELECT.

ENDIF.

LOOP AT ITAB.

IF ITAB-SHKZG = 'H'.

ITAB-701_702 = ITAB-701_702 * -1.

MODIFY ITAB index sy-tabix.

ELSE.

ITAB-701_702 = ITAB-701_702.

MODIFY ITAB index sy-tabix.

ENDIF.

ENDLOOP.

ENDLOOP.

LOOP AT ITAB .

MOVE-CORRESPONDING ITAB TO ITAB_TOT.

COLLECT ITAB_TOT.

clear itab,itab_tot.

ENDLOOP.

reward points to all helpful answers

kiran.M

Read only

kishorepallapothula
Participant
0 Likes
844

Hi Ankita,

Use AT NEW event in the loop of itab. when ever the new movement comes into the picture seperate those values and sum. Finally you will find all the sums bases on Movement types.

Reward if useful.

all the best.

kishore