Subtotal and Subtotal text in ALV REUSE_ALV_LIST_DISPLAY

Material       Mat. Descr                         Location Lot No.    Stock (Kg)
0512.5\      BLABLA Product 0512.5 test          A500     BL****         1,000
0512.5\      BLABLA Product 0512.5 test          A500     S*****           123
0512.5\      BLABLA Product 0512.5 test          C200     TU*****        2,000
106.10\      010101 Product 106.10               C200     BAR****NA        100
106.10\      010101 Product 106.10               C200     PA***            200
1067\        1234567890                          A001     TON**8       123,456
I am generating an ALV report using REUSE_ALV_LIST_DISPLAY. I need to compute the subtotal of the stock for each material. I tried doing this by building a sort but it does not work.
FORM build_sort .
  lwa_sort-fieldname = 'MATNR'.
  lwa_sort-spos = 1.
  lwa_sort-up = 'X'.
  lwa_sort-subtot = 'X'.
  APPEND lwa_sort TO gd_sort.
ENDFORM.                    " build_sort
Also I need to display the subtotal_text. Again this does not work either. The total text does show up.
FORM build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-window_titlebar   = sy-title.
  gd_layout-totals_text       = 'Total:'.
  gd_layout-subtotals_text    = 'Sum:'.
ENDFORM.                    " BUILD_LAYOUT
Can someone help me with the code. Thank you.

Megan,
Check this tread .I hope it might give you answer.
Subtotal in ALV report
Nirad Pachchigar

