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

Subtotal Based on the fields

Former Member
0 Likes
2,146

Hi Experts,

Please guide me,i am alonr here.

I want to calculate the sub total of vat amount based on GR NUMBER in classical report.

I have report as shown below.

GRNUMBER AMT1 AMT2 Amt3

111111111 3.00 10.00

111111111 23.00 432.00

111111111 234.0 22.00

333333333 34.00

333333333 45.00

I wnat subtotal of amt1 and amt2 amt3 based on the gr number.

for that i tried the control statment like AT END OF GRNUMBER

sum.

write : amt1,amt2.

endat.

but its not calculating subtoatals based on the gr.

Please guide me, i am alone here..

Thanks & regards,

Krishna Reddy

Edited by: krishnab121 on Feb 24, 2012 6:22 AM

1 ACCEPTED SOLUTION
Read only

sreenivas_pachva
Participant
0 Likes
2,063

Hi,

Please go through the below program and you can adjust the as per your requirement..

REPORT  ZGRP_77 NO STANDARD PAGE HEADING LINE-SIZE 116.
TABLES VBAP.
*TO CREATE LINE TYPE .
TYPES : BEGIN OF LINE_TYPE,
          VBELN TYPE VBELN_VA, "SALES DOCUMENT NUMBER
          POSNR TYPE POSNR_VA, "SALES DOCUMENT ITEM
          MATNR TYPE MATNR,    "MATERIAL NUMBER
          NETWR TYPE NETWR_AP, "NET VALUE
          KWMENG TYPE KWMENG,  "ORDERED QUANTITY
          ERDAT TYPE ERDAT,    "DATE
          NETPR TYPE NETPR,   "UNIT PRICE
        END OF LINE_TYPE.

*TO CREATE INTERNAL TABLE IT_VBAP OF STRUCTURE LINE_TYPE WITH HEADER LINE.
DATA IT_VBAP TYPE TABLE OF LINE_TYPE WITH HEADER LINE.

*TO PROVIDE DATE RANGE
SELECT-OPTIONS S_ERDAT FOR VBAP-ERDAT.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.

FORM GET_DATA .
*TO GET THE DATA FROM DBTABLE : VBAP INTO INTERNAL TABLE IT_VBAP
SELECT *
  FROM VBAP
  INTO CORRESPONDING FIELDS OF TABLE IT_VBAP
    WHERE ERDAT IN S_ERDAT.
*TO SORT INTERNAL TABLE IT_VBAP
SORT IT_VBAP.
ENDFORM.                    " GET_DATA

FORM DISPLAY_DATA .
LOOP AT IT_VBAP.

AT FIRST.
*PAGE HEADING
WRITE:/20 'SALES REPORT' COLOR 6 INTENSIFIED.
*COLUMN HEADINGS
WRITE:/2 'SDOC.NO' COLOR 3 INVERSE,
      14 'S ITEM' COLOR 4 INVERSE,
      24 'MATERIAL NUMBER' COLOR 2 INVERSE,
      44 'QUANTITY' COLOR 1 INVERSE,
      60 'UNIT PRICE' COLOR 6 INVERSE,
      72 'NET VALUE ' COLOR 7 INVERSE,
      85 'DATE' COLOR 3 INVERSE.
ENDAT.

*AT NEW VBELN.
*WRITE:/3 IT_VBAP-VBELN COLOR 6 INVERSE.
*ENDAT.

ON CHANGE OF IT_VBAP-VBELN OR IT_VBAP-POSNR.
WRITE:/3 IT_VBAP-VBELN COLOR 6 INVERSE.
ENDON.

WRITE:/15 IT_VBAP-POSNR COLOR 5 INVERSE,
       25 IT_VBAP-MATNR COLOR 1 INVERSE,
       44 IT_VBAP-KWMENG COLOR 3 INVERSE LEFT-JUSTIFIED,
       60 IT_VBAP-NETPR COLOR 4 INVERSE CENTERED,
       72 IT_VBAP-NETWR COLOR 2 INVERSE CENTERED,
       85 IT_VBAP-ERDAT COLOR 7 INVERSE.

AT END OF VBELN.
*TO CALCULATE SUBTOTAL
SUM.
WRITE:/45 IT_VBAP-KWMENG COLOR 3 CENTERED,
       60 IT_VBAP-NETPR COLOR 4 CENTERED,
       72 IT_VBAP-NETWR COLOR 2 CENTERED.
ENDAT.

