Skip to Content

why in my ALV report subtotal_text event not working?

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Aug 03, 2020 at 10:05 AM

    Shortest demo code (runs in 7.51):

    TYPES: BEGIN OF alv_line,
             carrid TYPE sflight-carrid,
             connid TYPE sflight-connid,
             text   TYPE scarr-carrname,
             text_2 TYPE string,
             price  TYPE sflight-price,
           END OF alv_line.
    DATA: it_output_all TYPE STANDARD TABLE OF alv_line.
    
    FORM subtotal_text CHANGING
                   p_total TYPE any
                   p_subtot_text TYPE slis_subtot_text.
      CASE p_subtot_text-criteria.
        WHEN 'CARRID'.
          p_subtot_text-display_text_for_subtotal = 'Carrier total'.
        WHEN 'CONNID'.
          p_subtot_text-display_text_for_subtotal = |{ p_subtot_text-display_text_for_subtotal } total|.
      ENDCASE.
    ENDFORM.
    
    START-OF-SELECTION.
      DATA(gt_events) = VALUE slis_t_event( ( name = 'SUBTOTAL_TEXT' form = 'SUBTOTAL_TEXT' ) ).
      DATA(gt_fieldcat) = VALUE slis_t_fieldcat_alv(
          ( fieldname = 'CARRID' seltext_l = 'CARRID NO'  no_out = 'X' )
          ( fieldname = 'CONNID' seltext_l = 'CONNID'     no_out = 'X' )
          ( fieldname = 'TEXT'   seltext_l = 'CARRID Name' )
          ( fieldname = 'TEXT_2' seltext_l = 'Conn. #' )
          ( fieldname = 'PRICE'  seltext_l = 'Price'      do_sum = 'X' ) ).
      DATA(i_sort) = VALUE slis_t_sortinfo_alv(
          ( spos = 1 fieldname = 'CARRID' up = 'X' subtot = 'X' )
          ( spos = 2 fieldname = 'CONNID' up = 'X' subtot = 'X' ) ).
      SELECT scarr~carrid AS carrid,
             sflight~connid AS connid,
             scarr~carrname AS text,
             concat_with_space( 'Connection' , sflight~connid , 1 ) AS text_2,
             sflight~price AS price
        FROM sflight INNER JOIN scarr ON scarr~carrid = sflight~carrid
        INTO CORRESPONDING FIELDS OF TABLE @it_output_all.
      SORT it_output_all BY carrid connid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = sy-repid
          it_fieldcat        = gt_fieldcat
          it_events          = gt_events
          it_sort            = i_sort
          i_save             = 'A'
        TABLES
          t_outtab           = it_output_all
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.