01-08-2014 10:48 AM
Hi Experts,
I Need to do subtotals and grandtotals in interactive reports using control break events and i have done according to that and below is
code
*&---------------------------------------------------------------------*
*& Report Z80INTERACTIVE_SUBTOTAL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z80INTERACTIVE_SUBTOTAL.
TYPES: BEGIN OF typ_cust,
customerno(15) TYPE c,
customername(15) TYPE c,
quantity(15) TYPE c,
amount(15) TYPE c,
ws_total TYPE c,
wg_total TYPE c,
ws_totals TYPE c,
wg_totals TYPE c,
END OF typ_cust.
DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno
customername quantity amount .
DATA : wa_cust TYPE typ_cust,
wa_temp TYPE typ_cust,
ws_total TYPE typ_cust,
wg_total TYPE typ_cust,
ws_totals TYPE typ_cust,
wg_totals TYPE typ_cust.
DEFINE fill.
wa_cust-customerno = &1.
wa_cust-customername = &2.
wa_cust-quantity = &3.
wa_cust-amount = &4.
append wa_cust to it_cust.
END-OF-DEFINITION.
fill '1000' 'C1' '10' '35'.
fill '1000' 'C1' '11' '45'.
fill '1000' 'C1' '12' '55'.
fill '1000' 'C1' '13' '65'.
fill '1000' 'C1' '14' '75'.
fill '1000' 'C1' '15' '85'.
fill '1000' 'C1' '16' '95'.
fill '1001' 'C2' '17' '25'.
fill '1001' 'C2' '18' '55'.
fill '1001' 'C2' '19' '65'.
LOOP AT it_cust INTO wa_cust.
wa_temp = wa_cust.
AT FIRST.
WRITE:/ 'Customer Details'.
ENDAT.
AT NEW customername.
WRITE:/ wa_temp-customerno,wa_temp-customername.
ENDAT.
WRITE:/33 wa_temp-quantity,40 wa_temp-amount.
SKIP 1.
ws_total = ws_total + wa_temp-quantity.
ws_totals = ws_totals + wa_temp-amount.
AT END OF customerno.
* SUM.
ULINE 43(16).
WRITE:/4 'Subtotal is:',15 ws_total,ws_totals.
CLEAR ws_total.
* wa_temp-quantity,30 wa_temp-amount.
ENDAT.
wg_total = wg_total + wa_temp-quantity.
wg_totals = wg_totals + wa_temp-amount.
AT LAST .
SKIP 2.
WRITE:/4 'GRAND TOTAL IS :',18 wg_total,wg_totals.
CLEAR: wg_total,wg_totals.
ENDAT.
ENDLOOP.
and the issue is i dont want to use another workarea.So please help me in this issue.
01-08-2014 11:44 AM
Hi Vinod,
Try Below Code.
REPORT ZTEMP_SAMPLE_IT_ALV.
"REPORT Z80INTERACTIVE_SUBTOTAL.
TYPES: BEGIN OF typ_cust,
customerno(15) TYPE c,
customername(15) TYPE c,
quantity(15) TYPE c,
amount(15) TYPE c,
ws_total TYPE c,
wg_total TYPE c,
ws_totals TYPE c,
wg_totals TYPE c,
END OF typ_cust.
DATA: cust(15) TYPE c.
DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno
customername quantity amount .
DATA : wa_cust TYPE typ_cust,
wa_temp TYPE typ_cust,
ws_total TYPE typ_cust,
wg_total TYPE typ_cust,
ws_totals TYPE typ_cust,
wg_totals TYPE typ_cust.
DEFINE fill.
wa_cust-customerno = &1.
wa_cust-customername = &2.
wa_cust-quantity = &3.
wa_cust-amount = &4.
append wa_cust to it_cust.
END-OF-DEFINITION.
fill '1000' 'C1' '10' '35'.
fill '1000' 'C1' '11' '45'.
fill '1000' 'C1' '12' '55'.
fill '1000' 'C1' '13' '65'.
fill '1000' 'C1' '14' '75'.
fill '1000' 'C1' '15' '85'.
fill '1000' 'C1' '16' '95'.
fill '1001' 'C2' '17' '25'.
fill '1001' 'C2' '18' '55'.
fill '1001' 'C2' '19' '65'.
LOOP AT it_cust INTO wa_cust.
"wa_temp = wa_cust.
AT FIRST.
WRITE:/ 'Customer Details'.
ENDAT.
if cust ne wa_cust-customername.
"AT NEW customername.
WRITE:/ wa_cust-customerno,wa_cust-customername.
endif.
cust = wa_cust-customername.
"ENDAT.
WRITE:/33 wa_cust-quantity,40 wa_cust-amount.
SKIP 1.
ws_total = ws_total + wa_cust-quantity.
ws_totals = ws_totals + wa_cust-amount.
AT END OF customerno.
* SUM.
ULINE 43(16).
WRITE:/4 'Subtotal is:',15 ws_total,ws_totals.
CLEAR ws_total.
* wa_temp-quantity,30 wa_temp-amount.
ENDAT.
wg_total = wg_total + wa_cust-quantity.
wg_totals = wg_totals + wa_cust-amount.
AT LAST .
SKIP 2.
WRITE:/4 'GRAND TOTAL IS :',18 wg_total,wg_totals.
CLEAR: wg_total,wg_totals.
ENDAT.
ENDLOOP.
01-08-2014 11:08 AM
hi,
if you use ' wa_cust instead of wa_temp' .What error you are getting?
01-08-2014 11:25 AM
Hi krishna,
i dont have any error all i need is i dont want to use another work area with single workarea i want to display the output.
Thanks,
Vinod.
01-08-2014 11:27 AM
If i am using with single workarea then it is showing me ***** instead of values,so please correct me in this.
01-08-2014 11:40 AM
hi,
Actually at new statement allow single varible only i.e. wa_temp-customerno.
if want more than one we have to pass those fields to another variable use those variables then you get it.
AT NEW customername.
WRITE:/ wa_temp-customerno,wa_temp-customername.
ENDAT.
try with this code..
TYPES: BEGIN OF typ_cust,
customerno(15) TYPE c,
customername(15) TYPE c,
quantity(15) TYPE c,
amount(15) TYPE c,
ws_total TYPE c,
wg_total TYPE c,
ws_totals TYPE c,
wg_totals TYPE c,
END OF typ_cust.
DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno
customername quantity amount .
DATA : wa_cust TYPE typ_cust,
wa_temp TYPE typ_cust,
ws_total TYPE typ_cust,
wg_total TYPE typ_cust,
ws_totals TYPE typ_cust,
wg_totals TYPE typ_cust.
DEFINE fill.
wa_cust-customerno = &1.
wa_cust-customername = &2.
wa_cust-quantity = &3.
wa_cust-amount = &4.
append wa_cust to it_cust.
END-OF-DEFINITION.
fill '1000' 'C1' '10' '35'.
fill '1000' 'C1' '11' '45'.
fill '1000' 'C1' '12' '55'.
fill '1000' 'C1' '13' '65'.
fill '1000' 'C1' '14' '75'.
fill '1000' 'C1' '15' '85'.
fill '1000' 'C1' '16' '95'.
fill '1001' 'C2' '17' '25'.
fill '1001' 'C2' '18' '55'.
fill '1001' 'C2' '19' '65'.
data x(15) type c.
LOOP AT it_cust INTO wa_cust.
wa_temp = wa_cust.
x = wa_cust-customername.
AT FIRST.
WRITE:/ 'Customer Details'.
ENDAT.
AT NEW customername.
WRITE:/ wa_cust-customerno,x."wa_cust-customername.
ENDAT.
WRITE:/33 wa_cust-quantity,40 wa_cust-amount.
SKIP 1.
ws_total = ws_total + wa_cust-quantity.
ws_totals = ws_totals + wa_cust-amount.
AT END OF customerno.
* SUM.
ULINE 43(16).
WRITE:/4 'Subtotal is:',15 ws_total,ws_totals.
CLEAR ws_total.
* wa_temp-quantity,30 wa_temp-amount.
ENDAT.
wg_total = wg_total + wa_cust-quantity.
wg_totals = wg_totals + wa_cust-amount.
AT LAST .
SKIP 2.
WRITE:/4 'GRAND TOTAL IS :',18 wg_total,wg_totals.
CLEAR: wg_total,wg_totals.
ENDAT.
ENDLOOP.
01-08-2014 11:44 AM
Hi Vinod,
Try Below Code.
REPORT ZTEMP_SAMPLE_IT_ALV.
"REPORT Z80INTERACTIVE_SUBTOTAL.
TYPES: BEGIN OF typ_cust,
customerno(15) TYPE c,
customername(15) TYPE c,
quantity(15) TYPE c,
amount(15) TYPE c,
ws_total TYPE c,
wg_total TYPE c,
ws_totals TYPE c,
wg_totals TYPE c,
END OF typ_cust.
DATA: cust(15) TYPE c.
DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno
customername quantity amount .
DATA : wa_cust TYPE typ_cust,
wa_temp TYPE typ_cust,
ws_total TYPE typ_cust,
wg_total TYPE typ_cust,
ws_totals TYPE typ_cust,
wg_totals TYPE typ_cust.
DEFINE fill.
wa_cust-customerno = &1.
wa_cust-customername = &2.
wa_cust-quantity = &3.
wa_cust-amount = &4.
append wa_cust to it_cust.
END-OF-DEFINITION.
fill '1000' 'C1' '10' '35'.
fill '1000' 'C1' '11' '45'.
fill '1000' 'C1' '12' '55'.
fill '1000' 'C1' '13' '65'.
fill '1000' 'C1' '14' '75'.
fill '1000' 'C1' '15' '85'.
fill '1000' 'C1' '16' '95'.
fill '1001' 'C2' '17' '25'.
fill '1001' 'C2' '18' '55'.
fill '1001' 'C2' '19' '65'.
LOOP AT it_cust INTO wa_cust.
"wa_temp = wa_cust.
AT FIRST.
WRITE:/ 'Customer Details'.
ENDAT.
if cust ne wa_cust-customername.
"AT NEW customername.
WRITE:/ wa_cust-customerno,wa_cust-customername.
endif.
cust = wa_cust-customername.
"ENDAT.
WRITE:/33 wa_cust-quantity,40 wa_cust-amount.
SKIP 1.
ws_total = ws_total + wa_cust-quantity.
ws_totals = ws_totals + wa_cust-amount.
AT END OF customerno.
* SUM.
ULINE 43(16).
WRITE:/4 'Subtotal is:',15 ws_total,ws_totals.
CLEAR ws_total.
* wa_temp-quantity,30 wa_temp-amount.
ENDAT.
wg_total = wg_total + wa_cust-quantity.
wg_totals = wg_totals + wa_cust-amount.
AT LAST .
SKIP 2.
WRITE:/4 'GRAND TOTAL IS :',18 wg_total,wg_totals.
CLEAR: wg_total,wg_totals.
ENDAT.
ENDLOOP.
01-08-2014 11:58 AM
Hi vinod,
The main reason For the ******* value when you code with SUM is that you have declared the amount and quantity in c .. change it to i..
and do the following code It will give you result.
TYPES: BEGIN OF typ_cust,
customerno(15) TYPE c,
customername(15) TYPE c,
quantity TYPE i,
amount TYPE i,
ws_total TYPE i,
wg_total TYPE i,
ws_totals TYPE i,
wg_totals TYPE i,
END OF typ_cust.
DATA : it_cust TYPE SORTED TABLE OF typ_cust WITH UNIQUE KEY customerno
customername quantity amount .
DATA : wa_cust TYPE typ_cust,
wa_temp TYPE typ_cust,
ws_total TYPE typ_cust,
wg_total TYPE typ_cust,
ws_totals TYPE typ_cust,
wg_totals TYPE typ_cust.
DEFINE fill.
wa_cust-customerno = &1.
wa_cust-customername = &2.
wa_cust-quantity = &3.
wa_cust-amount = &4.
append wa_cust to it_cust.
END-OF-DEFINITION.
fill '1000' 'C1' '10' '35'.
fill '1000' 'C1' '11' '45'.
fill '1000' 'C1' '12' '55'.
fill '1000' 'C1' '13' '65'.
fill '1000' 'C1' '14' '75'.
fill '1000' 'C1' '15' '85'.
fill '1000' 'C1' '16' '95'.
fill '1001' 'C2' '17' '25'.
fill '1001' 'C2' '18' '55'.
fill '1001' 'C2' '19' '65'.
LOOP AT it_cust INTO wa_cust.
AT FIRST.
WRITE:/ 'Customer Details'.
ULINE.
ENDAT.
AT NEW customername.
* READ TABLE ITAB INDEX SY-TABIX.
FORMAT INTENSIFIED OFF COLOR COL_HEADING.
WRITE:/ wa_cust-customerno,wa_cust-customername.
FORMAT RESET.
ENDAT.
WRITE:/50 wa_cust-quantity, wa_cust-amount.
AT END OF customername.
SUM.
FORMAT INTENSIFIED ON COLOR COL_TOTAL.
WRITE:/ 'Sub Total: ',60 wa_cust-quantity, wa_cust-amount.
FORMAT RESET.
ENDAT.
AT LAST.
SUM.
FORMAT INTENSIFIED ON COLOR COL_GROUP.
WRITE:/ 'Total: ',60 wa_cust-quantity, wa_cust-amount.
FORMAT RESET.
ENDAT.
ENDLOOP.
Regards,
sivaganesh
01-08-2014 2:16 PM