Skip to Content
0
Former Member
Mar 30, 2009 at 11:48 AM

ALV grid total andsub-total

22 Views

hi there...I know there´s a lot of posts about this subject but i didn't find what i´m looking for...

I want to know if there´s some way to give a total and a sub-total of a field, but instead of the total and subtotal sums I just want a count of the number of rows for the field that I've sorted.

FIELDCATALOG-FIELDNAME   = 'BUKRS'.
  FIELDCATALOG-SELTEXT_M   = 'BUKRS'.
  FIELDCATALOG-COL_POS     = 0.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.


  FIELDCATALOG-FIELDNAME   = 'BUTXT'.
  FIELDCATALOG-SELTEXT_M   = 'BUTXT'.
  FIELDCATALOG-COL_POS     = 1.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.



  FIELDCATALOG-FIELDNAME   = 'LIFNR'.
  FIELDCATALOG-SELTEXT_M   = 'LIFNR'.
  FIELDCATALOG-COL_POS     = 2.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'NAME1'.
  FIELDCATALOG-SELTEXT_M   = 'NAME1'.
  FIELDCATALOG-COL_POS     = 3.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'MBLNR'.
  FIELDCATALOG-SELTEXT_M   = 'MBLNR'.
  FIELDCATALOG-COL_POS     = 4.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'MJAHR'.
  FIELDCATALOG-SELTEXT_M   = 'MJAHR'.
  FIELDCATALOG-COL_POS     = 5.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'CPUDT'.
  FIELDCATALOG-SELTEXT_M   = 'CPUDT'.
  FIELDCATALOG-COL_POS     = 6.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'BUDAT'.
  FIELDCATALOG-SELTEXT_M   = 'BUDAT'.
  FIELDCATALOG-COL_POS     = 7.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'USNAM'.
  FIELDCATALOG-SELTEXT_M   = 'BUDAT'.
  FIELDCATALOG-COL_POS     = 8.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'MENGE'.
  FIELDCATALOG-SELTEXT_M   = 'MENGE'.
  FIELDCATALOG-COL_POS     = 9.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

  FIELDCATALOG-FIELDNAME   = 'DMBTR'.
  FIELDCATALOG-SELTEXT_M   = 'DMBTR'.
  FIELDCATALOG-COL_POS     = 10.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.

*&---------------------------------------------------------------------*
*          SORT
*&---------------------------------------------------------------------*
  WA_SORT-SPOS = 1.
  WA_SORT-FIELDNAME = 'BUKRS'.
  WA_SORT-TABNAME = 'ITAB'.
  WA_SORT-UP = 'X'.
  WA_SORT-SUBTOT = 'X'.
  APPEND WA_SORT TO IT_SORT.
  CLEAR WA_SORT.
  
  WA_SORT-SPOS = 2.
  WA_SORT-FIELDNAME = 'LIFNR'.
  WA_SORT-TABNAME = 'ITAB'.
  WA_SORT-UP = 'X'.
  WA_SORT-SUBTOT = 'X'.
  APPEND WA_SORT TO IT_SORT.
  CLEAR WA_SORT.

in the alv i want to know the number of rows for each value of lifnr (sub-total) and in the end the total of the all values of lifnr

thanks