Skip to Content
0
Former Member
Mar 11, 2009 at 07:47 AM

Using subtotal_text in ALV List

37 Views

I need to display 2 subtotals, one by SPART another one by VKORG. But it seems that both subtotals are overlapped. Another problem is, the display_text_for_subtotal is not shown. Following is part of my code:

FORM build_sortcat .
  gwa_sortcat-spos      = 1.
  gwa_sortcat-fieldname = 'SPART'.
  gwa_sortcat-tabname = 'gt_final'.
  gwa_sortcat-subtot = 'X'.
*  gwa_sortcat-up = 'X'.
  APPEND gwa_sortcat TO gt_sortcat.
  CLEAR gwa_sortcat.

  gwa_sortcat-spos      = 2.
  gwa_sortcat-fieldname = 'FKDAT'.
  gwa_sortcat-tabname = 'gt_final'.
  APPEND gwa_sortcat TO gt_sortcat.
  CLEAR gwa_sortcat.

  gwa_sortcat-spos      = 3.
  gwa_sortcat-fieldname = 'VBELN'.
  gwa_sortcat-tabname = 'gt_final'.
  APPEND gwa_sortcat TO gt_sortcat.
  CLEAR gwa_sortcat.

  gwa_sortcat-spos      = 4.
  gwa_sortcat-fieldname = 'VKORG'.
  gwa_sortcat-tabname = 'gt_final'.
  gwa_sortcat-subtot = 'X'.
  APPEND gwa_sortcat TO gt_sortcat.
  CLEAR gwa_sortcat.

ENDFORM.  

FORM alv_display .
  freport = sy-repid.
  PERFORM f_build_fieldcat.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
     i_callback_program             = freport
     IS_LAYOUT                      = gwa_layout
*    IS_VARIANT                     = WA_ALV_VARIANT
     it_fieldcat                    = gt_fieldcat[]
*     i_default                      = 'X'
     i_save                         = 'A'
     IT_EVENTS                      = GT_EVENTS[]
     it_sort                        = gt_sortcat[]
    TABLES
      t_outtab                       = gt_final[]
   EXCEPTIONS
     program_error                  = 1
     OTHERS                         = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.

FORM f_build_fieldcat.
  PERFORM f_fieldcat USING:
   'GT_FINAL'  'VBELN'  text-005  ' '  ' '  ' '  ' '  ' '  '010'  ' ',
   'GT_FINAL'  'AUBEL'  text-006  ' '  ' '  ' '  ' '  ' '  '010'  ' ',
   'GT_FINAL'  'FKDAT'  text-007  ' '  ' '  ' '  ' '  ' '  '012'  ' ',
   'GT_FINAL'  'KUNRG'  text-008  ' '  ' '  ' '  ' '  ' '  '016'  ' ',
   'GT_FINAL'  'NAME1'  text-009  ' '  ' '  ' '  ' '  ' '  '035'  ' ',
   'GT_FINAL'  'PERNR'  text-010  ' '  ' '  ' '  ' '  ' '  '008'  ' ',
   'GT_FINAL'  'LGORT'  text-011  ' '  ' '  ' '  ' '  ' '  '010'  ' ',
   'GT_FINAL'  'NETWR'  text-012  ' '  ' '  ' '  ' '  ' '  '013'  ' ',
   'GT_FINAL'  'KZWI4'  text-013  ' '  ' '  ' '  ' '  ' '  '016'  ' ',
   'GT_FINAL'  'MWSBK'  text-014  ' '  ' '  ' '  ' '  ' '  '013'  ' ',
   'GT_FINAL'  'TOTAL'  text-015  ' '  ' '  ' '  ' '  ' '  '013'  ' '.
ENDFORM. 

FORM f_fieldcat  USING  pv_a TYPE any
                        pv_b TYPE any
                        pv_c TYPE any
                        pv_d TYPE any
                        pv_e TYPE any
                        pv_f TYPE any
                        pv_g TYPE any
                        pv_h TYPE any
                        pv_i TYPE any
                        pv_j TYPE any.
  gwa_fieldcat-tabname      = pv_a.
  gwa_fieldcat-fieldname    = pv_b.
  gwa_fieldcat-reptext_ddic = pv_c.
  gwa_fieldcat-key          = pv_d.
  gwa_fieldcat-no_zero      = pv_e.
  gwa_fieldcat-decimals_out = pv_f.
  gwa_fieldcat-do_sum       = pv_g.
  gwa_fieldcat-no_out       = pv_h.
  gwa_fieldcat-outputlen    = pv_i.
  gwa_fieldcat-hotspot      = pv_j.

    IF pv_b = 'NETWR'.
      gwa_fieldcat-do_sum  = 'X'.
    ENDIF.
    IF pv_b = 'KZWI4'.
      gwa_fieldcat-do_sum = 'X'.
    ENDIF.
    IF pv_b = 'MWSBK'.
      gwa_fieldcat-do_sum  = 'X'.
    ENDIF.
    IF pv_b = 'TOTAL'.
      gwa_fieldcat-do_sum  = 'X'.
    ENDIF.

  APPEND gwa_fieldcat TO gt_fieldcat.
  CLEAR gwa_fieldcat.
ENDFORM.

FORM build_events .

CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE 'SUBTOTAL_TEXT'.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = gt_events[].

* for printing header using TOP_OF_LIST
  READ TABLE gt_events WITH KEY name = slis_ev_top_of_list
               INTO gwa_events.
  IF sy-subrc = 0.
    MOVE 'TOP_OF_LIST' TO gwa_events-form.
    MOVE 'TOP_OF_LIST' TO gwa_events-name.
    APPEND gwa_events TO gt_events.
    CLEAR gwa_events.

  ENDIF.

  READ TABLE GT_EVENTS WITH KEY name = slis_ev_subtotal_text
               INTO gwa_events.
  IF sy-subrc = 0.
    MOVE c_formname_subtotal_text TO gwa_events-form.
    MODIFY gt_events FROM gwa_events INDEX sy-tabix.
  ENDIF.

ENDFORM.      

FORM subtotal_text CHANGING
               p_total TYPE any
               p_subtot_text TYPE slis_subtot_text.

* Department level sub total
  IF p_subtot_text-criteria = 'SPART'.
    p_subtot_text-display_text_for_subtotal = 'Print department here'.
  ENDIF.

* Sale Org level sub total
  IF p_subtot_text-criteria = 'VKORG'.
    p_subtot_text-display_text_for_subtotal = 'Print sale org here'.
  ENDIF.

ENDFORM.


Edited by: big mug on Mar 11, 2009 8:49 AM