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: 

sub totals in List reports

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

6 REPLIES 6

Former Member
0 Kudos

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.

0 Kudos

hi,

yep.. I`m sorting the itab according to the fields I want to subtotal.

Former Member
0 Kudos

Hi Farhana Sheriff,

Use COLLECT satement.

COLLECT WA TO IT_NEW_ITAB.

Inside loop your table, add this code.

Regards,

R.Nagarajan.

Former Member
0 Kudos

at end of <field>

sum.

endat

use this in control break statement of write.

hope u will get this

with regards

s.janagar

Former Member
0 Kudos

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

0 Kudos

Hi Advait,

Thanks a lot. This solved my issue.

Thank you all for your quick response.

Regards,

Farhana.