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: 

How to make total using AT END OF ??

Former Member
0 Kudos
654

Hello experts,

I want to make some of quantities. I cant use SUM because i am using 'ASIGNING' with loop because its gives error.

here, is my code.....

loop at itab assigning <fs>.

w_info-qty1 = <fs>-qty1.

w_info-uom = <fs>-uom.

w_info-mfrgr = <fs>-mfrgr.

w_info-qty2 = <fs>-qty2.

endloop.

here my current data in itab......

QTY1 UOM MFRGR QTY2

1 CA ZA1 4

2 CA ZA1 5

2 CA ZA2 6

1 CA ZA1 2

3 CA ZA2 4

I need result like......

QTY1 UOM MFRGR QTY2

4 CA ZA1 11

5 CA ZA2 10

I have tried with following code.......

loop at itab assigning <fs>.

AT END OF mfrgr.

SUM.

w_info-qty1 = <fs>-qty1.

w_info-uom = <fs>-uom.

w_info-mfrgr = <fs>-mfrgr.

w_info-qty2 = <fs>-qty2.

ENDAT.

endloop.

but........it shows error : SUM cannot be used with LOOP.......ASIGNING. and its true.

Can any one tell me any other idea ?

<REMOVED BY MODERATOR>

Regards,

RH

Edited by: Alvaro Tejada Galindo on Apr 7, 2008 5:37 PM

12 REPLIES 12

Former Member
0 Kudos
378

Hi,

you can use COLLECT statement to satisfy your requirement.

<REMOVED BY MODERATOR>

Regards

rose

Edited by: Alvaro Tejada Galindo on Apr 7, 2008 5:38 PM

JozsefSzikszai
Active Contributor
0 Kudos
378

hi Ronny,

I had the same problem some months ago: /thread/557602 [original link is broken] I don't think there is a good solution, finally I implemented a 'manual' calculation.

regards

ec

0 Kudos
378

Hi eric,

I use this code but still getting problem.

can give me good code for it ?

egards

RH

0 Kudos
378

Hi Ronny,

Use this pseudo code..

Inside

LOOP

AT END OF <FIELD NAME>

SUM.

ENDAT.

ENDLOOP.

This will give you the desired result..

Regards,

Raghav

Former Member
0 Kudos
378

Hi,

try like this.


DATA: BEGIN OF LINE occurs 0,
        COL1(3) TYPE C,
        COL2(2) TYPE N,
        COL3    TYPE I,
      END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE
          WITH NON-UNIQUE KEY COL1.

LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 3.
append line

LINE-COL1 = 'def'. LINE-COL2 = '34'. LINE-COL3 = 5.
append line

LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 7.
append line

LOOP AT LINE.
  collect line into itab.
ENDLOOP.

LOOP AT ITAB INTO LINE.
  WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
ENDLOOP.

rgds,

bharat.

Former Member
0 Kudos
378

Hi,

Please refer to the below code:


  FIELD-SYMBOLS:  <pos_data> TYPE ANY,
                               <gt_pos_data>  TYPE table.
 
  DATA : lt_csks LIKE gt_csks WITH HEADER LINE.
 
 
 LOOP AT <gt_pos_data> ASSIGNING <pos_data>.
 
    MOVE-CORRESPONDING <pos_data> TO lt_csks.
    
    if lt_csks-oi_disp NE 0.
       APPEND lt_csks.
      CLEAR  lt_csks.
   endif.
 
  ENDLOOP.

Now you have the lt_csks, you can use at end of statement in addition with sum.

Thanks,

Sriram Ponna.

Former Member
0 Kudos
378

hi i had a program which displays the total and subtotal .

check this may it helps u...

&----


*& Report ZR_A1

*&

&----


REPORT ZR_A1

NO STANDARD PAGE HEADING.

Tables declarations

TABLES: VBAK, VBAP.

Variable declarations

DATA: C1 TYPE C.

Internal Table declarations*

DATA: BEGIN OF IT_VBAK OCCURS 0,

VBELN LIKE VBAK-VBELN,

VKORG LIKE VBAK-VKORG,

VTWEG LIKE VBAK-VTWEG,

SPART LIKE VBAK-SPART,

END OF IT_VBAK.

DATA: BEGIN OF IT_VBAP OCCURS 0,

VBELN LIKE VBAP-VBELN,

POSNR LIKE VBAP-POSNR,

MATNR LIKE VBAP-MATNR,

NETWR LIKE VBAP-NETWR,

BRGEW LIKE VBAP-BRGEW,

NTGEW LIKE VBAP-NTGEW,

END OF IT_VBAP.

DATA: BEGIN OF IT_FINAL OCCURS 0,

VBELN LIKE VBAK-VBELN,

VKORG LIKE VBAK-VKORG,

VTWEG LIKE VBAK-VTWEG,