AT LAST.
*TO FIND GRAND TOTAL
SUM.
WRITE:/45 IT_VBAP-KWMENG COLOR 3 CENTERED,
       60 IT_VBAP-NETPR COLOR 4 CENTERED,
       72 IT_VBAP-NETWR COLOR 2 CENTERED.
ENDAT.

ENDLOOP.

ENDFORM.    " DISPLAY_DATA

I hope the above information helpful to you..

Thanks&Regards

Sreenivas Pachva

Edited by: sreenivas.p on Feb 24, 2012 7:08 AM

14 REPLIES 14
Read only

Former Member
0 Likes
2,063

sort your internal table using grnumber.


types: begin of itab,
           grnumber type .......
           .
           .
           enb of itab.

" internal table & work area declaration.

" your logic.

sort <internal table> by grnumber.
loop at  <internal table>.
at end of grnumber.
sum.
write:/ wa_internaltable-grnumber,
           wa_internaltable-amt1,
           wa_internaltable-amt2.
endat.
endloop.

o/p


111111111 ( total of amt1)  (total of amt2)
333333333  ( total of amt1)  (total of amt2)

Read only

0 Likes
2,063

Try this code :

 

DATA : BEGIN OF itab OCCURS 0,
        mblnr TYPE mseg-mblnr,
        netwr TYPE mseg-dmbtr,
        netwr1 TYPE mseg-dmbtr,
       END OF itab.

itab-mblnr = '1111111111' . itab-netwr = '100.00'. itab-netwr1 = '200.00'. APPEND itab.
itab-mblnr = '1111111111' . itab-netwr = '200.00'. itab-netwr1 = '300.00'. APPEND itab.
itab-mblnr = '1111111111' . itab-netwr = '300.00'. itab-netwr1 = '400.00'. APPEND itab.
itab-mblnr = '2222222222' . itab-netwr = '150.00'. itab-netwr1 = '200.00'. APPEND itab.
itab-mblnr = '3333333333' . itab-netwr = '250.00'. itab-netwr1 = '300.00'. APPEND itab.

SORT itab BY mblnr.

LOOP AT itab.
  WRITE : / itab-mblnr,itab-netwr,itab-netwr1.
  AT END OF mblnr.
    WRITE : / sy-uline.
    SUM.
    WRITE : / itab-netwr,itab-netwr1.
  ENDAT.
ENDLOOP.

Regards,

Gagan

Read only

0 Likes
2,063

Hi,

Thanks for giving replay.

I was tried that way only,But its not calculating the sub total and some data has print like ******************************** format

and one more thing is my itab is with data and occurs statment.

Please guide me any othe solution,and where it is problem.

Thanks&regards

Krishna Reddy

Read only

Former Member
0 Likes
2,063

Hi,

Try this one.

LOOP AT itab.

  AT END OF grnumber.
    SUM.
    ULINE.
    WRITE:/ itab-amt1, itab-amt2, itab-amt3.
  ENDAT.

ENDLOOP.

Regards,

iostreamax

Read only

Former Member
0 Likes
2,063

Try this


types: begin of itab,
           grnumber type .......
           .
           .
           enb of itab.
 data: num type grnumber. "add this change grnumber to the corresponding data type
" internal table & work area declaration.
 
" your logic.
 
sort <internal table> by grnumber.
loop at  <internal table>.
 num =  wa_internaltable-grnumber  . "add this
at end of grnumber.
sum.
write:/ num,  "add this
           wa_internaltable-amt1,
           wa_internaltable-amt2.
endat.
endloop.

Read only

sreenivas_pachva
Participant
0 Likes
2,064

Hi,

Please go through the below program and you can adjust the as per your requirement..

REPORT  ZGRP_77 NO STANDARD PAGE HEADING LINE-SIZE 116.
TABLES VBAP.
*TO CREATE LINE TYPE .
TYPES : BEGIN OF LINE_TYPE,
          VBELN TYPE VBELN_VA, "SALES DOCUMENT NUMBER
          POSNR TYPE POSNR_VA, "SALES DOCUMENT ITEM
          MATNR TYPE MATNR,    "MATERIAL NUMBER
          NETWR TYPE NETWR_AP, "NET VALUE
          KWMENG TYPE KWMENG,  "ORDERED QUANTITY
          ERDAT TYPE ERDAT,    "DATE
          NETPR TYPE NETPR,   "UNIT PRICE
        END OF LINE_TYPE.

*TO CREATE INTERNAL TABLE IT_VBAP OF STRUCTURE LINE_TYPE WITH HEADER LINE.
DATA IT_VBAP TYPE TABLE OF LINE_TYPE WITH HEADER LINE.

