09-30-2008 9:17 AM
Hi,
Could anyone tell me how do we do sub totals in List reporting.
For instance, I do have list of records which belongs to different Cost centres and I want to sum up a Value (Type CUR) field cost-centre wise and display it as
CC1 2300
CC1 1000
CC2 500
Sub-totals:
CC1 3300
CC2 500
I tried using AT END statement, but this does not seems to work for this requirement.
Thanks in advance.
Regards,
Farhana.
09-30-2008 9:28 AM
Hi,
Check this code
REPORT Z_SUMMARIZE .
TYPES: BEGIN OF T_TYPE,
CODE(1),
name(20),
SALES TYPE P,
DISCOUNT TYPE P,
END OF T_TYPE.
DATA: T TYPE STANDARD TABLE OF T_TYPE WITH NON-UNIQUE
DEFAULT KEY INITIAL SIZE 100.
DATA: T2 TYPE STANDARD TABLE OF T_TYPE WITH NON-UNIQUE
DEFAULT KEY INITIAL SIZE 100,
WA_T TYPE T_TYPE,
wa_t1 type t_type.
data l_mod type i.
do 9 times.
.
l_mod = sy-index mod 2.
if l_mod = 0.
wa_t-code = '1'.
wa_t-name = 'Sam'.
else.
wa_t-code = '2'.
wa_t-name = 'Chris'.
endif.
wa_t-sales = sy-index * sy-index.
append wa_t to t.
enddo.
wa_t-code = '3'.
wa_t-name = 'John'.
wa_t-sales = 200.
append wa_t to t.
wa_t-code = '2'.
wa_t-name = 'John'.
wa_t-sales = 300.
append wa_t to t.
wa_t-code = '3'.
wa_t-name = 'Mathew'.
wa_t-sales = 200.
append wa_t to t.
sort t by code name.
LOOP AT T INTO WA_T.
wa_t1 = wa_t.
AT FIRST.
SUM.
WRITE: /4 'Grand Total:',
20 WA_T-SALES.
ULINE. SKIP.
ENDAT.
write 😕 wa_t-code, 20 wa_t-name, 40 wa_t-sales.
at end of name.
SUM.
* write : / 'Sum of Sales for',
* 20 wa_t-name, 40 wa_t-sales.
append wa_t to t2.
ENDAT.
ENDLOOP.
skip.
write : / sy-uline(40),'Summary', sy-uline(40).
loop at t2 into wa_t.
write 😕 wa_t-code, 20 wa_t-name, 40 wa_t-sales.
skip.
endloop.
regards,
Advait
09-30-2008 9:21 AM
Hi Farhana,
Before looping the internal table, just check whether you are Sorting the table by the table field with values CC1 CC2 etc or not. This makes lot of difference.
Regards,
Swapna.
09-30-2008 9:37 AM
hi,
yep.. I`m sorting the itab according to the fields I want to subtotal.
09-30-2008 9:21 AM
Hi Farhana Sheriff,
Use COLLECT satement.
COLLECT WA TO IT_NEW_ITAB.
Inside loop your table, add this code.
Regards,
R.Nagarajan.
09-30-2008 9:25 AM
at end of <field>
sum.
endat
use this in control break statement of write.
hope u will get this
with regards
s.janagar
09-30-2008 9:28 AM
Hi,
Check this code
REPORT Z_SUMMARIZE .
TYPES: BEGIN OF T_TYPE,
CODE(1),
name(20),
SALES TYPE P,
DISCOUNT TYPE P,
END OF T_TYPE.
DATA: T TYPE STANDARD TABLE OF T_TYPE WITH NON-UNIQUE
DEFAULT KEY INITIAL SIZE 100.
DATA: T2 TYPE STANDARD TABLE OF T_TYPE WITH NON-UNIQUE
DEFAULT KEY INITIAL SIZE 100,
WA_T TYPE T_TYPE,
wa_t1 type t_type.
data l_mod type i.
do 9 times.
.
l_mod = sy-index mod 2.
if l_mod = 0.
wa_t-code = '1'.
wa_t-name = 'Sam'.
else.
wa_t-code = '2'.
wa_t-name = 'Chris'.
endif.
wa_t-sales = sy-index * sy-index.
append wa_t to t.
enddo.
wa_t-code = '3'.
wa_t-name = 'John'.
wa_t-sales = 200.
append wa_t to t.
wa_t-code = '2'.
wa_t-name = 'John'.
wa_t-sales = 300.
append wa_t to t.
wa_t-code = '3'.
wa_t-name = 'Mathew'.
wa_t-sales = 200.
append wa_t to t.
sort t by code name.
LOOP AT T INTO WA_T.
wa_t1 = wa_t.
AT FIRST.
SUM.
WRITE: /4 'Grand Total:',
20 WA_T-SALES.
ULINE. SKIP.
ENDAT.
write 😕 wa_t-code, 20 wa_t-name, 40 wa_t-sales.
at end of name.
SUM.
* write : / 'Sum of Sales for',
* 20 wa_t-name, 40 wa_t-sales.
append wa_t to t2.
ENDAT.
ENDLOOP.
skip.
write : / sy-uline(40),'Summary', sy-uline(40).
loop at t2 into wa_t.
write 😕 wa_t-code, 20 wa_t-name, 40 wa_t-sales.
skip.
endloop.
regards,
Advait
09-30-2008 1:40 PM
Hi Advait,
Thanks a lot. This solved my issue.
Thank you all for your quick response.
Regards,
Farhana.