SPART LIKE VBAK-SPART,

POSNR LIKE VBAP-POSNR,

MATNR LIKE VBAP-MATNR,

NETWR LIKE VBAP-NETWR,

BRGEW LIKE VBAP-BRGEW,

NTGEW LIKE VBAP-NTGEW,

END OF IT_FINAL.

Selection-screen design

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-R01.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.

SELECTION-SCREEN: END OF BLOCK B1.

TOP-OF-PAGE.

FORMAT INTENSIFIED ON COLOR 5.

WRITE:/7 'LIST TO DISPLAY SALES ITEM INFO'.

START-OF-SELECTION.

Populating it_vbak table

SELECT VBELN

VKORG

VTWEG

SPART

FROM VBAK

INTO TABLE IT_VBAK

WHERE VBELN IN S_VBELN.

populating it_vbap table

IF NOT IT_VBAK[] IS INITIAL.

SELECT VBELN

POSNR

MATNR

NETWR

BRGEW

NTGEW

FROM VBAP

INTO TABLE IT_VBAP

FOR ALL ENTRIES IN IT_VBAK

WHERE VBELN = IT_VBAK-VBELN.

ENDIF.

populating the final list

LOOP AT IT_VBAP.

READ TABLE IT_VBAK WITH KEY VBELN = IT_VBAP-VBELN.

IF SY-SUBRC = 0.

MOVE: IT_VBAK-VBELN TO IT_FINAL-VBELN,

IT_VBAK-VKORG TO IT_FINAL-VKORG,

IT_VBAK-VTWEG TO IT_FINAL-VTWEG,

IT_VBAK-SPART TO IT_FINAL-SPART,

IT_VBAP-POSNR TO IT_FINAL-POSNR,

IT_VBAP-MATNR TO IT_FINAL-MATNR,

IT_VBAP-NETWR TO IT_FINAL-NETWR,

IT_VBAP-BRGEW TO IT_FINAL-BRGEW,

IT_VBAP-NTGEW TO IT_FINAL-NTGEW.

APPEND IT_FINAL.

ENDIF.

ENDLOOP.

*sort it_vbap by vbeln.

*

*loop at it_vbap.

SORT IT_FINAL BY VBELN.

LOOP AT IT_FINAL.

AT FIRST.

FORMAT INTENSIFIED ON COLOR 1.

WRITE:/35 'SALES DOCUMENT ITEM LIST'.

ULINE AT (100).

*endat.

FORMAT INTENSIFIED ON COLOR 5.

WRITE:/ SY-VLINE,

2 'SALES.DOCU.NO',

13 'ITEM',

21 'MATERIAL',

50 'NET-VAL',

65 'GROSS-WT',

82 'NET-WT',

100 SY-VLINE.

ENDAT.

FORMAT INTENSIFIED ON COLOR 2.

WRITE:/ SY-VLINE,

2 C1 AS CHECKBOX,

5 IT_FINAL-VBELN,

13 IT_FINAL-POSNR,

21 IT_FINAL-MATNR,

41 IT_FINAL-NETWR,

56 IT_FINAL-BRGEW,

71 IT_FINAL-NTGEW,

100 SY-VLINE.

AT END OF VBELN.

SUM.

FORMAT INTENSIFIED ON COLOR 3.

WRITE:/ SY-VLINE,

30 'SUB-TOTAL:',

41 IT_FINAL-NETWR,

56 IT_FINAL-BRGEW,

71 IT_FINAL-NTGEW.

WRITE:/100 SY-VLINE.

ENDAT.

AT LAST.

SUM.

FORMAT INTENSIFIED ON COLOR 6.

WRITE:/ SY-VLINE,

30 'GRAND-TOTAL:',

41 IT_FINAL-NETWR,

56 IT_FINAL-BRGEW,

71 IT_FINAL-NTGEW.

WRITE:/100 SY-VLINE.

ENDAT.

ENDLOOP.

regards,

venkat.

prabhu_s2
Active Contributor
0 Kudos
378

Ronny.....check this code:



SORT ITAB BY MFRGR ASCENDING.

LOOP AT ITAB ASSIGNING <FS>.

  AT FIRST.
    CLEAR AF.
  ENDAT.

  IF TEMP NE <FS>-MFRGR.
    MOVE WTAB TO ETAB.
  ENDIF.

  ON CHANGE OF <FS>-MFRGR.
    CLEAR WTAB.
    MOVE <FS>-MFRGR TO TEMP.
    IF AF IS NOT INITIAL.
      WRITE 😕 ETAB-QTY1, ETAB-UOM, ETAB-MFRGR, ETAB-QTY2.
    ENDIF.
    AF = 'X'.
  ENDON.

  IF TEMP EQ <FS>-MFRGR.
    WTAB-QTY1 = WTAB-QTY1 +  <FS>-QTY1.
    WTAB-UOM = <FS>-UOM.
    WTAB-QTY2 = WTAB-QTY2 +  <FS>-QTY2.
    WTAB-MFRGR = <FS>-MFRGR.
    MOVE WTAB TO ETAB.
  ENDIF.

  AT LAST.
    WRITE 😕 ETAB-QTY1, <FS>-UOM, <FS>-MFRGR, ETAB-QTY2.
  ENDAT.