*TO PROVIDE DATE RANGE
SELECT-OPTIONS S_ERDAT FOR VBAP-ERDAT.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.

FORM GET_DATA .
*TO GET THE DATA FROM DBTABLE : VBAP INTO INTERNAL TABLE IT_VBAP
SELECT *
  FROM VBAP
  INTO CORRESPONDING FIELDS OF TABLE IT_VBAP
    WHERE ERDAT IN S_ERDAT.
*TO SORT INTERNAL TABLE IT_VBAP
SORT IT_VBAP.
ENDFORM.                    " GET_DATA

FORM DISPLAY_DATA .
LOOP AT IT_VBAP.

AT FIRST.
*PAGE HEADING
WRITE:/20 'SALES REPORT' COLOR 6 INTENSIFIED.
*COLUMN HEADINGS
WRITE:/2 'SDOC.NO' COLOR 3 INVERSE,
      14 'S ITEM' COLOR 4 INVERSE,
      24 'MATERIAL NUMBER' COLOR 2 INVERSE,
      44 'QUANTITY' COLOR 1 INVERSE,
      60 'UNIT PRICE' COLOR 6 INVERSE,
      72 'NET VALUE ' COLOR 7 INVERSE,
      85 'DATE' COLOR 3 INVERSE.
ENDAT.

*AT NEW VBELN.
*WRITE:/3 IT_VBAP-VBELN COLOR 6 INVERSE.
*ENDAT.

ON CHANGE OF IT_VBAP-VBELN OR IT_VBAP-POSNR.
WRITE:/3 IT_VBAP-VBELN COLOR 6 INVERSE.
ENDON.

WRITE:/15 IT_VBAP-POSNR COLOR 5 INVERSE,
       25 IT_VBAP-MATNR COLOR 1 INVERSE,
       44 IT_VBAP-KWMENG COLOR 3 INVERSE LEFT-JUSTIFIED,
       60 IT_VBAP-NETPR COLOR 4 INVERSE CENTERED,
       72 IT_VBAP-NETWR COLOR 2 INVERSE CENTERED,
       85 IT_VBAP-ERDAT COLOR 7 INVERSE.

AT END OF VBELN.
*TO CALCULATE SUBTOTAL
SUM.
WRITE:/45 IT_VBAP-KWMENG COLOR 3 CENTERED,
       60 IT_VBAP-NETPR COLOR 4 CENTERED,
       72 IT_VBAP-NETWR COLOR 2 CENTERED.
ENDAT.

AT LAST.
*TO FIND GRAND TOTAL
SUM.
WRITE:/45 IT_VBAP-KWMENG COLOR 3 CENTERED,
       60 IT_VBAP-NETPR COLOR 4 CENTERED,
       72 IT_VBAP-NETWR COLOR 2 CENTERED.
ENDAT.

ENDLOOP.

ENDFORM.    " DISPLAY_DATA

I hope the above information helpful to you..

Thanks&Regards

Sreenivas Pachva

Edited by: sreenivas.p on Feb 24, 2012 7:08 AM

Read only

0 Likes
2,063

Hi All,

still i am getting same problem,that means not calculatin and *********************************** printing format.

I am posting my code please go through and guide me please.

SORT it_subtotal by YLFBNR.

LOOP AT IT_FINAL.

  • AT FIRST.

WRITE: /1 SY-VLINE, IT_FINAL-YLFBNR, SY-VLINE, "CHK FOR Mis NUMBER

20 IT_FINAL-YBUDAT, SY-VLINE, " Mis date

35 IT_FINAL-NAME1, SY-VLINE,

73 IT_FINAL-TIN, 87 SY-VLINE,

90 IT_FINAL-YMAKTX, 130 SY-VLINE,

131 IT_FINAL-YXBLNR, 143 SY-VLINE,

144 IT_FINAL-YBLDAT NO-GAP, 158 SY-VLINE NO-GAP.

at END OF YLFBNR.

sum.

write :/159 IT_FINAL-INV4 NO-GAP, 173 SY-VLINE NO-GAP,

174 IT_FINAL-INV125 ,190 SY-VLINE NO-GAP,

191 IT_FINAL-INV5 NO-GAP, 205 SY-VLINE NO-GAP,

206 IT_FINAL-INV135, 221 SY-VLINE NO-GAP,

222 IT_FINAL-INV14, 236 SY-VLINE NO-GAP,

237 IT_FINAL-TAX4, 251 SY-VLINE NO-GAP,

252 IT_FINAL-TAX125, 270 SY-VLINE NO-GAP,

