Skip to Content
0
Jul 31, 2020 at 06:28 AM

why in my ALV report subtotal_text event not working?

75 Views

I'm using below code to display an ALV and subtotal

DATA: BEGIN OF IT_OUTPUT_ALL OCCURS 0,
        ACCT    TYPE FAGLFLEXT-rAcct,
        ANAM    TYPE SKAT-txt20,
        ITEM    TYPE ZTFI03-zfiitem ,                                
        SITEM   TYPE ZTFI03-zfisuit,
        TEXT    TYPE ZTFI03-ZFITEXT ,                               
        ZFISIGN TYPE ZTFI03-ZFISIGN ,                               
        HSL_ALL   TYPE FAGLFLEXT-HSL01.
DATA: GT_EVENTS TYPE SLIS_T_EVENT, 
      LS_EVENT  TYPE LINE OF SLIS_T_EVENT. 
DATA: wa_sort TYPE slis_sortinfo_alv,
      i_sort TYPE  slis_t_sortinfo_alv.

FORM sub_populate_sort .
    wa_sort-spos = '01' .
    wa_sort-fieldname = 'ITEM'.
    wa_sort-up = 'X'.
    wa_sort-subtot = 'X'.
    APPEND wa_sort TO i_sort .
    CLEAR wa_sort.
ENDFORM.

FORM subtotal_text CHANGING
               p_total TYPE any
               p_subtot_text TYPE slis_subtot_text.
* Material level sub total
  IF p_subtot_text-criteria = 'ITEM'.
    p_subtot_text-display_text_for_subtotal
    = 'Material level total'.
  ENDIF.
ENDFORM. 

FORM FRM_SET_FIELDCAT.
  DATA: LV_FIELDNAME(7) TYPE C,
        LV_LTX(20)      TYPE C.
  FILLFIEDCAT 'ACCT'  ' Acct NO' '' ''.
  FILLFIEDCAT 'ANAM' ' Acct Name' '' ''.
  FILLFIEDCAT 'ITEM' ' ITEMS NO' '' ''.
  LS_FIELDCAT-FIELDNAME     = 'TEXT'.  
  LS_FIELDCAT-SELTEXT_L     = 'ITEM Name'.  
  LS_FIELDCAT-NO_ZERO       = ''. 
  LS_FIELDCAT-OUTPUTLEN     = ''.   
  LS_FIELDCAT-no_out   = 'X'.   
  APPEND LS_FIELDCAT TO GT_FIELDCAT.
  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-FIELDNAME     = 'HSL_ALL'.  
  LS_FIELDCAT-SELTEXT_L     = ' CURRENT YEAR CUMULATIVE'. 
  LS_FIELDCAT-NO_ZERO       = ''.  
  LS_FIELDCAT-OUTPUTLEN     = ''.    
  LS_FIELDCAT-do_sum    = 'X'.  
  APPEND LS_FIELDCAT TO GT_FIELDCAT.
  CLEAR LS_FIELDCAT.
ENDFORM. 

FORM DISPLAY_ALV.
  MOVE 'SUBTOTAL_TEXT' TO LS_EVENT-NAME.
  MOVE 'SUBTOTAL_TEXT' TO LS_EVENT-FORM.
  APPEND LS_EVENT TO GT_EVENTS.
   PERFORM FRM_SET_FIELDCAT.
  PERFORM sub_populate_sort.
  SORT IT_OUTPUT_ALL BY ITEM.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'  "statt LIST
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID
      I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
      I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
      IS_LAYOUT                = GS_LAYOUT
      IT_FIELDCAT              = GT_FIELDCAT
      IT_EVENTS                = GT_EVENTS
      IT_SORT                  = i_sort
      I_SAVE                   = 'A'  " Anzeigevarianten
    TABLES
      T_OUTTAB                 = IT_OUTPUT_ALL
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
ENDFORM.                      

The ALV has following fields: ACCT, ANAME,ITEM,TEXT,HSL_ALL. TEXT is the name of ITEM. I want to display the subtotal by ITEM and in the subtotal line display the TEXT of ITEM. So I wrote the above code, I still not get how to do it exactly so I still not modify the subtotal_text subform. But with above code when I debug it, it didn't go to this subtotal_text subForm at all. My question is: 1. To achieve this, do I need to use subtotal_text event? 2. what's wrong with my code? Thx.