ENDLOOP.

Edited by: Prabhu S on Mar 11, 2008 11:43 AM

Former Member
0 Kudos
378

Hi,

Check this following code.

This will be helpful, incase your internal table has the values as you have specified.

types: begin of tp_itab,

fld1(3) type c,

fld2(3) type c,

fld3(3) type c,

fld4(3) type c,

end of tp_itab.

data: t_itab type standard table of tp_itab,

t_itab2 type standard table of tp_itab.

data: wa_itab type tp_itab,

wa_itab2 type tp_itab.

wa_itab-fld1 = '1'.

wa_itab-fld2 = 'CA'.

wa_itab-fld3 = 'ZA1'.

wa_itab-fld4 = '4'.

append wa_itab to t_itab.

clear wa_itab.

wa_itab-fld1 = '2'.

wa_itab-fld2 = 'CA'.

wa_itab-fld3 = 'ZA1'.

wa_itab-fld4 = '5'.

append wa_itab to t_itab.

clear wa_itab.

wa_itab-fld1 = '2'.

wa_itab-fld2 = 'CA'.

wa_itab-fld3 = 'ZA2'.

wa_itab-fld4 = '6'.

append wa_itab to t_itab.

clear wa_itab.

wa_itab-fld1 = '1'.

wa_itab-fld2 = 'CA'.

wa_itab-fld3 = 'ZA1'.

wa_itab-fld4 = '2'.

append wa_itab to t_itab.

clear wa_itab.

wa_itab-fld1 = '3'.

wa_itab-fld2 = 'CA'.

wa_itab-fld3 = 'ZA2'.

wa_itab-fld4 = '4'.

append wa_itab to t_itab.

clear wa_itab.

write: / 'fld1', 'fld2', 'fld3', 'fld4'.

loop at t_itab into wa_itab.

write: / wa_itab-fld1, wa_itab-fld2, wa_itab-fld3, wa_itab-fld4.

endloop.

clear wa_itab.

loop at t_itab into wa_itab where fld3 = 'ZA1'.

wa_itab2-fld1 = wa_itab2-fld1 + wa_itab-fld1.

wa_itab2-fld4 = wa_itab2-fld4 + wa_itab-fld4.

endloop.

wa_itab2-fld2 = wa_itab-fld2.

wa_itab2-fld3 = wa_itab-fld3.

append wa_itab2 to t_itab2.

clear wa_itab2.

loop at t_itab into wa_itab where fld3 = 'ZA2'.

wa_itab2-fld1 = wa_itab2-fld1 + wa_itab-fld1.

wa_itab2-fld4 = wa_itab2-fld4 + wa_itab-fld4.

endloop.

wa_itab2-fld2 = wa_itab-fld2.

wa_itab2-fld3 = wa_itab-fld3.

append wa_itab2 to t_itab2.

clear wa_itab2.

write: / 'fld1', 'fld2', 'fld3', 'fld4'.

loop at t_itab2 into wa_itab2.

write: / wa_itab2-fld1, wa_itab2-fld2, wa_itab2-fld3, wa_itab2-fld4.

endloop.

<REMOVED BY MODERATOR>

Regards.

Edited by: Alvaro Tejada Galindo on Apr 7, 2008 5:38 PM

Former Member
0 Kudos
378

myself !!

Former Member
0 Kudos
378

IN MY PGM, I HAVE TO COUNT HOW MANY PERNR IS AVAILABLE FOR ONE ORGEH.

HOW CAN I DO THAT.

CAN YOU HELP ME

THANKS IN ADVANCE

SELECT ZPAYCO TPROG ORGEH ZHOLDT PERNR FROM ZPTIM_HOLIDAY INTO TABLE I_HOLIDAY

WHERE ZPAYCO = ZPAYCO AND

TPROG IN TPROG AND

ORGEH IN ORGEH AND

ZHOLDT IN ZHOLDT AND

PERNR IN PERNR.

former_member303542
Participant
0 Kudos
378

Hello RH,

In the below issue you have two ways to collect the sum based on certain criteria:

1.In the loop of itab ,at every new MFRGR pass the MFRGR field values into another table.

Now once you are completed of collecting all the MFRGR values , loop itab and read the new internal table with distint MFRGR fields and cummulate them into another final internal table.

2.Second way is loop the itab and then at ever new mfrgr field use AT NEW field command and sum the values of qantity into another table .

THanks,

M.naveen kumar,