Similar Messages

  • My subtotal and total text in ALV list does not show...

    Hello Experts,
    Please see my code below on what I am doing wrong. I want to display the subtotal and total text in my ALV list.
    CLEAR gs_layout.
        gs_layout-colwidth_optimize = 'X'.
        gs_layout-zebra             = 'X'.
        gs_layout-subtotals_text    = 'Subtotal'.
        gs_layout-totals_text       = 'Total'.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
          EXPORTING
    *       I_INTERFACE_CHECK                 = ' '
    *       I_BYPASSING_BUFFER                = ' '
    *       I_BUFFER_ACTIVE                   = ' '
            i_callback_program                = sy-repid
    *       I_CALLBACK_PF_STATUS_SET          = ' '
    *       I_CALLBACK_USER_COMMAND           = ' '
    *       I_CALLBACK_TOP_OF_PAGE            = ' '
    *       I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    *       I_CALLBACK_HTML_END_OF_LIST       = ' '
    *       I_STRUCTURE_NAME                  =
    *       I_BACKGROUND_ID                   = ' '
    *       I_GRID_TITLE                      =
    *       I_GRID_SETTINGS                   =
            is_layout                         = gs_layout
            it_fieldcat                       = gt_fieldcat
    *       IT_EXCLUDING                      =
    *       IT_SPECIAL_GROUPS                 =
            it_sort                           = gt_sort
    *       IT_FILTER                         =
    *       IS_SEL_HIDE                       =
    *       I_DEFAULT                         = 'X'
    *       I_SAVE                            = ' '
    *       IS_VARIANT                        =
            it_events                         = gt_events
    *       IT_EVENT_EXIT                     =
            is_print                          = gs_print
    *       IS_REPREP_ID                      =
    *       I_SCREEN_START_COLUMN             = 0
    *       I_SCREEN_START_LINE               = 0
    *       I_SCREEN_END_COLUMN               = 0
    *       I_SCREEN_END_LINE                 = 0
    *       I_HTML_HEIGHT_TOP                 = 0
    *       I_HTML_HEIGHT_END                 = 0
    *       IT_ALV_GRAPHICS                   =
    *       IT_HYPERLINK                      =
    *       IT_ADD_FIELDCAT                   =
    *       IT_EXCEPT_QINFO                   =
    *       IR_SALV_FULLSCREEN_ADAPTER        =
    *     IMPORTING
    *       E_EXIT_CAUSED_BY_CALLER           =
    *       ES_EXIT_CAUSED_BY_USER            =
          TABLES
            t_outtab                          = lt_output_fin
         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.

    Use on Thread. Don't Cross post. and Follow the Rules.

  • Need to display Subtotal text and total text in ALV

    HI,
    I need help.
    I am displaying subtotal and total for cost column which is group by Project type column
    My problem is i am able to display the subtotal and total values but not able to display the 'Subtotal' and 'Total' text on that respective row.
    I have updated lvc_s_sort table as follow.
    ls_sort-spos = 1.
      ls_sort-subtot = 'X'.
      ls_sort-fieldname = 'SUBTOT'.
      ls_sort-up = 'X'.
      ls_sort-SELTEXT = 'Subtotal'.
      ls_sort-spos = 2.
      ls_sort-subtot = 'X'.
      ls_sort-fieldname = 'PRART'.
      ls_sort-GROUP = 'UL'.
      ls_sort-up = 'X'.
    Please suggest what should be done to display the text.
    Regards,
    Rachna

    You have to use the event SUBTOTAL_TEXT for the ALV.
    the field CRITERIA can be used for checking the field.
    and field CRIT_TEXT for the sub total text.
    I hope you are aware about how to implement the events in ALV using OOP.
    Hope this helps you.

  • ALV Grid  Subtotal text and Total text display

    Hello ABAPGuru's
    I want to display the subtotal and Total texts. alv grid program runing on background.
    Regards
    Sweety(Sri)

    Hello Neil,
    Here I have attached my routines.anyway my confusion. I have wrote the routine subtotal_text .but i am not passing ALV GRID FM.
    *&      Form  eventtab_build
    &----       This is used to get the list of events
    ----      <--RI_EVENTS  Internal table
    FORM eventtab_build  CHANGING ri_events TYPE slis_t_event.
    Structure for event handling.
      DATA: rs_event TYPE slis_alv_event.
    Returns table of possible events for a list type.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = ri_events.  " Table of events to perform
    Read the internal table with the TOP_OF_PAGE and move the
    form name to the internal table
      READ TABLE ri_events
        WITH KEY name = slis_ev_top_of_page INTO rs_event.
      IF sy-subrc = 0.
        MOVE c_formname TO rs_event-form.              " Form name
        MODIFY ri_events FROM rs_event
           INDEX sy-tabix.                  " Top of page event
      ENDIF.
      READ TABLE ri_events
         WITH KEY name = slis_ev_end_of_page INTO rs_event.
      IF sy-subrc = 0.
        MOVE c_form_eop_name TO rs_event-form.              " Form name
        MODIFY ri_events FROM rs_event
           INDEX sy-tabix.                  " Top of page event
      ENDIF.
      READ TABLE ri_events
          WITH KEY name = slis_ev_subtotal_text INTO rs_event.
      IF sy-subrc = 0.
        MOVE c_formname_subtotal_text TO rs_event-form.     " Formname
        MODIFY ri_events FROM rs_event
           INDEX sy-tabix.                  " Top of page event
      ENDIF.
    *&-- Delete all unneeded events:
    DELETE ri_events  WHERE form IS INITIAL.
    ENDFORM.                    " eventtab_build
    *&      Form  SUBTOTAL_TEXT
          text
    -->  p1        text
    <--  p2        text
    FORM SUBTOTAL_TEXT USING  ep_subtot_line     TYPE  type_data
                              e_event_data       TYPE  slis_subtot_text.
      IF NOT e_event_data-criteria IS INITIAL.
      E_EVENT_DATA-DISPLAY_TEXT_FOR_SUBTOTAL = 'Account Total'.
       ENDIF.
    ENDFORM.                    "SUBTOTAL_TEXT
    *&      Form  initialise_layout
          Initialise Layout
    FORM initialise_layout .
      i_layout-colwidth_optimize = c_x.
      i_layout-group_change_edit = c_x.
    *i_layout-subtotals_text = ' a'.
      i_layout-detail_popup   = c_x.
    i_layout-zebra          = c_x.
      i_layout-no_vline       = 'X'.
      i_layout-no_hline       = 'X'.
      i_layout-totals_text = 'Account Total'.
    ENDFORM.                    " initialise_layout
    Call the function module to display the report
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program     = v_program
          i_callback_top_of_page = 'TOP_OF_PAGE'       "Top Of Page
          is_layout              = i_layout
          it_fieldcat            = i_fieldtab
          it_sort                = i_sort
          it_events              = i_events         " Events
          is_print               = i_print
          i_default              = c_x
          i_save                 = c_save
          is_variant             = v_variant
        TABLES
          t_outtab               = i_data
        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.
    Regards
    Sweety (Sri)

  • Subtotal Text in ALV

    Hi all,
    I wanted to display subtotal and total text in the output.
    I searched in SDN and specified subtotal_text in Layout.
    But still i am not getting the subtotal Text in  output.
    Here is my code.....
    Please help me , where i did wrong?
    REPORT  YTEST_ALV.
    Tables VBAK.
    Type-pools: slis.
    INITIALIZATION.
    Types: Begin of TY_VBAK,
             vbeln type vbak-vbeln,
             ERDAT TYPE VBAK-ERDAT,
             ERNAM TYPE VBAK-ERNAM,
             NETWR TYPE VBAK-NETWR,
             WAERK TYPE VBAK-WAERK,
             VKORG TYPE VBAK-VKORG,
           End Of TY_VBAK.
    DATA: IT_VBAK TYPE STANDARD TABLE OF TY_VBAK,
          IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
          WA_FLDCAT LIKE LINE OF IT_FLDCAT,
          GD_LAYOUT TYPE STANDARD TABLE OF SLIS_LAYOUT_ALV WITH HEADER LINE,
    *TO DISPLAY THE LIST BY SORTING A PARTICULAR COLUMN
          it_sortcat   type slis_sortinfo_alv occurs 1,
          wa_sort like line of it_sortcat.
    START-OF-SELECTION.
    SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN.
    PERFORM DATA_RETRIEVAL.
    PERFORM BUILD_FLDCAT.
    PERFORM BLD_LAYOUT.
    PERFORM BUILD_SORTCAT.
    PERFORM DISPLAY_LIST.
    PERFORM TOP_OF_PAGE.
    *&      Form  DATA_RETRIEVAL
          text
    -->  p1        text
    <--  p2        text
    form DATA_RETRIEVAL .
    SELECT vbeln
           ERDAT
           ERNAM
           NETWR
           WAERK
           VKORG
           FROM VBAK INTO TABLE IT_VBAK WHERE VBELN IN S_VBELN.
    endform.                    " DATA_RETRIEVAL
    *&      Form  BUILD_FLDCAT
          text
    -->  p1        text
    <--  p2        text
    form BUILD_FLDCAT .
    WA_FLDCAT-FIELDNAME = 'VBELN'.
    WA_FLDCAT-SELTEXT_L = 'Sales Order No'.
    *WA_FLDCAT-EMPHASIZE = 'C013'.
    WA_FLDCAT-COL_POS = 0.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'ERDAT'.
    WA_FLDCAT-SELTEXT_L = 'Date'.
    WA_FLDCAT-COL_POS = 1.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'ERNAM'.
    WA_FLDCAT-SELTEXT_L = 'UserName'.
    WA_FLDCAT-COL_POS = 2.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'NETWR'.
    WA_FLDCAT-SELTEXT_L = 'Amount'.
    WA_FLDCAT-COL_POS = 3.
    WA_FLDCAT-DO_SUM = 'X'.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'WAERK'.
    WA_FLDCAT-SELTEXT_L = 'Currency'.
    WA_FLDCAT-COL_POS = 4.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    WA_FLDCAT-FIELDNAME = 'VKORG'.
    WA_FLDCAT-SELTEXT_L = 'Sales Organisation'.
    WA_FLDCAT-COL_POS = 5.
    APPEND WA_FLDCAT TO IT_FLDCAT.
    endform.                    " BUILD_FLDCAT
    FORM BLD_LAYOUT.
    GD_LAYOUT-NO_INPUT = 'X'.
    GD_LAYOUT-TOTALS_TEXT = 'Total'.
    GD_LAYOUT-subtotals_text = 'SubTotal'.
    APPEND GD_LAYOUT.
    ENDFORM.
    *&      Form  DISPLAY_LIST
          text
    -->  p1        text
    <--  p2        text
    form DISPLAY_LIST .
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
       I_CALLBACK_PROGRAM                = SY-REPID
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
       I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
       IS_LAYOUT                         = GD_LAYOUT
       IT_FIELDCAT                        = IT_FLDCAT
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
       IT_SORT                           = it_sortcat
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
       I_SAVE                            = 'X'
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        t_outtab                          = IT_VBAK.
    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.                    " DISPLAY_LIST
    *&      Form  TOP_OF_PAGE
          text
    -->  p1        text
    <--  p2        text
    form TOP_OF_PAGE .
    DATA: IT_HEADER TYPE SLIS_T_LISTHEADER,
          WA_HEADER TYPE SLIS_LISTHEADER.
          WA_HEADER-TYP = 'H'.
          WA_HEADER-INFO = 'WELCOME HEADER'.
          APPEND WA_HEADER TO IT_HEADER.
          WA_HEADER-TYP = 'S'.
          WA_HEADER-KEY = 'REPORT'.
          WA_HEADER-INFO = SY-REPID.
          APPEND WA_HEADER TO IT_HEADER.
          WA_HEADER-TYP = 'S'.
          WA_HEADER-KEY = 'DATE'.
          CONCATENATE SY-DATUM6(2) '/'  SY-DATUM4(2) '/' SY-DATUM+0(4)       inTO WA_HEADER-INFO.
         WA_HEADER-INFO = SY-DATUM.
          APPEND WA_HEADER TO IT_HEADER.
          CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
            EXPORTING
              it_list_commentary       = IT_HEADER.
            I_LOGO                   =
            I_END_OF_LIST_GRID       =
            I_ALV_FORM               =
    endform.                    " TOP_OF_PAGE
    *TO DISPLAY THE LIST BY SORTING A PARTICULAR COLUMN
    *&      Form  BUILD_SORTCAT
          text
    -->  p1        text
    <--  p2        text
    form BUILD_SORTCAT .
      wa_sort-spos      = 1.
      wa_sort-fieldname = 'ERDAT'.
      wa_sort-SUBTOT    = 'X'. "subtotals any totals column by this field
      APPEND wa_sort TO it_sortcat.
    endform.                    " BUILD_SORTCAT

    Hi Elan,
    *& Report  Z_ALV_SUBTOTAL
    REPORT z_alv_subtotal.
    *& Table declaration
    TABLES: ekko.
    *& Type pool declaration
    TYPE-POOLS: slis. " Type pool for ALV
    *& Selection screen
    SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
    *& Type declaration
    * Type declaration for internal table to store EKPO data
    TYPES: BEGIN OF x_data,
           ebeln  TYPE char30,  " Document no.
           ebelp  TYPE ebelp,   " Item no
           matnr  TYPE matnr,   " Material no
           matnr1 TYPE matnr,   " Material no
           werks  TYPE werks_d, " Plant
           werks1 TYPE werks_d, " Plant
           ntgew  TYPE entge,   " Net weight
           gewe   TYPE egewe,   " Unit of weight                          
           END OF x_data.
    *& Internal table declaration
    DATA:
    * Internal table to store EKPO data
      i_ekpo TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
    * Internal table for storing field catalog information
      i_fieldcat TYPE slis_t_fieldcat_alv,
    * Internal table for Top of Page info. in ALV Display
      i_alv_top_of_page TYPE slis_t_listheader,
    * Internal table for ALV Display events
      i_events TYPE slis_t_event,
    * Internal table for storing ALV sort information
      i_sort TYPE  slis_t_sortinfo_alv,
      i_event TYPE slis_t_event.
    *& Work area declaration
    DATA:
      wa_ekko TYPE x_data,
      wa_layout     TYPE slis_layout_alv,
      wa_events         TYPE slis_alv_event,
      wa_sort TYPE slis_sortinfo_alv.
    *& Constant declaration
    CONSTANTS:
       c_header   TYPE char1
                  VALUE 'H',                    "Header in ALV
       c_item     TYPE char1
                  VALUE 'S'.
    *& Start-of-selection event
    START-OF-SELECTION.
    * Select data from ekpo
      SELECT ebeln " Doc no
             ebelp " Item
             matnr " Material
             matnr " Material
             werks " Plant
             werks " Plant
             ntgew " Quantity
             gewei " Unit
             FROM ekpo
             INTO TABLE i_ekpo
             WHERE ebeln IN s_ebeln
             AND ntgew NE '0.00'.
      IF sy-subrc = 0.
        SORT i_ekpo BY ebeln ebelp matnr .
      ENDIF.
    * To build the Page header
      PERFORM sub_build_header.
    * To prepare field catalog
      PERFORM sub_field_catalog.
    * Perform to populate the layout structure
      PERFORM sub_populate_layout.
    * Perform to populate the sort table.
      PERFORM sub_populate_sort.
    * Perform to populate ALV event
      PERFORM sub_get_event.
    END-OF-SELECTION.
    * Perform to display ALV report
      PERFORM sub_alv_report_display.
    *&      Form  sub_build_header
    *       To build the header
    *       No Parameter
    FORM sub_build_header .
    * Local data declaration
      DATA: l_system     TYPE char10 ,          "System id
            l_r_line     TYPE slis_listheader,  "Hold list header
            l_date       TYPE char10,           "Date
            l_time       TYPE char10,           "Time
            l_success_records TYPE i,           "No of success records
            l_title(300) TYPE c.                " Title
    * Title  Display
      l_r_line-typ = c_header.               " header
      l_title = 'Test report'(001).
      l_r_line-info = l_title.
      APPEND l_r_line TO i_alv_top_of_page.
      CLEAR l_r_line.
    * Run date Display
      CLEAR l_date.
      l_r_line-typ  = c_item.                " Item
      WRITE: sy-datum  TO l_date MM/DD/YYYY.
      l_r_line-key = 'Run Date :'(002).
      l_r_line-info = l_date.
      APPEND l_r_line TO i_alv_top_of_page.
      CLEAR: l_r_line,
             l_date.
    ENDFORM.                    " sub_build_header
    *&      Form  sub_field_catalog
    *       Build Field Catalog
    *       No Parameter
    FORM sub_field_catalog .
    *  Build Field Catalog
      PERFORM sub_fill_alv_field_catalog USING:
         '01' '01' 'EBELN' 'I_EKPO' 'L'
         'Doc No'(003) ' ' ' ' ' ' ' ',
         '01' '02' 'EBELP' 'I_EKPO' 'L'
         'Item No'(004) 'X' 'X' ' ' ' ',
         '01' '03' 'MATNR' 'I_EKPO' 'L'
         'Material No'(005) 'X' 'X' ' ' ' ',
         '01' '03' 'MATNR1' 'I_EKPO' 'L'
         'Material No'(005) ' ' ' ' ' ' ' ',
         '01' '04' 'WERKS' 'I_EKPO' 'L'
         'Plant'(006) 'X' 'X' ' ' ' ',
         '01' '04' 'WERKS1' 'I_EKPO' 'L'
         'Plant'(006) ' ' ' ' ' ' ' ',
         '01' '05' 'NTGEW' 'I_EKPO' 'R'
         'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'.
    ENDFORM.                    " sub_field_catalog
    *&     Form  sub_fill_alv_field_catalog
    *&     For building Field Catalog
    *&     p_rowpos   Row position
    *&     p_colpos   Col position
    *&     p_fldnam   Fldname
    *&     p_tabnam   Tabname
    *&     p_justif   Justification
    *&     p_seltext  Seltext
    *&     p_out      no out
    *&     p_tech     Technical field
    *&     p_qfield   Quantity field
    *&     p_qtab     Quantity table
    FORM sub_fill_alv_field_catalog  USING  p_rowpos    TYPE sycurow
                                            p_colpos    TYPE sycucol
                                            p_fldnam    TYPE fieldname
                                            p_tabnam    TYPE tabname
                                            p_justif    TYPE char1
                                            p_seltext   TYPE dd03p-scrtext_l
                                            p_out       TYPE char1
                                            p_tech      TYPE char1
                                            p_qfield    TYPE slis_fieldname
                                            p_qtab      TYPE slis_tabname.
    * Local declaration for field catalog
      DATA: wa_lfl_fcat    TYPE  slis_fieldcat_alv.
      wa_lfl_fcat-row_pos        =  p_rowpos.     "Row
      wa_lfl_fcat-col_pos        =  p_colpos.     "Column
      wa_lfl_fcat-fieldname      =  p_fldnam.     "Field Name
      wa_lfl_fcat-tabname        =  p_tabnam.     "Internal Table Name
      wa_lfl_fcat-just           =  p_justif.     "Screen Justified
      wa_lfl_fcat-seltext_l      =  p_seltext.    "Field Text
      wa_lfl_fcat-no_out         =  p_out.        "No output
      wa_lfl_fcat-tech           =  p_tech.       "Technical field
      wa_lfl_fcat-qfieldname     =  p_qfield.     "Quantity unit
      wa_lfl_fcat-qtabname       =  p_qtab .      "Quantity table
      IF p_fldnam = 'NTGEW'.
        wa_lfl_fcat-do_sum  = 'X'.
      ENDIF.
      APPEND wa_lfl_fcat TO i_fieldcat.
      CLEAR wa_lfl_fcat.
    ENDFORM.                    " sub_fill_alv_field_catalog
    *&      Form  sub_populate_layout
    *       Populate ALV layout
    *       No Parameter
    FORM sub_populate_layout .
      CLEAR wa_layout.
      wa_layout-colwidth_optimize = 'X'." Optimization of Col width
    ENDFORM.                    " sub_populate_layout
    *&      Form  sub_populate_sort
    *       Populate ALV sort table
    *       No Parameter
    FORM sub_populate_sort .
    * Sort on material
      wa_sort-spos = '01' .
      wa_sort-fieldname = 'MATNR'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.
    * Sort on plant
      wa_sort-spos = '02'.
      wa_sort-fieldname = 'WERKS'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.
    ENDFORM.                    " sub_populate_sort
    *&      Form  sub_get_event
    *       Get ALV grid event and pass the form name to subtotal_text
    *       event
    *       No Parameter
    FORM sub_get_event .
      CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE
    'SUBTOTAL_TEXT'.
      DATA: l_s_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 4
        IMPORTING
          et_events       = i_event
        EXCEPTIONS
          list_type_wrong = 0
          OTHERS          = 0.
    * Subtotal
      READ TABLE i_event  INTO l_s_event
                        WITH KEY name = slis_ev_subtotal_text.
      IF sy-subrc = 0.
        MOVE c_formname_subtotal_text TO l_s_event-form.
        MODIFY i_event FROM l_s_event INDEX sy-tabix.
      ENDIF.
    ENDFORM.                    " sub_get_event
    *&      Form  sub_alv_report_display
    *       For ALV Report Display
    *       No Parameter
    FORM sub_alv_report_display .
      DATA: l_repid TYPE syrepid .
      l_repid = sy-repid .
    * This function module for displaying the ALV report
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = l_repid
          i_callback_top_of_page   = 'SUB_ALV_TOP_OF_PAGE'
          is_layout                = wa_layout
          it_fieldcat              = i_fieldcat
          it_sort = i_sort
          it_events                = i_event
          i_default                = 'X'
          i_save                   = 'A'
        TABLES
          t_outtab                 = i_ekpo
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
    *    MESSAGE i000 WITH 'Error in ALV report display'(055).
      ENDIF.
    ENDFORM.                    " sub_alv_report_display
    *       FORM sub_alv_top_of_page
    *       Call ALV top of page
    *       No parameter
    FORM sub_alv_top_of_page.                                   "#EC CALLED
    * To write header for the ALV
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = i_alv_top_of_page.
    ENDFORM.                    "alv_top_of_page
    *&      Form  subtotal_text
    *       Build subtotal text
    *       P_total  Total
    *       p_subtot_text Subtotal text info
    FORM subtotal_text CHANGING
                   p_total TYPE any
                   p_subtot_text TYPE slis_subtot_text.
    * Material level sub total
      IF p_subtot_text-criteria = 'MATNR'.
        p_subtot_text-display_text_for_subtotal
        = 'Material level total'(009).
      ENDIF.
    * Plant level sub total
      IF p_subtot_text-criteria = 'WERKS'.
        p_subtot_text-display_text_for_subtotal = 'Plant level total'(010).
      ENDIF.
    ENDFORM.                    "subtotal_text
    If found helpfull do reward.
    Regards.
    Eshwar.

  • How to do subtotal and grand total as per currency in a tree ALV

    Hi Experts,
    I am doing a tree ALV for SD output. I met an urgent problem that is how to do subtotal and grand total on the field (netwr) as per currency (waerk) in the tree ALV. I am using below codes to create the tree ALV.
        l_tree_container_name = 'CCONTAINER1'.
        CREATE OBJECT objCustomContainer
            EXPORTING
                  container_name = l_tree_container_name
            EXCEPTIONS
                  cntl_error                  = 1
                  cntl_system_error      = 2
                  create_error               = 3
                  lifetime_error              = 4
                  lifetime_dynpro_dynpro_link = 5.
    create tree control
        CREATE OBJECT objTree1
          EXPORTING
              parent              = objCustomContainer
              node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
              item_selection      = ' '
              no_html_header      = 'X'
              no_toolbar          = ''
          EXCEPTIONS
              cntl_error                   = 1
              cntl_system_error       = 2
              create_error                = 3
              lifetime_error               = 4
              illegal_node_selection_mode  = 5
              failed                       = 6
              illegal_column_name          = 7.
        DATA l_hierarchy_header TYPE treev_hhdr.
        call method buildHierarchyHeader
          IMPORTING
            p_hierarchy_header = l_hierarchy_header.
    Build fieldcatalog
        call method buildFieldcatalog.
        CALL METHOD objTree1->set_table_for_first_display
            EXPORTING
              is_hierarchy_header = l_hierarchy_header
            CHANGING
              it_fieldcatalog     = l_fieldcatalog
              it_outtab            = lt_order.             
        CALL METHOD objTree1->update_calculations.
        CALL METHOD objTree1->frontend_update.
    filling fieldcatalog,
          LS_FIELDCATALOG-FIELDNAME = 'NETWR'.
          LS_FIELDCATALOG-SCRTEXT_S = 'Net Value'.
          LS_FIELDCATALOG-COL_POS = l_pos.
          LS_FIELDCATALOG-OUTPUTLEN = 15.
          LS_fieldcatalog-do_dum= 'X'.
          LS_FIELDCATALOG-DATATYPE = 'CURR'.
          APPEND LS_FIELDCATALOG TO l_FIELDCATALOG.
          CLEAR LS_FIELDCATALOG.
          l_pos = l_pos + 1.
    I could see the subtotal and grandtotal in tree ALV but they are simply sumed up  regardless different currency.
    Thank you very much for your kindly helps.
    Yu

    hi
    good
    go through this report and work accordingly.
    REPORT ZALV.
    TYPE-POOLS: SLIS.
    DATA: G_REPID LIKE SY-REPID,
    GS_PRINT            TYPE SLIS_PRINT_ALV,
    GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
    GT_EVENTS           TYPE SLIS_T_EVENT,
    GT_SORT             TYPE SLIS_T_SORTINFO_ALV,
    GS_LAYOUT           TYPE SLIS_LAYOUT_ALV,
    GT_FIELDCAT         TYPE SLIS_T_FIELDCAT_ALV,
    FIELDCAT_LN LIKE LINE OF GT_FIELDCAT,
    COL_POS TYPE I.
    DATA: BEGIN OF ITAB,
      FIELD1(5) TYPE C,
      FIELD2(5) TYPE C,
      FIELD3(5) TYPE P DECIMALS 2,
    END OF ITAB.
    DATA: BEGIN OF ITAB1 OCCURS 0.
      INCLUDE STRUCTURE ITAB.
    DATA: END OF ITAB1.
    DATA: BEGIN OF ITAB_FIELDCAT OCCURS 0.
      INCLUDE STRUCTURE ITAB.
    DATA: END OF ITAB_FIELDCAT.
    Print Parameters
    PARAMETERS:
                P_PRINT  AS CHECKBOX DEFAULT ' ', "PRINT IMMEDIATE
                P_NOSINF AS CHECKBOX DEFAULT 'X', "NO SELECTION INFO
                P_NOCOVE AS CHECKBOX DEFAULT ' ', "NO COVER PAGE
                P_NONEWP AS CHECKBOX DEFAULT ' ', "NO NEW PAGE
                P_NOLINF AS CHECKBOX DEFAULT 'X', "NO PRINT LIST INFO
                P_RESERV TYPE I.                  "NO OF FOOTER LINE
    INITIALIZATION.
    G_REPID = SY-REPID.
    PERFORM PRINT_BUILD    USING GS_PRINT.      "Print PARAMETERS
    START-OF-SELECTION.
    TEST DATA
    MOVE 'TEST1' TO ITAB1-FIELD1.
    MOVE 'TEST1' TO ITAB1-FIELD2.
    MOVE '10.00' TO ITAB1-FIELD3.
    APPEND ITAB1.
    MOVE 'TEST2' TO ITAB1-FIELD1.
    MOVE 'TEST2' TO ITAB1-FIELD2.
    MOVE '20.00' TO ITAB1-FIELD3.
    APPEND ITAB1.
    DO 50 TIMES.
      APPEND ITAB1.
    ENDDO.
    END-OF-SELECTION.
    PERFORM BUILD.
    PERFORM EVENTTAB_BUILD CHANGING GT_EVENTS.
    PERFORM COMMENT_BUILD  CHANGING GT_LIST_TOP_OF_PAGE.
    PERFORM CALL_ALV.
    FORM BUILD.
    DATA FIELD CATALOG
    Explain Field Description to ALV
    DATA: FIELDCAT_IN TYPE SLIS_FIELDCAT_ALV.
    CLEAR FIELDCAT_IN.
    FIELDCAT_LN-FIELDNAME = 'FIELD1'.
    FIELDCAT_LN-TABNAME   = 'ITAB1'.
    *FIELDCAT_LN-NO_OUT    = 'X'.  "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT
    FIELDCAT_LN-KEY       = ' '.   "SUBTOTAL KEY
    FIELDCAT_LN-NO_OUT    = ' '.
    FIELDCAT_LN-SELTEXT_L = 'HEAD1'.
    APPEND FIELDCAT_LN TO GT_FIELDCAT.
    CLEAR FIELDCAT_IN.
    FIELDCAT_LN-FIELDNAME = 'FIELD2'.
    FIELDCAT_LN-TABNAME   = 'ITAB1'.
    FIELDCAT_LN-NO_OUT    = 'X'.
    FIELDCAT_LN-SELTEXT_L = 'HEAD2'.
    APPEND FIELDCAT_LN TO GT_FIELDCAT.
    CLEAR FIELDCAT_IN.
    FIELDCAT_LN-FIELDNAME     = 'FIELD3'.
    FIELDCAT_LN-TABNAME       = 'ITAB1'.
    FIELDCAT_LN-REF_FIELDNAME = 'MENGE'. "<- REF FIELD IN THE DICTIONNARY
    FIELDCAT_LN-REF_TABNAME   = 'MSEG'.  "<- REF TABLE IN THE DICTIONNARY
    FIELDCAT_LN-NO_OUT        = ' '.
    FIELDCAT_LN-DO_SUM        = 'X'.   "SUM UPON DISPLAY
    APPEND FIELDCAT_LN TO GT_FIELDCAT.
    DATA SORTING AND SUBTOTAL
    DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.
    CLEAR GS_SORT.
    GS_SORT-FIELDNAME = 'FIELD1'.
    GS_SORT-SPOS      = 1.
    GS_SORT-UP        = 'X'.
    GS_SORT-SUBTOT    = 'X'.
    APPEND GS_SORT TO GT_SORT.
    CLEAR GS_SORT.
    GS_SORT-FIELDNAME = 'FIELD2'.
    GS_SORT-SPOS      = 2.
    GS_SORT-UP        = 'X'.
    *GS_SORT-SUBTOT    = 'X'.
    APPEND GS_SORT TO GT_SORT.
    ENDFORM.
    FORM CALL_ALV.
    ABAP List Viewer
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER =
    I_BUFFER_ACTIVE = ' '
    I_CALLBACK_PROGRAM = G_REPID
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = ' '
    I_STRUCTURE_NAME = 'ITAB1'
    IS_LAYOUT =  GS_LAYOUT
    IT_FIELDCAT = GT_FIELDCAT[]
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
      IT_SORT = GT_SORT[]
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT =
      IT_EVENTS = GT_EVENTS[]
    IT_EVENT_EXIT =
      IS_PRINT = GS_PRINT
    IS_REPREP_ID =
    I_SCREEN_START_COLUMN = 0
    I_SCREEN_START_LINE = 0
    I_SCREEN_END_COLUMN = 0
    I_SCREEN_END_LINE = 0
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
    TABLES
    T_OUTTAB = ITAB1
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    ENDFORM.
    HEADER FORM
    FORM EVENTTAB_BUILD CHANGING LT_EVENTS TYPE SLIS_T_EVENT.
    CONSTANTS:
    GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.
    *GC_FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE 'END_OF_PAGE'.
      DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
           EXPORTING
                I_LIST_TYPE = 0
           IMPORTING
                ET_EVENTS   = LT_EVENTS.
      READ TABLE LT_EVENTS WITH KEY NAME =  SLIS_EV_TOP_OF_PAGE
                               INTO LS_EVENT.
      IF SY-SUBRC = 0.
        MOVE GC_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
        APPEND LS_EVENT TO LT_EVENTS.
      ENDIF.
    define END_OF_PAGE event
    READ TABLE LT_EVENTS WITH KEY NAME =  SLIS_EV_END_OF_PAGE
                             INTO LS_EVENT.
    IF SY-SUBRC = 0.
      MOVE GC_FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.
      APPEND LS_EVENT TO LT_EVENTS.
    ENDIF.
    ENDFORM.
    FORM COMMENT_BUILD CHANGING GT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
      DATA: GS_LINE TYPE SLIS_LISTHEADER.
      CLEAR GS_LINE.
      GS_LINE-TYP  = 'H'.
      GS_LINE-INFO = 'HEADER 1'.
      APPEND GS_LINE TO GT_TOP_OF_PAGE.
      CLEAR GS_LINE.
      GS_LINE-TYP  = 'S'.
      GS_LINE-KEY  = 'STATUS 1'.
      GS_LINE-INFO = 'INFO 1'.
      APPEND GS_LINE TO GT_TOP_OF_PAGE.
      GS_LINE-KEY  = 'STATUS 2'.
      GS_LINE-INFO = 'INFO 2'.
      APPEND GS_LINE TO GT_TOP_OF_PAGE.
    CLEAR GS_LINE.
    GS_LINE-TYP  = 'A'.
    GS_LINE-INFO = 'ACTION'.
    APPEND GS_LINE TO  GT_TOP_OF_PAGE.
    ENDFORM.
    FORM TOP_OF_PAGE.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
           EXPORTING
                IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
      WRITE: SY-DATUM, 'Page No', SY-PAGNO LEFT-JUSTIFIED.
    ENDFORM.
    FORM END_OF_PAGE.
      WRITE at (sy-linsz) sy-pagno CENTERED.
    ENDFORM.
    PRINT SETTINGS
    FORM PRINT_BUILD USING LS_PRINT TYPE SLIS_PRINT_ALV.
      LS_PRINT-PRINT              = P_PRINT.  "PRINT IMMEDIATE
      LS_PRINT-NO_PRINT_SELINFOS  = P_NOSINF. "NO SELECTION INFO
      LS_PRINT-NO_COVERPAGE       = P_NOCOVE. "NO COVER PAGE
      LS_PRINT-NO_NEW_PAGE        = P_NONEWP.
      LS_PRINT-NO_PRINT_LISTINFOS = P_NOLINF. "NO PRINT LIST INFO
      LS_PRINT-RESERVE_LINES      = P_RESERV.
    ENDFORM.
    thanks
    mrutyun^

  • Display Subtotal Text  in ALV

    Hi,
    I have done the subtotal and total operation in ALV report.
    I wanted to display the text like
    Subtotal: _______
    Total     : _______
    I tried to give the text in th layout like..
    GD_LAYOUT-TOTALS_TEXT = 'Total'.
    GD_LAYOUT-subtotals_text = 'SubTotal'.
    i passed this layout in REUSE_ALV_GRID_DISPLAY
    but i am not getting the text in the output. what is wrong?
    Can any one please tell me to place the text?
    Regards,
    Elanthendral.

    Hi,
    Check out the layout work area declaration and passing part. What u have mentioned should work. Try to debug and find it.
    Find below the sample code.
    DATA: wa_layout       TYPE slis_layout_alv, "Layout structure
    END-OF-SELECTION.
       PERFORM build_layout.
    FORM build_layout .
    wa_layout-ZEBRA = 'X'.
    wa_layout-NO_VLINE = 'X'.
    wa_layout-NO_HLINE = 'X'.
    wa_layout-CELL_MERGE = 'X'.
    wa_layout-EDIT = 'X'.
    wa_layout-WINDOW_TITLEBAR = ''.
    wa_layout-NO_ULINE_HS = 'X'.
    wa_layout-LIGHTS_FIELDNAME = ''.
    wa_layout-LIGHTS_TABNAME = ''.
    wa_layout-LIGHTS_ROLLNAME = ''.
    wa_layout-LIGHTS_CONDENSE = 'X'.
    wa_layout-NO_TOTALLINE = 'X'.
    wa_layout-NO_SUBTOTALS = 'X'.
    wa_layout-TOTALS_BEFORE_ITEMS = 'X'.
    wa_layout-TOTALS_ONLY = 'X'.
    wa_layout-TOTALS_TEXT = ''.
    wa_layout-SUBTOTALS_TEXT = ''.
    wa_layout-BOX_FIELDNAME = ''.
    wa_layout-BOX_TABNAME = ''.
    wa_layout-BOX_ROLLNAME = ''.
    wa_layout-CONFIRMATION_PROMPT = 'X'.
    wa_layout-HEADER_TEXT = ''.
    ENDFORM.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'           EXPORTING
            i_callback_program      = gf_repid
            is_layout               = gwa_layout
            it_fieldcat             = gt_catalog
          TABLES
            t_outtab                = gt_line
          EXCEPTIONS
            program_error           = 1
            OTHERS                  = 2.
    Regards,
    ramya

  • Keep subtotal and hide grand total

    Hi,
    I have an ALV whose subtotal should be displayed and grand total hidden. CL_SALV_WD_FIELD=>IF_SALV_WD_SORT~SET_AGGREGATION_ALLOWED calculate both subtotal and subtotal. How can I only display subtotal?
    Thanks,
    ts

    Hi Kumar,
    In the Layout, there is a parameter called "NO_TOTALLINE". Set this to 'X" and see if the grand total is hidden in your ALV display.
    Also, in the SORT table that you build for sub-totals and totals, there are these two fields         
    comp(1) type c,
    expa(1) type c,
    Here EXPA is used to HIDE all the line items and displa only totals.
    So, just check with these two parameters.
    Best Regards,
    Ram.
    Edited by: ram Kumar on Dec 18, 2008 12:02 PM

  • Subtotal Text in ALV Grid and hiding empty row

    Hello,
    ive got a ALV-Grid with a few fields .. Total on one field subtotal on VKORG, category or some other fields .
    after subtotal of one of the 2 named fields i'm reading the literal to the given fields and writing them in the table which is displayed and do a refresh.
    i can show the field literal in the alv by adding it into the field cat but than its displayed even if its not filled.
    i just want to display that column after filling it - the subtotal of the 2 columns.
    and i want to add the text of  the literal to the subtotal line. so if the alv grid is closed to display the totals. i want to see what the subtotal is for.
    for displaying i use        
    CALL METHOD lcl_alv_grid->set_table_for_first_display
          EXPORTING
            is_layout            = gs_layout
            is_variant           = gs_variant
            it_toolbar_excluding = gt_exclude
            i_save               = x_save
            i_default            = 'X'
          CHANGING
            it_outtab            = it_alvlist[]
            it_fieldcatalog      = gt_field_cat.
    for refresh 
        lv_lvc_s_stbl-row = 'X'.
        lv_lvc_s_stbl-col = 'X'.
        lv_soft_refresh = 'X'.
        CALL METHOD lcl_alv_grid->refresh_table_display
          EXPORTING
            is_stable      = lv_lvc_s_stbl
            i_soft_refresh = lv_soft_refresh
          EXCEPTIONS
            finished       = 1
            OTHERS         = 2.
    get the selected column to read literal
    CALL METHOD lcl_alv_grid->get_selected_columns
        IMPORTING
          et_index_columns = it_col_tab
        EXCEPTIONS
          OTHERS           = 1.
    Hope you can help me and understand my problem

    Hi,
    Use the No_out from Reusable types of fieldcat..For example.
    IF it_final-field is initial.
            READ TABLE IT_FIELDCAT5 WITH KEY FIELDNAME = 'BCD'.
            IF SY-SUBRC EQ 0.
              IT_FIELDCAT5-NO_OUT = 'X'.
              MODIFY IT_FIELDCAT5 INDEX SY-TABIX TRANSPORTING NO_OUT.
            ENDIF.
    else.
            READ TABLE IT_FIELDCAT5 WITH KEY FIELDNAME = 'BCD'.
            IF SY-SUBRC EQ 0.
              IT_FIELDCAT5-NO_OUT = ' '.
              MODIFY IT_FIELDCAT5 INDEX SY-TABIX TRANSPORTING NO_OUT.
            ENDIF.
    ENDIf.
    Cheers,
    Syed Maheboob.

  • Total and subtotal in alv

    hi,
    i have an ALV REPORT,displaying the fields such as po item(ekpo-menge).the data type is qunt.
    but i am unable to perform total and sub total,it gives me a information message 'total cannot b performed'.
      even i tried with  X_FIELDCAT-DO_SUM = 'X',
    can any one help me, how to total and subtotal.

    HI
    GOOD
    CHECK WITH THIS EXAMPLES
    data: begin of output_tab occurs 0,
           total_field_hidden(1) type c,
           sortfield1(3) type c,
           sortfield1_hidden(3) type c,
           numerator type p,
           denominator type p,
           perc type p decimals 2,
           percentage type p decimals 2, "(7) type c,
         end of output_tab.
    data: abaplist type standard table of abaplist.
    type-pools: slis.
    data: g_repid like sy-repid.
    data: gt_events type slis_t_event.
    parameters: p_grid radiobutton group g1,
               p_list radiobutton group g1.
    initialization.
    *This is necessary so that the ALV_GRID knows where to
    find the form
    g_repid = sy-repid.
    start-of-selection.
    perform fill_output_tab.
    perform output_alv.
    *&      Form  FILL_OUTPUT_TAB
    form fill_output_tab.
    output_tab-total_field_hidden = '1'.
    output_tab-sortfield1 = output_tab-sortfield1_hidden
    = 'AAA'.
    output_tab-numerator  = 1.
    output_tab-denominator = 2.
    output_tab-perc = output_tab-numerator /
    output_tab-denominator
    100.
    output_tab-percentage = output_tab-perc .
    write output_tab-perc to output_tab-percentage.
    append output_tab.
    output_tab-numerator  = 1.
    output_tab-denominator = 3.
    output_tab-perc = output_tab-numerator /
    output_tab-denominator
    100.
    output_tab-percentage = output_tab-perc .
    write output_tab-perc to output_tab-percentage.
    append output_tab.
    output_tab-numerator  = 1.
    output_tab-denominator = 5.
    output_tab-perc = output_tab-numerator /
    output_tab-denominator
    100.
    output_tab-percentage = output_tab-perc .
    write output_tab-perc to output_tab-percentage.
    append output_tab.
    output_tab-numerator  = 1.
    output_tab-denominator = 5.
    output_tab-perc = output_tab-numerator /
    output_tab-denominator
    100.
    output_tab-percentage = output_tab-perc .
    write output_tab-perc to output_tab-percentage.
    append output_tab.
    output_tab-sortfield1 = output_tab-sortfield1_hidden
    = 'BBB'.
    output_tab-numerator  = 1.
    output_tab-denominator = 2.
    output_tab-perc = output_tab-numerator /
    output_tab-denominator
    100.
    output_tab-percentage = output_tab-perc .
    write output_tab-perc to output_tab-percentage.
    append output_tab.
    output_tab-numerator  = 1.
    output_tab-denominator = 2.
    output_tab-perc = output_tab-numerator /
    output_tab-denominator
    100.
    output_tab-percentage = output_tab-perc .
    write output_tab-perc to output_tab-percentage.
    append output_tab.
    output_tab-numerator  = 1.
    output_tab-denominator = 3.
    output_tab-perc = output_tab-numerator /
    output_tab-denominator
    100.
    output_tab-percentage = output_tab-perc .
    write output_tab-perc to output_tab-percentage.
    append output_tab.
    output_tab-numerator  = 1.
    output_tab-denominator = 5.
    output_tab-perc = output_tab-numerator /
    output_tab-denominator
    100.
    output_tab-percentage = output_tab-perc .
    write output_tab-perc to output_tab-percentage.
    append output_tab.
    endform.                    " FILL_OUTPUT_TAB
    *&      Form  output_alv
    output the list in an ALV Grid
    form output_alv.
    data: ls_layo    type slis_layout_alv,
           lt_fcat    type slis_t_fieldcat_alv,
           lt_sort    type slis_t_sortinfo_alv.
    perform f01_set_sort changing lt_sort.
    perform f01_set_layo changing ls_layo.
    perform f01_set_fcat changing lt_fcat.
    perform eventtab_build using gt_events[].
    g_repid = sy-repid.
    clear output_tab.
    case 'X'.
       when p_list.
         call function 'REUSE_ALV_LIST_DISPLAY'
              exporting
                   I_INTERFACE_CHECK = 'X'
                   i_callback_program = g_repid
                   is_layout          = ls_layo
                   it_fieldcat        = lt_fcat
                   it_events          = gt_events[]
                   it_sort            = lt_sort
              tables
                   t_outtab           = output_tab
              exceptions
                   program_error      = 1
                   others             = 2.
       when p_grid.
         call function 'REUSE_ALV_GRID_DISPLAY'
              exporting
                   i_callback_program = g_repid
                   is_layout          = ls_layo
                   it_fieldcat        = lt_fcat
                   it_events          = gt_events[]
                   it_sort            = lt_sort
              tables
                   t_outtab           = output_tab
              exceptions
                   program_error      = 1
                   others             = 2.
    endcase.
    endform.                    " output_alv
    Sets the Events the ALV Grid needs to react to for
    the Overall Output.
         -->RT_EVENTS[]  A table of events and the forms
    that must be
                         performed for each one.
    form eventtab_build using rt_events type slis_t_event.
    *"Registration of events to happen during list display
    data: ls_event type slis_alv_event.
    refresh rt_events.
    call function 'REUSE_ALV_EVENTS_GET'
          exporting
               i_list_type = 0
          importing
               et_events   = rt_events.
    Subtotal
    read table rt_events with key name =
    slis_ev_subtotal_text
                              into ls_event.
    if sy-subrc = 0.
       move 'SUBTOTAL_TEXT' to ls_event-form.
       append ls_event to rt_events.
    endif.
    endform.                    " EVENTTAB_BUILD2
    *&      Form  f01_set_sort
    form f01_set_sort changing p_lt_sort type
    slis_t_sortinfo_alv.
    data: ls_sort type slis_sortinfo_alv.
    clear ls_sort.
    ls_sort-spos = 1.
    ls_sort-fieldname = 'TOTAL_FIELD_HIDDEN'.
    ls_sort-subtot = 'X'.
    append ls_sort to p_lt_sort.
    clear ls_sort.
    ls_sort-spos = 2.
    ls_sort-fieldname = 'SORTFIELD1_HIDDEN'.
    ls_sort-subtot = 'X'.
    append ls_sort to p_lt_sort.
    endform.                    " f01_set_sort
    *&      Form  f01_set_layo
    Sets layout options
    form f01_set_layo changing p_ls_layo type
    slis_layout_alv.
    p_ls_layo-no_totalline = 'X'.
    endform.                    " f01_set_layo
    *&      Form  f01_set_fcat
          Sets the columns and texts for the ALV Grid
         <--P_LT_FCAT  text
    form f01_set_fcat changing ct_fcat type
    slis_t_fieldcat_alv.
    data: ls_fcat type slis_fieldcat_alv.
    ls_fcat-tabname = 'OUTPUT_TAB'.
    ls_fcat-fieldname    = 'TOTAL_FIELD_HIDDEN'.
    ls_fcat-no_out = 'X'.
    ls_fcat-col_pos       = 1.
    append ls_fcat to ct_fcat.
    clear ls_fcat.
    ls_fcat-tabname = 'OUTPUT_TAB'.
    ls_fcat-fieldname    = 'SORTFIELD1_HIDDEN'.
    ls_fcat-no_out = 'X'.
    ls_fcat-col_pos       = 2.
    append ls_fcat to ct_fcat.
    clear ls_fcat.
    ls_fcat-seltext_m = 'SORT'.
    ls_fcat-tabname = 'OUTPUT_TAB'.
    ls_fcat-fieldname    = 'SORTFIELD1'.
    ls_fcat-col_pos       = 3.
    append ls_fcat to ct_fcat.
    clear ls_fcat.
    ls_fcat-seltext_m = 'SALES'.
    ls_fcat-tabname = 'OUTPUT_TAB'.
    ls_fcat-fieldname    = 'NUMERATOR'.
    ls_fcat-col_pos       = 4.
    ls_fcat-datatype = 'CURR'.
    ls_fcat-do_sum = 'X'.
    append ls_fcat to ct_fcat.
    clear ls_fcat.
    ls_fcat-seltext_m = 'COST'.
    ls_fcat-tabname = 'OUTPUT_TAB'.
    ls_fcat-fieldname    = 'DENOMINATOR'.
    ls_fcat-datatype = 'CURR'.
    ls_fcat-col_pos       = 5.
    ls_fcat-do_sum = 'X'.
    append ls_fcat to ct_fcat.
    clear ls_fcat.
    ls_fcat-seltext_m = 'MARGIN'.
    ls_fcat-tabname = 'OUTPUT_TAB'.
    ls_fcat-fieldname    = 'PERCENTAGE'.
    ls_fcat-datatype = 'CHAR'.
    ls_fcat-do_sum = 'X'.
    ls_fcat-col_pos       = 6.
    append ls_fcat to ct_fcat.
    endform.
    *&      Form  subtotal_text
    Manipulate the subtotal line in the ALV to
    recalculate eficiency at
    total level.
    form subtotal_text using ep_subtot_line like
    output_tab
                            es_subtottxt type
    slis_subtot_text.
    if es_subtottxt-criteria = 'TOTAL_FIELD_HIDDEN'.
       es_subtottxt-display_text_for_subtotal = 'Final
    Total'.
    endif.
    ep_subtot_line-percentage = ep_subtot_line-numerator
                / ep_subtot_line-denominator
    100.
    ep_subtot_line-perc = ep_subtot_line-percentage.
    endform.
           total_field_hidden(1) type c,
    >        sortfield1(3) type c,
    >        sortfield1_hidden(3) type c,
    >        numerator type p,
    >        denominator type p,
    >        perc type p decimals 2,
    >        percentage type p decimals 2, "(7) type c, end of output_tab.
    >
    >data: abaplist type standard table of abaplist.
    >
    >type-pools: slis.
    >data: g_repid like sy-repid.
    >data: gt_events type slis_t_event.
    >*----
    >parameters: p_grid radiobutton group g1,
    >            p_list radiobutton group g1.
    >
    >initialization.
    >*This is necessary so that the ALV_GRID knows where to
    >find the form
    >  g_repid = sy-repid.
    >
    >start-of-selection.
    >  perform fill_output_tab.
    >
    >  perform output_alv. &---- *&      Form  FILL_OUTPUT_TAB &---- form fill_output_tab.
    >  output_tab-total_field_hidden = '1'.
    >  output_tab-sortfield1 = output_tab-sortfield1_hidden = 'AAA'.
    >  output_tab-numerator  = 1.
    >  output_tab-denominator = 2.
    >  output_tab-perc = output_tab-numerator / output_tab-denominator
    >                        * 100. output_tab-percentage = output_tab-perc . *  write output_tab-perc to output_tab-percentage. append output_tab.
    >
    >  output_tab-numerator  = 1.
    >  output_tab-denominator = 3.
    >  output_tab-perc = output_tab-numerator / output_tab-denominator
    >                        * 100. output_tab-percentage = output_tab-perc . *  write output_tab-perc to output_tab-percentage. append output_tab.
    >
    >  output_tab-numerator  = 1.
    >  output_tab-denominator = 5.
    >  output_tab-perc = output_tab-numerator / output_tab-denominator
    >                        * 100. output_tab-percentage = output_tab-perc . *  write output_tab-perc to output_tab-percentage. append output_tab.
    >
    >  output_tab-numerator  = 1.
    >  output_tab-denominator = 5.
    >  output_tab-perc = output_tab-numerator / output_tab-denominator
    >                        * 100. output_tab-percentage = output_tab-perc . *  write output_tab-perc to output_tab-percentage. append output_tab.
    >
    >  output_tab-sortfield1 = output_tab-sortfield1_hidden = 'BBB'.
    >  output_tab-numerator  = 1.
    >  output_tab-denominator = 2.
    >  output_tab-perc = output_tab-numerator / output_tab-denominator
    >                        * 100. output_tab-percentage = output_tab-perc . *  write output_tab-perc to output_tab-percentage. append output_tab.
    >
    >  output_tab-numerator  = 1.
    >  output_tab-denominator = 2.
    >  output_tab-perc = output_tab-numerator / output_tab-denominator
    >                        * 100. output_tab-percentage = output_tab-perc . *  write output_tab-perc to output_tab-percentage. append output_tab.
    >
    >  output_tab-numerator  = 1.
    >  output_tab-denominator = 3.
    >  output_tab-perc = output_tab-numerator / output_tab-denominator
    >                        * 100. output_tab-percentage = output_tab-perc . *  write output_tab-perc to output_tab-percentage. append output_tab.
    >
    >  output_tab-numerator  = 1.
    >  output_tab-denominator = 5.
    >  output_tab-perc = output_tab-numerator / output_tab-denominator
    >                        * 100. output_tab-percentage = output_tab-perc . *  write output_tab-perc to output_tab-percentage. append output_tab.
    >
    >endform.                    " FILL_OUTPUT_TAB
    >&----
    >*&      Form  output_alv
    >&----
    >* output the list in an ALV Grid
    >----
    >form output_alv.
    >  data: ls_layo    type slis_layout_alv,
    >        lt_fcat    type slis_t_fieldcat_alv,
    >        lt_sort    type slis_t_sortinfo_alv.
    >
    >  perform f01_set_sort changing lt_sort.
    >  perform f01_set_layo changing ls_layo.
    >  perform f01_set_fcat changing lt_fcat.
    >  perform eventtab_build using gt_events[].
    >  g_repid = sy-repid.
    >  clear output_tab.
    >  case 'X'.
    >    when p_list.
    >      call function 'REUSE_ALV_LIST_DISPLAY'
    >           exporting *                I_INTERFACE_CHECK = 'X'
    >                i_callback_program = g_repid
    >                is_layout          = ls_layo
    >                it_fieldcat        = lt_fcat
    >                it_events          = gt_events[]
    >                it_sort            = lt_sort tables
    >                t_outtab           = output_tab exceptions
    >                program_error      = 1
    >                others             = 2. when p_grid. call function 'REUSE_ALV_GRID_DISPLAY' exporting
    >                i_callback_program = g_repid
    >                is_layout          = ls_layo
    >                it_fieldcat        = lt_fcat
    >                it_events          = gt_events[]
    >                it_sort            = lt_sort tables
    >                t_outtab           = output_tab exceptions
    >                program_error      = 1
    >                others             = 2. endcase.
    >
    >endform.                    " output_alv
    >
    >&----
    >* Sets the Events the ALV Grid needs to react to for
    >the Overall Output.
    >----
    >*      -->RT_EVENTS[]  A table of events and the forms
    >that must be
    >*                      performed for each one.
    >----
    >form eventtab_build using rt_events type slis_t_event.
    >*"Registration of events to happen during list display
    >  data: ls_event type slis_alv_event.
    >*
    >  refresh rt_events.
    >  call function 'REUSE_ALV_EVENTS_GET'
    >       exporting
    >            i_list_type = 0 importing
    >            et_events   = rt_events.
    >
    >* Subtotal
    >  read table rt_events with key name = slis_ev_subtotal_text
    >                           into ls_event. if sy-subrc = 0. move 'SUBTOTAL_TEXT' to ls_event-form. append ls_event to rt_events. endif.
    >
    >endform.                    " EVENTTAB_BUILD2
    >&----
    >*&      Form  f01_set_sort
    >&----
    >form f01_set_sort changing p_lt_sort type
    >slis_t_sortinfo_alv.
    >
    >  data: ls_sort type slis_sortinfo_alv.
    >
    >  clear ls_sort.
    >  ls_sort-spos = 1.
    >  ls_sort-fieldname = 'TOTAL_FIELD_HIDDEN'.
    >  ls_sort-subtot = 'X'.
    >  append ls_sort to p_lt_sort.
    >
    >  clear ls_sort.
    >  ls_sort-spos = 2.
    >  ls_sort-fieldname = 'SORTFIELD1_HIDDEN'.
    >  ls_sort-subtot = 'X'.
    >  append ls_sort to p_lt_sort.
    >
    >endform.                    " f01_set_sort
    >&----
    >*&      Form  f01_set_layo
    >&----
    >* Sets layout options
    >----
    >form f01_set_layo changing p_ls_layo type
    >slis_layout_alv.
    >
    >  p_ls_layo-no_totalline = 'X'.
    >
    >endform.                    " f01_set_layo
    >&----
    >*&      Form  f01_set_fcat
    >&----
    >*       Sets the columns and texts for the ALV Grid
    >----
    >*      <--P_LT_FCAT  text
    >----
    >form f01_set_fcat changing ct_fcat type
    >slis_t_fieldcat_alv.
    >
    >  data: ls_fcat type slis_fieldcat_alv.
    >
    >  ls_fcat-tabname = 'OUTPUT_TAB'.
    >  ls_fcat-fieldname    = 'TOTAL_FIELD_HIDDEN'.
    >  ls_fcat-no_out = 'X'.
    >  ls_fcat-col_pos       = 1.
    >  append ls_fcat to ct_fcat.
    >
    >  clear ls_fcat.
    >  ls_fcat-tabname = 'OUTPUT_TAB'.
    >  ls_fcat-fieldname    = 'SORTFIELD1_HIDDEN'.
    >  ls_fcat-no_out = 'X'.
    >  ls_fcat-col_pos       = 2.
    >  append ls_fcat to ct_fcat.
    >
    >  clear ls_fcat.
    >  ls_fcat-seltext_m = 'SORT'.
    >  ls_fcat-tabname = 'OUTPUT_TAB'.
    >  ls_fcat-fieldname    = 'SORTFIELD1'.
    >  ls_fcat-col_pos       = 3.
    >  append ls_fcat to ct_fcat.
    >
    >  clear ls_fcat.
    >  ls_fcat-seltext_m = 'SALES'.
    >  ls_fcat-tabname = 'OUTPUT_TAB'.
    >  ls_fcat-fieldname    = 'NUMERATOR'.
    >  ls_fcat-col_pos       = 4.
    >  ls_fcat-datatype = 'CURR'.
    >  ls_fcat-do_sum = 'X'.
    >  append ls_fcat to ct_fcat.
    >
    >  clear ls_fcat.
    >  ls_fcat-seltext_m = 'COST'.
    >  ls_fcat-tabname = 'OUTPUT_TAB'.
    >  ls_fcat-fieldname    = 'DENOMINATOR'.
    >  ls_fcat-datatype = 'CURR'.
    >  ls_fcat-col_pos       = 5.
    >  ls_fcat-do_sum = 'X'.
    >  append ls_fcat to ct_fcat.
    >
    >  clear ls_fcat.
    >  ls_fcat-seltext_m = 'MARGIN'.
    >  ls_fcat-tabname = 'OUTPUT_TAB'.
    >  ls_fcat-fieldname    = 'PERCENTAGE'. *  ls_fcat-datatype = 'CHAR'.
    >  ls_fcat-do_sum = 'X'.
    >  ls_fcat-col_pos       = 6.
    >  append ls_fcat to ct_fcat.
    >
    >endform.
    >&----
    >*&      Form  subtotal_text
    >&----
    >* Manipulate the subtotal line in the ALV to
    >recalculate eficiency at
    >* total level.
    >----
    >form subtotal_text using ep_subtot_line like
    >output_tab
    >                         es_subtottxt type slis_subtot_text.
    >
    >  if es_subtottxt-criteria = 'TOTAL_FIELD_HIDDEN'.
    >    es_subtottxt-display_text_for_subtotal = 'Final Total'. endif.
    >
    >  ep_subtot_line-percentage = ep_subtot_line-numerator
    >             / ep_subtot_line-denominator
    >             * 100.
    >
    >  ep_subtot_line-perc = ep_subtot_line-percentage. endform.
    >
    THANKS
    MRUTYUN

  • How can we change the Subtotal text in alv  , urgent.

    hi,
    i want to maintain the text at subtotal level in an ALV.here i am using standard alv.not abap oops. i tried with the event subtotal_text but the form was not triggering in the progam.please provide some sample code.

    Hi,
    See This code .
    Reward if its usefull.
    Regards,
    Durgaprasad.
    *& Report  ZALV1
    REPORT  ZALV1.
    TABLES : vbak.
    TYPE-POOLS: slis.                      " ALV Global types
    SELECT-OPTIONS :
      s_vkorg FOR vbak-vkorg,              " Sales organization
      s_kunnr FOR vbak-kunnr,              " Sold-to party
      s_vbeln FOR vbak-vbeln.              " Sales document
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    DATA:
      BEGIN OF gt_vbak OCCURS 0,
        vkorg LIKE vbak-vkorg,             " Sales organization
        kunnr LIKE vbak-kunnr,             " Sold-to party
        vbeln LIKE vbak-vbeln,             " Sales document
        netwr LIKE vbak-netwr,             " Net Value of the Sales Order
        waerk LIKE vbak-waerk,             " Document currency
      END OF gt_vbak.
    INITIALIZATION.
      v_1 = 'Maximum of records to read'.
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
         Form  f_read_data
    FORM f_read_data.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
               FROM vbak
                 UP TO p_max ROWS
              WHERE kunnr IN s_kunnr
                AND vbeln IN s_vbeln
                AND vkorg IN s_vkorg.
    ENDFORM.                               " F_READ_DATA
         Form  f_display_data
    FORM f_display_data.
      DEFINE m_fieldcat.
        add 1 to ls_fieldcat-col_pos.
        ls_fieldcat-fieldname   = &1.
        ls_fieldcat-ref_tabname = 'VBAK'.
        ls_fieldcat-do_sum      = &2.
        ls_fieldcat-cfieldname  = &3.
        append ls_fieldcat to lt_fieldcat.
      END-OF-DEFINITION.
      DEFINE m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        ls_sort-up        = 'X'.
        ls_sort-subtot    = &2.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv,
        lt_sort     TYPE slis_t_sortinfo_alv,
        ls_sort     TYPE slis_sortinfo_alv,
        ls_layout   TYPE slis_layout_alv.
      m_fieldcat 'VKORG' ''  ''.
      m_fieldcat 'KUNNR' ''  ''.
      m_fieldcat 'VBELN' ''  ''.
      m_fieldcat 'NETWR' 'X' 'WAERK'.
      m_fieldcat 'WAERK' ''  ''.
      m_sort 'VKORG' 'X'.                  " Sort by vkorg and subtotal
      m_sort 'KUNNR' 'X'.                  " Sort by kunnr and subtotal
      m_sort 'VBELN' ''.                   " Sort by vbeln
      ls_layout-cell_merge = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                is_layout   = ls_layout
                it_fieldcat = lt_fieldcat
                it_sort     = lt_sort
           TABLES
                t_outtab    = gt_vbak.
    ENDFORM.                               " F_DISPLAY_DATA

  • SUBTOTAL TEXT IN ALV GRID

    HI ALL,
    could any one  send me how to display the subtotal Text  in ALV grid output with code sample.
    with thanks.
    kannan

    hi,
    means u want to print some text instead of star ( coming in subtotal) ?
    If so than try like,
    *& Report  ZALV_LIST
    REPORT  zalv_list.
    TABLES : mseg.
    TYPE-POOLS : slis.
    DATA : BEGIN OF itab OCCURS 0,
            mblnr LIKE mseg-mblnr,
            matnr LIKE mseg-matnr,
            werks LIKE mseg-werks,
            menge LIKE mseg-menge,
            line_color(4) TYPE c,
           END OF itab.
    DATA : BEGIN OF itab1 OCCURS 0,
            mblnr LIKE mseg-mblnr,
            matnr LIKE mseg-matnr,
            werks LIKE mseg-werks,
            menge LIKE mseg-menge,
            line_color(4) TYPE c,
           END OF itab1.
    DATA : t_fcat TYPE slis_t_fieldcat_alv,
           t_eve TYPE slis_t_event,
           t_subtot TYPE slis_t_sortinfo_alv,
           subtot LIKE LINE OF t_subtot,
           wa_fcat LIKE LINE OF t_fcat,
           gd_layout    TYPE slis_layout_alv.
    DATA : gt_menge LIKE mseg-menge,
           st_menge LIKE mseg-menge.
    SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS : doc FOR mseg-mblnr.
    SELECTION-SCREEN : END OF BLOCK blk1.
    INITIALIZATION.
      PERFORM build_cat USING t_fcat.
      PERFORM build_eve.
      PERFORM build_layout.
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM display.
    *&      Form  build_cat
          text
         -->TEMP_FCAT  text
    FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MBLNR'.
      wa_fcat-seltext_m = 'Material Doc.'.
      APPEND wa_fcat TO temp_fcat.
      CLEAR wa_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MATNR'.
      wa_fcat-seltext_m = 'Material'.
      APPEND wa_fcat TO temp_fcat.
      CLEAR wa_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'WERKS'.
      wa_fcat-seltext_m = 'Plant'.
      APPEND wa_fcat TO temp_fcat.
      CLEAR wa_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MENGE'.
      wa_fcat-seltext_m = 'Quantity'.
    wa_fcat-do_sum = 'Y'.
      APPEND wa_fcat TO temp_fcat.
      CLEAR wa_fcat.
    subtot-spos = 1.
    subtot-fieldname = 'MBLNR'.
    subtot-tabname = 'ITAB'.
    subtot-up = 'X'.
    subtot-group = 'X'.
    subtot-subtot = 'X'.
    subtot-expa = 'X'.
    APPEND subtot TO t_subtot.
    ENDFORM.                    "build_cat
    *&      Form  build_eve
          text
    FORM build_eve.
      DATA : wa_eve TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = t_eve
        EXCEPTIONS
          list_type_wrong = 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.
      READ TABLE t_eve WITH KEY name =  slis_ev_top_of_page
                             INTO wa_eve.
      IF sy-subrc = 0.
        MOVE 'TOP_OF_PAGE' TO wa_eve-form.
        APPEND wa_eve TO t_eve.
      ENDIF.
    ENDFORM.                    "build_eve
    *&      Form  build_layout
          text
    FORM build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-info_fieldname =      'LINE_COLOR'.
      gd_layout-subtotals_text = 'Sub Total'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  get_data
          text
    FORM get_data.
      SELECT mblnr matnr werks menge FROM mseg INTO CORRESPONDING FIELDS OF TABLE itab
      WHERE mblnr IN doc.
      SORT itab BY mblnr.
      LOOP AT itab.
        AT NEW mblnr.
          LOOP AT itab WHERE mblnr = itab-mblnr.
            st_menge = st_menge + itab-menge.
            itab1-mblnr = itab-mblnr.
            itab1-matnr = itab-matnr.
            itab1-werks = itab-werks.
            itab1-menge = itab-menge.
            APPEND itab1.
          ENDLOOP.
          itab1-mblnr = 'Sub_Total'.
          itab1-matnr = ''.
          itab1-werks = ''.
          itab1-menge = st_menge.
          itab1-line_color = 'C710'.
          APPEND itab1.
          itab1-line_color = ''.
          CLEAR st_menge.
        ENDAT.
      ENDLOOP.
      LOOP AT itab.
        gt_menge = gt_menge + itab-menge.
      ENDLOOP.
      itab1-mblnr = 'Total'.
      itab1-matnr = ''.
      itab1-werks = ''.
      itab1-menge = gt_menge.
      itab1-line_color = 'C310'.
      APPEND itab1.
    ENDFORM.                    "get_data
    *&      Form  display
          text
    FORM display.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
         i_callback_program             = 'ZALV_LIST'
         is_layout                      = gd_layout
         it_fieldcat                    = t_fcat
        it_sort                        = t_subtot
         it_events                      = t_eve
        TABLES
          t_outtab                       = itab1
    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.                    "display
    *&      Form  top_of_page
          text
    FORM top_of_page.
      WRITE:/ 'Data'.
    ENDFORM.                    "top_of_page
    reward if useful....
    Edited by: Dhwani shah on Dec 20, 2007 1:20 PM

  • Regarding subtotal text and total text

    Hi All,
    can any body provide example program for ALV total text and subtotal text both using REUSE_ALV_GRID_DISPALY.  and
    using OOPS.
    @@@MODERATOR::    Please dont lock my threads.I have been searching since 2 days for this example and i tried with the provided examples .but they are not worked out ::
    FOr your information :
    Some of the links i searched in SDN: 
    http://wiki.sdn.sap.com/wiki/display/ABAP/ALVDisplayTotalTextOrSubtotalText
    Re: SubTotal Text in ALV?
    http://wiki.sdn.sap.com/wiki/display/ABAP/ALVStandardSumTotalOr+Subtotal

    Hi Naveen,
    If you are looking for specific Subtotal text in ALV Grid, then i think it is not possible.
    You can use SORT table to get sub-totals based on the columns that you display.
    Generally the record existing on the column based on which you sort the table, appears as the sub-total text automatically.....
    You can try giving Subtotal text in the LAYOUT as well and pass the layout to the ALV function module.
    Best Regards,
    Ram.

  • Reg: Subtotal text in alv grid.

    Hi All,
    I need to display the subtotal text in ALV.
    If:
    data: i_layout type slis_layout_alv.
    Then, we can used
    i_layout-subtotal_text = ‘my subtotal text’.
    But my declaration is :
    Data: ls_layout   type lvc_s_layo.
    This dosnt have subtotaltext.
    I have tried the method:
    method subtotal_text.
        perform event_subtotal_text using es_subtottxt_info
                                          ep_subtot_line
                                          e_event_data.
    and also used the handle.
    as per the coding in : BCALV_TEST_GRID_EVENTS
    Still its not working.
    Waiting for your valuable inputs.
    Thanks & Regards,
    Anjali

    Hi Anjali,
    Try this sample code.
    REPORT z_demo_alv_sort.
    TABLES : vbak.
    TYPE-POOLS: slis.                      " ALV Global types
    SELECT-OPTIONS :
      s_vkorg FOR vbak-vkorg,              " Sales organization
      s_kunnr FOR vbak-kunnr,              " Sold-to party
      s_vbeln FOR vbak-vbeln.              " Sales document
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    DATA:
      BEGIN OF gt_vbak OCCURS 0,
        vkorg LIKE vbak-vkorg,             " Sales organization
        kunnr LIKE vbak-kunnr,             " Sold-to party
        vbeln LIKE vbak-vbeln,             " Sales document
        netwr LIKE vbak-netwr,             " Net Value of the Sales Order
        waerk LIKE vbak-waerk,             " Document currency
      END OF gt_vbak.
    INITIALIZATION.
      v_1 = 'Maximum of records to read'.
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
         Form  f_read_data
    FORM f_read_data.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
               FROM vbak
                 UP TO p_max ROWS
              WHERE kunnr IN s_kunnr
                AND vbeln IN s_vbeln
                AND vkorg IN s_vkorg.
    ENDFORM.                               " F_READ_DATA
         Form  f_display_data
    FORM f_display_data.
      DEFINE m_fieldcat.
        add 1 to ls_fieldcat-col_pos.
        ls_fieldcat-fieldname   = &1.
        ls_fieldcat-ref_tabname = 'VBAK'.
        ls_fieldcat-do_sum      = &2.
        ls_fieldcat-cfieldname  = &3.
        append ls_fieldcat to lt_fieldcat.
      END-OF-DEFINITION.
      DEFINE m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        ls_sort-up        = 'X'.
        ls_sort-subtot    = &2.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv,
        lt_sort     TYPE slis_t_sortinfo_alv,
        ls_sort     TYPE slis_sortinfo_alv,
        ls_layout   TYPE slis_layout_alv.
      m_fieldcat 'VKORG' ''  ''.
      m_fieldcat 'KUNNR' ''  ''.
      m_fieldcat 'VBELN' ''  ''.
      m_fieldcat 'NETWR' 'X' 'WAERK'.
      m_fieldcat 'WAERK' ''  ''.
      m_sort 'VKORG' 'X'.                  " Sort by vkorg and subtotal
      m_sort 'KUNNR' 'X'.                  " Sort by kunnr and subtotal
      m_sort 'VBELN' ''.                   " Sort by vbeln
      ls_layout-cell_merge = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                is_layout   = ls_layout
                it_fieldcat = lt_fieldcat
                it_sort     = lt_sort
           TABLES
                t_outtab    = gt_vbak.
    ENDFORM.                               " F_DISPLAY_DATA
    Hope this helps,
    Thanks,
    Priya.

  • Displaying subtotal text in alv using the fm reuse_alv_grid_display

    Hi,
    Can someone help me with this, I am having some problem in displaying the subtotal text in subtotal field in alv. I tried populating the layout of the alv with the text that will be displayed on the output but nothing happens. Is is possible to display the subtotal text in alv using the fm reuse_alv_grid_display? If so, what are the things that I must consider to display the subtotal text in alv output.
    Please help me with this. I promise to give you points if you resolve this problem.
    Thanks,
    Gie

    Hi ,
         Make it use in your code and let me know if u have any concerns...
        Use "Subtotal_text" in events table.
    here GTOTAL is field in itab on which we sortindf data, and use your own field on which field u want to sort...
    refresh gt_event.
    clear gw_event.
    call function 'REUSE_ALV_EVENTS_GET'
       EXPORTING
         i_list_type = 0
       IMPORTING
         et_events   = gt_event.
    Subtotal
    read table gt_event with key name = slis_ev_subtotal_text into gw_event.
    if sy-subrc = 0.
       move 'SUBTOTAL_TEXT' to gw_event-form.
       append gw_event to gt_event.
    endif.
         form subtotal_text using uw_subtot_line type ty_main
                    uv_subtottxt type slis_subtot_text.  "#EC CALLED
    if uv_subtottxt-criteria = 'GTOTAL'.
       uv_subtottxt-display_text_for_subtotal = 'TOTAL'.
    endif.
         *FORM build_sort .
    refresh gt_sort.
    gw_sort-spos      = 1.
    gw_sort-fieldname = 'GTOTAL'.
    gw_sort-tabname   = 'GT_MAIN'.
    gw_sort-up        = 'X'.
    gw_sort-subtot    = 'X'.
    APPEND gw_sort TO gt_sort.
    CLEAR gw_sort.
    Reward points once its useful..