271 IT_FINAL-TAX5, 289 SY-VLINE NO-GAP,

290 IT_FINAL-TAX135, 303 SY-VLINE NO-GAP,

304 IT_FINAL-TAX14, 318 SY-VLINE NO-GAP.

  • 308 IT_FINAL-BELNR, 320 sy-vline NO-GAP,

endat.

WRITE:/319 IT_FINAL-BELNR , 335 sy-vline.

  • ENDAT.

Thanks&regars.

Krishna

Read only

0 Likes
2,063

Hi,

why do you sort internal table IT_SUBTOTAL while you use IT_FINAL in your LOOP statement to get the subtotal per YLFBNR.

Instead, try this.

SORT it_final by YLFBNR.

Regards,

iostreamax

Read only

0 Likes
2,063

Hi,

please check internal table declaration, all field which u want to write in at...endat statement should be structured before short field. like in this case your internal table structure should be like :

begin of IT_FINAL.

INV125

INV5

INV135

INV14

Tax...

..

..

YLFBNR -


> Key Field

.... after this all fields are represented as *

....

end of IT_FINAL.

Regards,

Gagan

Read only

0 Likes
2,063

Hi,

Thanks for replay,

that internal table my mistake only,i was modifiyed also.

after that also not updated.

Please guide me.

Thnaks&regards,

krishna

Read only

0 Likes
2,063

what are the data types you are using for INV* and TAX* field?

Read only

0 Likes
2,063

HI Gagan,

Thanks For replay,

I am using data type is WERTV6(amount).

Thanks&regards

krishna

Read only

0 Likes
2,063

->Do remember that your GR number field (YLFBNR) Must be a first field in your internal table declarations.

->the internal table must be sorted befor using control statements like (at end of, at new..)

->another point is all the variables you are displaying as subtotal must be a data type of numbers, or amount. If any one is different, output will come as **************** for all.

If im not wrong your code should be like this, but check above points, before coding

sort it_final by YLFBNR.
LOOP AT IT_FINAL.
WRITE: 
/1 SY-VLINE, IT_FINAL-YLFBNR, SY-VLINE, "CHK FOR Mis NUMBER
20 IT_FINAL-YBUDAT, SY-VLINE, " Mis date
35 IT_FINAL-NAME1, SY-VLINE,
73 IT_FINAL-TIN, 87 SY-VLINE,
90 IT_FINAL-YMAKTX, 130 SY-VLINE,
131 IT_FINAL-YXBLNR, 143 SY-VLINE,
144 IT_FINAL-YBLDAT NO-GAP, 158 SY-VLINE NO-GAP,
159 IT_FINAL-INV4 NO-GAP, 173 SY-VLINE NO-GAP,
174 IT_FINAL-INV125 ,190 SY-VLINE NO-GAP,
191 IT_FINAL-INV5 NO-GAP, 205 SY-VLINE NO-GAP,
206 IT_FINAL-INV135, 221 SY-VLINE NO-GAP,
222 IT_FINAL-INV14, 236 SY-VLINE NO-GAP,
237 IT_FINAL-TAX4, 251 SY-VLINE NO-GAP,
252 IT_FINAL-TAX125, 270 SY-VLINE NO-GAP,
271 IT_FINAL-TAX5, 289 SY-VLINE NO-GAP,
290 IT_FINAL-TAX135, 303 SY-VLINE NO-GAP,
304 IT_FINAL-TAX14, 318 SY-VLINE NO-GAP,
319 IT_FINAL-BELNR , 335 sy-vline.

at END OF YLFBNR.
sum.
write :
/159 IT_FINAL-INV4 NO-GAP, 173 SY-VLINE NO-GAP,
174 IT_FINAL-INV125 ,190 SY-VLINE NO-GAP,
191 IT_FINAL-INV5 NO-GAP, 205 SY-VLINE NO-GAP,
206 IT_FINAL-INV135, 221 SY-VLINE NO-GAP,
222 IT_FINAL-INV14, 236 SY-VLINE NO-GAP,
237 IT_FINAL-TAX4, 251 SY-VLINE NO-GAP,
252 IT_FINAL-TAX125, 270 SY-VLINE NO-GAP,
271 IT_FINAL-TAX5, 289 SY-VLINE NO-GAP,
290 IT_FINAL-TAX135, 303 SY-VLINE NO-GAP,
304 IT_FINAL-TAX14, 318 SY-VLINE NO-GAP.
endat.
endloop.

Read only

0 Likes
2,063

Hi Play,

Thaks for guided me,

Problem has solved.

Thanks&regards

Krishna