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: 

Regarding how to find sub totals in alv hierarchial reports

Former Member
0 Kudos
72

hi..

i need to calculate sub totals in alv hierarachial report.

For Eg

sales doc header1

items netpr

item netpr

total netpr

sales doc header2

items netpr

item netpr

total netpr.

this is the o/p i require..

awaiting for your earliest response........

2 REPLIES 2

former_member181995
Active Contributor
0 Kudos
37

Use at end of field.

sum.

endat.

former_member188685
Active Contributor
0 Kudos
37

Using the function REUSE_ALV_HIERSEQ_LIST_DISPLAY

using sort option you can get the totals.

check this sample code .

REPORT  ZTEST_HIER.
TABLES spfli.
TYPE-POOLS:  slis.

DATA:
 BEGIN OF t_spfli OCCURS 0,
   carrid LIKE spfli-carrid,
   connid LIKE spfli-connid,
 END OF t_spfli,

 BEGIN OF t_sflight OCCURS 0,
  carrid LIKE spfli-carrid,
  connid LIKE sflight-connid,
  fldate LIKE sflight-fldate,
  price  LIKE sflight-price,
  currency LIKE sflight-currency,
END OF t_sflight.

DATA:
  t_fieldcat   TYPE slis_t_fieldcat_alv,
  fs_fieldcat  LIKE LINE OF t_fieldcat.

DATA:
  is_keyinfo TYPE slis_keyinfo_alv.

SELECT-OPTIONS:
  s_carrid FOR spfli-carrid.

START-OF-SELECTION.

  SELECT carrid
         connid
    FROM spfli
    INTO TABLE t_spfli
   WHERE carrid IN s_carrid.

  IF sy-subrc EQ 0.
    SELECT carrid
           connid
           fldate
           price
           currency
      FROM sflight
      INTO TABLE t_sflight
       FOR ALL ENTRIES IN t_spfli
     WHERE carrid EQ t_spfli-carrid
       AND connid EQ t_spfli-connid.
  ENDIF.

END-OF-SELECTION.

  is_keyinfo-header01 = 'CARRID'.
  is_keyinfo-item01   = 'CARRID'.

  is_keyinfo-header02 = 'CONNID'.
  is_keyinfo-item02   = 'CONNID'.

  fs_fieldcat-fieldname = 'CARRID'.
  fs_fieldcat-tabname   = 'T_SPFLI'.
  fs_fieldcat-seltext_l = 'Carrier'.
  APPEND fs_fieldcat TO t_fieldcat.
  CLEAR fs_fieldcat.

  fs_fieldcat-fieldname = 'CONNID'.
  fs_fieldcat-tabname   = 'T_SPFLI'.
  fs_fieldcat-seltext_l = 'Connection'.
  APPEND fs_fieldcat TO t_fieldcat.
  CLEAR fs_fieldcat.

  fs_fieldcat-fieldname = 'CARRID'.
  fs_fieldcat-tabname   = 'T_SFLIGHT'.
  fs_fieldcat-seltext_l = 'Carrier'.
  fs_fieldcat-no_out = 'X'.
  APPEND fs_fieldcat TO t_fieldcat.
  CLEAR fs_fieldcat.

  fs_fieldcat-fieldname = 'CONNID'.
  fs_fieldcat-tabname   = 'T_SFLIGHT'.
  fs_fieldcat-seltext_l = 'Connection'.
  fs_fieldcat-no_out = 'X'.
  APPEND fs_fieldcat TO t_fieldcat.
  CLEAR fs_fieldcat.

  fs_fieldcat-fieldname = 'FLDATE'.
  fs_fieldcat-tabname   = 'T_SFLIGHT'.
  fs_fieldcat-seltext_l = 'Flight Date'.
  APPEND fs_fieldcat TO t_fieldcat.
  CLEAR fs_fieldcat.

  fs_fieldcat-fieldname = 'PRICE'.
  fs_fieldcat-tabname   = 'T_SFLIGHT'.
  fs_fieldcat-seltext_l = 'Price'.
  fs_fieldcat-inttype = 'P'.
  fs_fieldcat-do_sum = 'X'.
  APPEND fs_fieldcat TO t_fieldcat.
  CLEAR fs_fieldcat.

  fs_fieldcat-fieldname = 'CURRENCY'.
  fs_fieldcat-tabname   = 'T_SFLIGHT'.
  fs_fieldcat-seltext_l = 'Currency'.
  APPEND fs_fieldcat TO t_fieldcat.
  CLEAR fs_fieldcat.

  DATA:
  t_sort TYPE slis_t_sortinfo_alv,
  fs_sort LIKE LINE OF t_sort.

  fs_sort-fieldname = 'CARRID'.
  fs_sort-tabname = 'T_SPFLI'.
  fs_sort-up = 'X'.
  APPEND fs_sort TO t_sort.
  CLEAR fs_sort.

  fs_sort-fieldname = 'CONNID'.
  fs_sort-tabname = 'T_SPFLI'.
  fs_sort-up = 'X'.
  fs_sort-subtot  = 'X'.
  APPEND fs_sort TO t_sort.
  CLEAR fs_sort.
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      it_fieldcat        = t_fieldcat[]
      it_sort            = t_sort[]
      i_tabname_header   = 'T_SPFLI'
      i_tabname_item     = 'T_SFLIGHT'
      is_keyinfo         = is_keyinfo
    TABLES
      t_outtab_header    = t_spfli
      t_outtab_item      = t_sflight
    EXCEPTIONS
      program_error      = 1.