Maybe you are looking for

  • Why does the Vision M come with old Creative Mediasource ,and not version

    I just got a Vision M player and was disappointed to find it came with the older version of Mediasource, I recently purchased and returned a Zen V 2 gb. player that came with version 5 software. I'm confused why the M only gets version 3.30.35 . I re

  • JCo Increaing maximum no of connections

    Hi, I have some issues with RFC adapter. I need to increase the Maximum no. of connections for RFC adapter JCo Connection pool. I have increased the maximum connections in RFC receiver adapter. This does not seem to work. Any help on this is highly a

  • Does anyone know how to manlipulate the itunes 8 database

    I have a compilation of 16 cd's with each having 15-20 titles. For some reason disk 11 of 16 won't play in the secquence that it was loaded in. it plays disk 10 and then starts disk 12. Under the Genre, itunes says that it has 2 albums 291 songs. In

  • No PVO attributes on MX_Member_

    Hello,       I hope someone can give me some advice.  The proceedure for users to get new roles in our case involves a external system.  We want to record this request number as we assign roles to users.   We have decided to use the MX_REASON attribu

  • How can i transmit music using bluetooth to my stereo

    in a fairly cheap way, though still being of a reasonable quality, can i send audio from my iphone 2g to my stereo and if so how? any help would be appreciated, thanks