Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Sub total in ALV

Hi,

I would like to know how we code in ALV so that i does sub total on one field ?

Regards,

Imran

Tags:
Former Member
Former Member replied

Hi,

Just follow these simple steps.

1. Define SORT table and FIELDCATALOG table .

  DATA IT_FCAT    TYPE slis_T_fieldcat_alv.
  DATA WA_FCAT    LIKE LINE OF IT_FCAT.
  DATA IT_SORT    TYPE SLIS_T_SORTINFO_ALV.
  DATA WA_SORT    LIKE LINE OF IT_SORT.

  "Others data
  DATA I_REPID    LIKE SY-REPID.

2. Create Grand Total.
    While creating fieldcatalog, we have to set DO_SUM = 'X' for quantity field .

  clear WA_FCAT.
  WA_FCAT-fieldname = 'ANZHL'.  " Your Quantity Field
  WA_FCAT-tabname = 'IT_CUTI'.  " Your Internal Table 
  WA_FCAT-DO_SUM = 'X'.
  append WA_FCAT TO IT_FCAT.

3. Create Subtotal
    Whenever BEGDA [Start Date] is changed Subtotal is displayed ( Set Subtot = 'X' )  .
    Build our sort table .

  Clear: WA_SORT.
  WA_SORT-spos = 1.
  WA_SORT-fieldname = 'BEGDA'. "
  WA_SORT-up = 'X'.
  WA_SORT-subtot = 'X'.
  append WA_SORT  TO IT_SORT.

4.Pass this IT_SORT table thrugh REUSE_ALV_LIST_DISPLAY function module.
  I_REPID = SY-REPID.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME         = I_REPID
      I_INTERNAL_TABNAME     = 'IT_CUTI'  "capital letters = Your Internal Table 
      I_INCLNAME             = I_REPID
    CHANGING
      CT_FIELDCAT            = IT_FCAT
    EXCEPTIONS
      INCONSISTENT_INTERFACE = 1
      PROGRAM_ERROR          = 2
      OTHERS                 = 3.  

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = I_REPID
      IT_FIELDCAT        = IT_FCAT
      I_SAVE             = 'A'
      IT_SORT            = IT_SORT
    TABLES
      T_OUTTAB           = IT_CUTI  " Your Internal Table 
    EXCEPTIONS
      PROGRAM_ERROR      = 1
      OTHERS             = 2.

Hopefuly it will help you.

Regards,

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question