ALV Subtotals - Average

Hi everybody,
I know that ALV has the subtotals function (application bar), but does someone knows if ALV classes or FM(REUSE_ALV...) have a way to define another formula (i.e. average of values in the group) instead sum of the group?
Thanks!
Flavio Furlan

Hi,
There is an option for Mean, Minimum and Maximum in the standard ALV. If you go to the Menu path Edit -> Calculate with respect to a column with numeric values, you can choose to display:
Mean (Average)
Minimum
Maximum
Cheers,
Bhanu

Similar Messages

  • ALV Subtotals

    Hi ABAP Gurus,
    I have a problem with ALV subtotals and don't now how to solve it using ALV. I might have to go back to Classical reports if I cannot solve it. Here is the Problem :
    The tables BSET stores the Taxes info for the accounting documents. Each line is for the tax jurisdiction levels and tax jurisdiction code. The base amount on all the lines is same say 100.00 and let us assume 6 lines. When the subtotals are done for the jurisdiction levels the subtotal for the base amount is 100.00 ( only one line per level ) and this is what is expected. But for tax jurisdiction code the total comes to 600.00 Which is what is expected from ALV totals . But since 100.00 is the base amount for tax report purposes this should be the subtotal. That is the subtotal should be 100 for the jurisdiction codes not 600.00.
    I tried varous stuff but couldn't get desired results? Any solution is highly appreciated.
    Thanks,
    Nanda

    REPORT ysalesorder_alv_subtotals.
    Type Pools
    TYPE-POOLS:slis.
    Tables
    TABLES: vbak, "Sales Document: Header Data
    vbap. "Sales Document: Item Data
    Global Structures
    DATA:gt_fieldcat TYPE slis_t_fieldcat_alv,
    wa_fieldcat TYPE slis_fieldcat_alv,
    gt_sortcat TYPE slis_t_sortinfo_alv,
    wa_sortcat LIKE LINE OF gt_sortcat.
    Internal Table
    DATA: BEGIN OF gt_salesorder OCCURS 0,
    vbeln LIKE vbak-vbeln, " Sales Document Number
    posnr LIKE vbap-posnr, " Sales Doc Item
    netwr LIKE vbap-netwr, " Net Value
    END OF gt_salesorder.
    SELECT OPTIONS
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME
    TITLE text-001.
    SELECT-OPTIONS: s_vbeln FOR vbak-vbeln. " Sales Document
    Number.
    SELECTION-SCREEN END OF BLOCK b1.
    Initialization
    INITIALIZATION.
    PERFORM initialization.
    Start Of Selection
    START-OF-SELECTION.
    PERFORM field_catalog. "For Structure Creation
    PERFORM fetch_data. "Get the Data From DB Table
    PERFORM sorting USING gt_sortcat.
    End Of Selection
    END-OF-SELECTION.
    PERFORM display_data.
    *& Form initialization
    text
    --> p1 text
    <-- p2 text
    FORM initialization .
    s_vbeln-sign = 'I'.
    s_vbeln-option = 'BT'.
    s_vbeln-low = '4969'.
    s_vbeln-high = '5000'.
    APPEND s_vbeln.
    ENDFORM. " initialization
    *& Form field_catalog
    text
    --> p1 text
    <-- p2 text
    FORM field_catalog .
    REFRESH : gt_fieldcat.
    CLEAR : wa_fieldcat.
    wa_fieldcat-col_pos = '1'. "Column Position
    wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table
    wa_fieldcat-fieldname = 'VBELN'. "Field Name
    wa_fieldcat-key = 'X'. "Blue Color
    wa_fieldcat-seltext_m = 'Sales Doc No'. "Display Text In Screen
    APPEND wa_fieldcat TO gt_fieldcat.
    CLEAR wa_fieldcat.
    wa_fieldcat-col_pos = '2'. "Column Position
    wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table Name
    wa_fieldcat-fieldname = 'POSNR'. "Field Name
    wa_fieldcat-seltext_m = 'Sales Doc Item'."Display Text In Screen
    APPEND wa_fieldcat TO gt_fieldcat.
    CLEAR wa_fieldcat.
    *SubTotal on the Field NETWR
    wa_fieldcat-col_pos = '3'. "Column Position
    wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table
    wa_fieldcat-fieldname = 'NETWR'. "Field Name
    wa_fieldcat-do_sum = 'X'. "Sum
    wa_fieldcat-seltext_m = 'Net Value'. "Display Text In Screen
    APPEND wa_fieldcat TO gt_fieldcat.
    CLEAR wa_fieldcat.
    ENDFORM. " field_catalog
    *& Form sorting
    text
    -->P_IT_SORTCAT text
    FORM sorting USING p_it_sortcat TYPE slis_t_sortinfo_alv.
    CLEAR wa_sortcat.
    wa_sortcat-fieldname = 'VBELN'.
    wa_sortcat-up ='X'.
    wa_sortcat-subtot = 'X'.
    APPEND wa_sortcat TO p_it_sortcat.
    ENDFORM. " sorting
    *& Form display_data
    text
    --> p1 text
    <-- p2 text
    FORM display_data .
    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 = ' '
    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 =
    it_fieldcat = gt_fieldcat
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    it_sort = gt_sortcat
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    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
    IT_ALV_GRAPHICS =
    IT_HYPERLINK =
    IT_ADD_FIELDCAT =
    IT_EXCEPT_QINFO =
    I_HTML_HEIGHT_TOP =
    I_HTML_HEIGHT_END =
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
    TABLES
    t_outtab = gt_salesorder
    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_data
    *& Form fetch_data
    text
    --> p1 text
    <-- p2 text
    FORM fetch_data .
    REFRESH : gt_salesorder.
    CLEAR : gt_salesorder.
    SELECT a~vbeln
    posnr
    b~netwr
    FROM vbak AS a
    INNER JOIN vbap AS b ON avbeln = bvbeln
    INTO TABLE gt_salesorder
    WHERE a~vbeln IN s_vbeln.
    ENDFORM. " fetch_data
    pls see this example and try u r program.i
    regards
    ravi

  • ALV sum average subtotal...

    Can anyone show me where in code of class CL_GUI_ALV_GRID are calculated:
    sum, average, max, min.
    I need to calculatete this values on a huge amount of data and I;m interesting how this is done in ALV.
    Regards, Tomek

    Hi Tomasz,
    method GET_TOTALS of class CL_GUI_ALV_GRID says this:
    method get_totals .
    * not in use while import/export from memory has to be used for
    * saving the internal tables. Therfore the function module
    * LVC_TOTALS_GET is used.
    endmethod.
    For subtotals, take a look at method GET_GROUPLEVELS, line 65:
      data: l_sumlevel      type i,
            l_sumlevel_unit type i.
      call function 'LVC_SUMLEVEL_TRANSLATE'
        changing
          ct_sort           = m_cl_variant->mt_sort
          ct_grouplevels    = m_cl_variant->mt_grouplevels
          c_sumlevel_global = l_sumlevel
          c_sumlevel_unit   = l_sumlevel_unit.
    Hope this helps,
    R.

  • In ALV: Subtotals for every month, not for every day, possible?

    Hello,
    in my Alv-Grid I have a date column, which I want to use to generate subtotals. But I don't want to have a subtotal for every date, but for every month. Is there a method to accomplish this with subtotals? Thanks.
    Regards, Lars.

    Hi Stembergg,
    1. Its not possible with only date field.
    2. However, if you have one EXTRA FIELD
       which contains the Month
       only then it is possible.
      ( You may hide this extra field if   u don't
      won't to display. But anyhow, u need to
      modify your logic and the internal table
       and accordingly populate the extra field)
    3. There is contraint in alv
        that we cannot use any function for any column value
        for any claculation/grouping purpose.
    Hope it helps.
    Regards,
    Amit M.
    Message was edited by: Amit Mittal

  • Reg: ALV subtotals calculation

    Hi SDN's,
    I have 4 fields(coloumns) In ALV Grid display output,
    first 2 coloumn fields having the subtotal.
    I need to calculate 3rd, 4th columns based on first 2 columns subtotals.
    Can u help me in this regard..
    My problem some thing like the below example..
                                         Col1                  Col2              Col3        Col4
                                         25.00                  0.00    
                                         45.00                  30.00
      <b>                 70.00                  30.00         X                   Y</b>
    Now, i need to find out the values of X and Y based on the subtotals of first and second column,
    like X = (subtotal of column1 -  subtotal of column2) /  subtotal of column2 *100
    Thanks in advance...
    Rahul

    hi,
    follow these links to solve u r query.
    http://www.sapfans.com/forums/viewtopic.php?t=85191
    http://www.erpgenie.com/sapgenie/docs/Using%20ALV.pdf
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CAGTFLV/CAGTFLV.pdf
    regards,
    Ashokreddy.

  • Alv-subtotals texts

    hi all,
        i need to display the short texts of the field at the subtotals.for instance,for an order i need to sum up currency and i need to dispaly its short description at the subtotal column..for this i'm using layout-subtotals_text..
    and i'm sending the field to this alv field..
    Thanks in Advance.

    HI venkata
    for this you need to do using handlers
    in local classs , you need a event for sub total text,
    and set the handler for it, then sub total text will come.
    FORM method_subtotal_text USING es_subtottxt_info TYPE lvc_s_stxt
    ep_subtot_line TYPE REF TO data
    e_event_data TYPE REF TO
    cl_alv_event_data.
    DATA ls_sflight LIKE sflight.
    FIELD-SYMBOLS: <fs1> STRUCTURE sflight DEFAULT ls_sflight,
    <fs2>.
    IF es_subtottxt_info-criteria = 'PLANETYPE'.
    ASSIGN ep_subtot_line->* TO <fs1>.
    ASSIGN e_event_data->m_data->* TO <fs2>.
    CONCATENATE es_subtottxt_info-keyword ': '
    <fs1>-planetype INTO <fs2>.
    ENDIF.
    regards
    kishore

  • ALV - Subtotals with different waers

    Hello!
    I have a hierarquical ALV sorted by LIFNR and payments with the WRBTR and WAERS columns.
    WAERS can be 'ARS' 'USD' etc. for the same LIFNR.
    I want to display subtotals of WRBTR field for each LIFNR by WAERS.
    Can anyone help me please?
    Thanks,
    Liliana.

    Hi Liliana,
    Plz check this code .
    report  zxx_alvexer4    message-id zz        .
    *& TABLES DECLARATION                                                  *
    tables: vbak, vbap.
    *& TYPE POOLS DECLARATION                                              *
    type-pools: slis.
                          DATA DECLARATIONS                             *
    data: v_flag type c.                        "Flag to display the header
    data: v_repid type sy-repid.
    *& INTERNAL TABLE DECLARATION                                          *
    data: begin of it_vbak occurs 0,
           vbeln like vbak-vbeln,
           audat like vbak-audat,
           auart like vbak-auart,
           netwr like vbak-netwr,
           expand(1),
          end of it_vbak.
    data: begin of it_vbap occurs 0,
           vbeln like vbap-vbeln,
           posnr like vbap-posnr,
           matnr like vbap-matnr,
           pstyv like vbap-pstyv,
           charg like vbap-charg,
         end of it_vbap.
    data: it_fldcat type slis_t_fieldcat_alv,
          it_fldcat1 type slis_t_fieldcat_alv,
    *events
          it_events type slis_t_event with header line,
          v_call type c,
          x_user type  slis_exit_by_user,
          it_variant like  disvariant occurs 0 with header line,
          x_keyinfo type slis_keyinfo_alv,
    *layout
          x_layout type slis_layout_alv,
    *sort
          it_sort type slis_t_sortinfo_alv,
          wa_sort like line of it_sort,
          x_cat type slis_fieldcat_alv,
          v_tabix like sy-tabix.
          Selection screen Declaration
    *--BLOCK1
    selection-screen begin of block b1 with frame title text-001.
    select-options: s_vbeln for vbak-vbeln,
                    s_auart for vbak-auart.
    selection-screen end of block b1.
    AT SELECTION-SCREEN                                                 *
    *- Validations
    at selection-screen.
      perform validate_screen.
                  START OF SELECTION                                    *
    start-of-selection.
    *- To get data from VBAK
      perform get_data.
    *to get data from VBAP
      perform get_data_vbap.
      perform prepare_alv.
                  END OF SELECTION                                    *
    end-of-selection.
      perform display_report.
    *&      Form  VALIDATE_SCREEN
          text
    -->  p1        text
    <--  p2        text
    form validate_screen .
      data: lv_vbeln like vbak-vbeln,
            lv_auart like vbak-auart.
      if not s_vbeln[] is initial.
        select vbeln
               into lv_vbeln
               from vbak
               where vbeln in s_vbeln.
        endselect.
        if sy-subrc <> 0.
          message e000 with 'INVALID SALES DOC'(002).
        endif.
      endif.
      if not s_auart[] is initial.
        select auart
               into lv_auart
               from vbak
               where auart in s_auart.
        endselect.
        if sy-subrc <> 0.
          message e000 with 'INVALID SALES DOC TYPE'(003).
        endif.
      endif.
    endform.                    " VALIDATE_SCREEN
    *&      Form  GET_DATA
          text
    -->  p1        text
    <--  p2        text
    form get_data .
      select vbeln
             audat
             auart
             netwr
             from vbak
             into table it_vbak
             where vbeln in s_vbeln
             and auart in s_auart.
      if sy-subrc = 0.
        sort it_vbak by vbeln.
      endif.
    endform.                    " GET_DATA
    *&      Form  GET_DATA_VBAP
          text
    -->  p1        text
    <--  p2        text
    form get_data_vbap .
      select vbeln
             posnr
             matnr
             pstyv
             charg
             into table it_vbap
             from vbap
             for all entries in it_vbak
             where vbeln = it_vbak-vbeln.
      if sy-subrc = 0.
        sort it_vbap by vbeln posnr.
      endif.
    endform.                    " GET_DATA_VBAP
    *&      Form  prepare_alv
          text
    -->  p1        text
    <--  p2        text
    form prepare_alv .
    Prepare field catalog .
      perform prepare_catalog.
    Modify catalog
      perform change_attr_of_catalog.
    Modify Layout
      perform modify_layout.
    Sort Catalog
      perform sort_catalog.
    endform.                    " prepare_alv
    *&      Form  prepare_catalog
          text
    -->  p1        text
    <--  p2        text
    form prepare_catalog .
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
        exporting
          i_program_name         = sy-repid
          i_internal_tabname     = 'IT_VBAK'
          i_inclname             = sy-repid
        changing
          ct_fieldcat            = it_fldcat1[]
        exceptions
          inconsistent_interface = 1
          program_error          = 2
          others                 = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
      append lines of it_fldcat1 to it_fldcat.
      clear: it_fldcat1[].
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
        exporting
          i_program_name         = sy-repid
          i_internal_tabname     = 'IT_VBAP'
          i_inclname             = sy-repid
        changing
          ct_fieldcat            = it_fldcat1[]
        exceptions
          inconsistent_interface = 1
          program_error          = 2
          others                 = 3.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
      append lines of it_fldcat1 to it_fldcat.
    endform.                    " prepare_catalog
    *&      Form  change_attr_of_catalog
          text
    -->  p1        text
    <--  p2        text
    form change_attr_of_catalog .
      loop at it_fldcat into x_cat.
        v_tabix = sy-tabix.
        case x_cat-fieldname.
          when  'EXPAND'.
            if x_cat-tabname = 'IT_VBAK'.
              x_cat-no_out = 'X'.
            endif.
         when  'VBELN'.
           if x_cat-tabname = 'IT_VBAK'.
             x_cat-no_out = 'X'.
           endif.
          when  'VBELN'.
            if x_cat-tabname = 'IT_VBAK'.
              x_cat-col_pos   = '1'.
              x_cat-seltext_m = 'SALES DOC'.
              x_cat-seltext_l = 'SALES DOC'.
              x_cat-seltext_s = 'SALES DOC'.
              x_cat-outputlen = '10'.
            endif.
          when  'AUDAT'.
            if x_cat-tabname = 'IT_VBAK'.
              x_cat-col_pos   = '2'.
              x_cat-seltext_m = 'DOC DATE'.
              x_cat-seltext_l = 'DOC DATE'.
              x_cat-seltext_s = 'DOC DATE'.
              x_cat-outputlen = '8'.
            endif.
          when  'AUART'.
            if x_cat-tabname = 'IT_VBAK'.
              x_cat-col_pos   = '3'.
              x_cat-seltext_m = 'ORDER REASON'.
              x_cat-seltext_l = 'ORDER REASON'.
              x_cat-seltext_s = 'ORDER REASON'.
              x_cat-outputlen = '5'.
            endif.
          when  'NETWR'.
            if x_cat-tabname = 'IT_VBAK'.
              x_cat-col_pos   = '4'.
              x_cat-seltext_m = 'NET PRICE'.
              x_cat-seltext_l = 'NET PRICE'.
              x_cat-seltext_s = 'NET PRICE'.
              x_cat-outputlen = '15'.
            endif.
        endcase.
        modify it_fldcat from x_cat.
        clear x_cat.
      endloop.
    endform.                    " change_attr_of_catalog
    *&      Form  modify_layout
          text
    -->  p1        text
    <--  p2        text
    form modify_layout .
      x_layout-default_item = 'X'.
      x_layout-zebra = 'X'.
      x_layout-expand_fieldname = 'EXPAND'.
    endform.                    " modify_layout
    *&      Form  sort_catalog
          text
    -->  p1        text
    <--  p2        text
    form sort_catalog .
      clear wa_sort.
      wa_sort-spos = '01'.
      wa_sort-fieldname = 'VBELN' .
      wa_sort-tabname   = 'IT_VBAP'.
      wa_sort-up        = 'X'.
      append wa_sort to it_sort.
      clear  wa_sort.
      wa_sort-spos = '02'.
      wa_sort-fieldname = 'POSNR' .
      wa_sort-tabname   = 'IT_VBAP'.
      wa_sort-up        = 'X'.
      append wa_sort to it_sort.
    endform.                    " sort_catalog
    *&      Form  DISPLAY_REPORT
          text
    -->  p1        text
    <--  p2        text
    form display_report .
      it_variant-report = sy-repid.
      sort it_vbak by vbeln.
      sort it_vbap by vbeln posnr.
      call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
        exporting
          i_callback_program      = sy-repid
          is_layout               = x_layout
          it_fieldcat             = it_fldcat[]
          it_sort                 = it_sort
          is_variant              = it_variant
          it_events               = it_events[]
          i_tabname_header        = 'IT_VBAK'
          i_tabname_item          = 'IT_VBAP'
          is_keyinfo              = x_keyinfo
        importing
          e_exit_caused_by_caller = v_call
          es_exit_caused_by_user  = x_user
        tables
          t_outtab_header         = it_vbak
          t_outtab_item           = it_vbap
        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_REPORT
    Regards,
    Laxmi
    Message was edited by: Laxmi

  • Alv subtotals problem

    hi gurus i just want subtotals in my alv but it only sort the fields by NOACRE but no subtotals are shown
    what shold i do ? this is a portion of my source code my container is a docking container
    data gt_sort          type lvc_t_sort                 
    performs build_sortcat
    form build_sortcat .
    data wa_sort like line of gt_sort.
      wa_sort-spos      = 1    .
      wa_sort-fieldname = 'NOACRE'.
      wa_sort-subtot    = 'X'  .
      wa_sort-up        = 'X'.
      wa_sort-group = '01'.
      append wa_sort to gt_sort.
      clear wa_sort.
    endform.        
    create object custom_container
         exporting
           repid                       = sy-repid
           dynnr                       = sy-dynnr
           extension                   = 1500
         exceptions
           cntl_error                  = 1
           cntl_system_error           = 2
           create_error                = 3
           lifetime_error              = 4
           lifetime_dynpro_dynpro_link = 5
           others                      = 6.
      create object grid1
      exporting i_parent = custom_container.
      gs_variant-report =  sy-repid.
      gs_variant-variant = dispo.
      call method grid1->set_table_for_first_display
        exporting
          is_variant      = gs_variant
          i_save          = 'A'
          i_default       = 'X'
          is_layout       = gs_layout
        changing
          it_fieldcatalog = gt_fieldcat
          it_sort         = gt_sort[]
          it_outtab       = it_file[].
      call method grid1->set_ready_for_input
        exporting
          i_ready_for_input = 0.

    HI,
    Pass X to the DO_SUM in fieldcaltalog for the field's you want subtotal.

  • ALV Subtotals calculation - Urgent

    Hi All,
      How can I caliculate subtotals in ALV ?
      How to increase column size in alv?
    Regards

    Hi,
    Refer this code
    *&      Form  sub_display_data
          text
    FORM sub_display_data .
    *--To sort the output through material number
      DATA : lwa_sort TYPE slis_sortinfo_alv.
      DATA : lit_sort TYPE slis_t_sortinfo_alv.
    *--Pass the values to the table
      lwa_sort-fieldname = 'PERNR'.             "Field name in o/p inttable
      lwa_sort-tabname   = 'it_final2'.         "Output Internal table
      lwa_sort-spos      = '1'.                 "Sort  sequence
      lwa_sort-up        = 'X'.                 "Sort in ascending order
      lwa_sort-down      = ' '.                 "Sort in descending order
      lwa_sort-subtot    = 'X'.                 "Subtotal
      APPEND lwa_sort TO lit_sort.
    *--Pass the values to the table
      lwa_sort-fieldname = 'WORKDATE'.          "Field name in o/p inttable
      lwa_sort-tabname   = 'it_final2'.         "Output Internal table
      lwa_sort-spos      = '2'.                 "Sort  sequence
      lwa_sort-up        = 'X'.                 "Sort in ascending order
      lwa_sort-down      = ' '.                 "Sort in descending order
      lwa_sort-subtot    = ' '.                 "Subtotal
      APPEND lwa_sort TO lit_sort.
    *--Pass the values to the table
      lwa_sort-fieldname = 'WEKLY'.             "Field name in o/p inttable
      lwa_sort-tabname   = 'it_final2'.         "Output Internal table
      lwa_sort-spos      = '3'.                 "Sort  sequence
      lwa_sort-up        = 'X'.                 "Sort in ascending order
      lwa_sort-down      = ' '.                 "Sort in descending order
      lwa_sort-subtot    = ' '.                 "Subtotal
      APPEND lwa_sort TO lit_sort.
      wa_layout-colwidth_optimize = 'X'.       to increase collumn length
      IF NOT it_final2[] IS INITIAL.
    *--Call the function module to display the ALV report
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            is_layout          = wa_layout
            i_callback_program = v_repid
            it_fieldcat        = it_fieldcat1[]
            i_default          = c_chk
            i_save             = c_save
            it_sort            = lit_sort
          TABLES
            t_outtab           = it_final2
          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.
      ELSE.
    *--Message No data found
        MESSAGE i888 WITH text-017.
        LEAVE LIST-PROCESSING.
      ENDIF.
    ENDFORM.                    " sub_display_data
    Regards,
    Prashant

  • ALV Subtotals Description

    Hi,
    Can you please tell how to write subtotal text in ALV Report.
    770016     MTNL Gas     770018143     KGST     7/24/2005     DG     -157.77
    770016     MTNL Gas     770018203     KGST     7/24/2005     DG     -1,354.75
    770016     MTNL Gas     770018219     KGST     7/24/2005     DG     -499.26
    770016     MTNL Gas     770018220     KGST     7/17/2005     DG     -609.34
    770016     MTNL Gas     770018253     KGST     7/24/2005     DG     -332.84
    770016     MTNL Gas     770018257     KGST     7/24/2005     DG     -630.05
    770016     MTNL Gas     770018299     KGST     7/31/2005     DG     -158.01
    770016     A/R Open Balances                     (3,742.02)
    770016     Unapplied Customer Credits     3,742.02                 
    Please let me know how to write description <b>A/R Open</b> <b>Balances(Debit)</b> and <b>Unapplied Customer</b> <b>Credits(Credit)</b> for the subtotals in ALV.
    Thanks in advance.
    Regards,
    Baba.

    hi
    try this out this may help u.............
    populate Table IT_SORT with the sort criteria for the different fields.
    sorting and subtotaling are specified by the caller in the internal table I_SORT.
    call this function and mention the fields.

  • ALV Report - Average and Grand total.

    Hi,
    Could you tell me in ALV, how i can calculate the average of a particular field and display it in the grand total row?
    What is the property to display the grand total alone, without the subtotal?

    To force a grand total line, first you need to have a field in your internal table that can be totaled, when defining that field in your field catalog, you must set the flag for DO_SUM = 'X',  you may also need to set the DATATYPE = 'QUAN'.  Then the grand total line will show automatically.
    Regards,
    RIch Heilman

  • ALV Subtotals - how to compress them all?

    This question is not about ABAP programming, but about ALV interface.
    SE16, choose a table of interest, ALV Grid Display, display some data. Then, sort by a column, sum, and then subtotal by sorted column.
    There is a little icon on the subtotal row that I can click on and toggle the details to compress and expand. Unfortunately, I have to do that manually on every subtotal row to compress all the results.
    Is there a quick way to compress them all?
    Thank you.

    Hi,
    I checked it in SE16N not SE16.  Anyhow right now I can see that this option (subtotals dropdown list) is swithed off in classical ALV grid (REUSE_ALV_GRID_DISPLAY) but comes with OO ALV grid (CL_GUI_ALV_GRID), so I am affraid you will have to use the second in case you want that functionality.
    Regards
    Marcin

  • ALV tree -average

    Hi ,
    i am doing a alv tree display. in which i want to display the average amount .but i find only do_sum. is there any possiblity to do average.
    thanks,
    madhu

    In the 'end_of_list' event of the ALV you can calculate the avarage and display.
    Ex:
    call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
                i_callback_top_of_page   = 'TOP-OF-PAGE' 
                i_callback_html_end_of_list = 'END_OF_LIST_HTML'
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
                i_save                  = 'X'
           tables
                t_outtab                = it_ekko
           exceptions
                program_error           = 1
                others                  = 2.
    *&      Form  end_of_list_html
          output at the end of the list - not in printed output       *
    FORM end_of_list_html USING end TYPE REF TO cl_dd_document.
       calculate the avarage and display.
    ENDFORM. "end_of_list_html.

  • ALV GRID AVERAGE WEIGHTNESS

    Hi, how can we do aaverage weightness in alv grid on grouped levels records.
    EX:
    level group 1       level group2     qty              price          average weightness
    PL1                    GR1                10              30              (10*30)/23
    PL1                    GR1                13              32              (13*32)/23
                 subtotal GR1                23              62               31,13
    PL1                    GR2                10              25              (10*25)/25
    PL1                    GR2                15              28              (15*28)/25
                  subtotal GR2                25              53               26,8
    THANX.

    I think you will have to handle this in a program and populate new columns AVERAGE. I am afraid to say i did not find any functionality for AVERAGE in ALV.
    ashish

  • Hierarchical alv subtotals

    HI,
    i am trying to print the subtotals in hierarchical sequential alv.
    i have written some code.but in that it is not showing the subtotals by default.for subtotals i am selecting a column in header and pressing the subtotals button.then only it is showing subtotals.
    how can i show the subtotals by default(without selecting any column and subtotals button)
    regards,
    Hi

    Please help me on this issue: i want grand total on end of every column for example field 'metric-safety'
    'metric-avtual'. very urgent. thanks in advance
    TYPE-POOLS : slis.
    Tables : Marc,                      " Plant Data for Material
             Mbew,                      " Material Valuation
             Ekpo,                      " Purchasing Document Item
             Eord,                      " Purchasing Source List
            Zpmt.                      " Purchasing Metric Table
    --Internal Tables Declaration--
    Data : Begin of metric occurs 0,
           matnr like marc-matnr,        " Material number
           werks like marc-werks,        " Plant
           minbe like marc-minbe,        " Recoder Point
           eisbe like marc-eisbe,        " Safety Stock
           stprs like mbew-stprs,        " Standard Price
           lifnr like eord-lifnr,        " Vendor
           menge like ekpo-menge,        " PO Quantity
           scalc type p decimals 2,
           safety(20) type c,
           tcalc type p decimals 2,
           Target(20) type c,
           acalc type p decimals 2,
           actual(20) type c,
           ecalc type p decimals 2,
           excess(20) type c,
           ucalc type p decimals 2,
           usafety(20) type c,
    *******Custom table
           inscr like zpmt-inscr,        " Inventory Score
           stkot like zpmt-stkot,        " Stock Out
           impct like zpmt-impct,        " Impact
           nafta like zpmt-nafta,        " %nafta
           stscr like zpmt-stscr,        " Stock Out Score
           end of metric.
    Data : final like metric occurs 0 with header line.
    DATA: fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    **Data : Begin of output occurs 0,
          lifnr like eord-lifnr,        " Vendor
          eisbe like marc-eisbe,        " Safety Stock
          minbe like marc-minbe,        " Re-order Point
          stprs like mbew-stprs,        " Standard Price
          sstock(13) type c,            " Value of Safety Stock
          Actual(13) type c,            " Actual
          Excess(13) type c,            " Excess Inv
          underSs(13) type c,           " Under Safety Stock
          end of output.
    --Data type  Declaration--
    Data : a type c value '$'.
    Data : safety(20) type c,
            target(20) type c,
            actual(20) type c,
            excess(20) type c,
            usafety(20) type c,
            repid like sy-repid.
    data : i_pos type i.
    --Selection Screen--
    selection-screen : begin of block b1 with frame Title tname.
    Select-options:    Mat for marc-matnr,  " Material Number Selection
                       Plt for marc-werks,  " Plant Selection
                       Vdr for eord-lifnr.  " Vendor Selection
    selection-screen : end of block b1.
    --Initialization--
    initialization.
    tname = 'Purchasing Metric Report'.
    --At Selection-Screen--
    At selection-screen.
    IF mat = ' ' and  Plt = ' ' and Vdr = ' '.
    message e000.
    *elseif mat <> metric-matnr.
    *message e001.
    *elseif plt <> metric-werks.
    *message e002.
    *elseif vdr <> metric-lifnr.
    *message e003.
    endif.
    --Start-of-Selection--
    Start-of-selection.
    *******For Data Retrival
           Perform Data_retrival.
    *******For Calculation
            Perform Calculation.
    *******For Building Fieldcatalog
            Perform Build_fieldcatalog.
    *******Alv Display
            Perform Alv_display.
    *&      Form  Get_Data
          text
    FORM Data_retrival .
    SELECT a~matnr
           a~werks
           a~eisbe
           a~minbe
           b~matnr
           b~stprs
           c~matnr
           c~lifnr
           d~matnr
           d~menge
                  into corresponding fields of table metric from
                  (  ( ( marc as a inner join mbew as b on bmatnr = amatnr )
                         inner join eord as c on cmatnr = amatnr )
                         inner join ekpo as d on dmatnr = amatnr )
                         where amatnr in mat and awerks in plt and c~lifnr in vdr.
                         if sy-subrc = 0.
                            sort metric by matnr.
                            endif.
    ENDFORM.                    " Get_Data
    *&      Form  Calculation
          text
    FORM Calculation .
    loop at metric.
    ******calculation for safety stock ( safety stock * standard price )
    metric-scalc = metric-eisbe * metric-stprs.
    move metric-scalc to safety.
    condense safety.
    concatenate a safety into metric-safety.
    ******calculation for target ( safety stock + standard price )
    metric-tcalc = ( metric-eisbe * metric-stprs ) + metric-stprs.
    move metric-tcalc to target.
    condense target.
    concatenate a target into metric-target.
    ******calculation for Actual ( Po quantity  * standard price )
    metric-acalc = metric-menge * metric-stprs.
    move metric-acalc to actual.
    condense actual.
    concatenate a actual into metric-actual.
    ******calculation for Excess Inv ( Actual - Target )
    metric-ecalc = ( metric-menge * metric-stprs ) - ( ( metric-eisbe * metric-stprs ) + metric-stprs ).
    move metric-ecalc to excess.
    condense excess.
    concatenate a excess into metric-excess.
    ******calculation for Under Safety Stock ( actual < safety stock. then actual + safety stock (Else) zero )
       if actual < safety.
    metric-menge * metric-stprs <   metric-eisbe * metric-stprs.
        metric-ucalc =  ( metric-menge * metric-stprs ) + ( metric-eisbe * metric-stprs ).
        else.
        metric-ucalc = 0.
        endif.
    move metric-ucalc to usafety.
    condense usafety.
    concatenate a usafety into metric-usafety.
    collect metric into final.
    endloop.
    ENDFORM.                    " Calculation
    *--End-for-Selection--
    *end-of-selection.
    *loop at final.
    *write : / final-lifnr, final-safety, final-target, final-actual, final-excess, final-usafety.
    *endloop.
    *&      Form  Build_fieldcatalog
          text
    -->  p1        text
    <--  p2        text
    FORM Build_fieldcatalog .
      fcat-fieldname   = 'LIFNR'.
      fcat-seltext_m   = 'Vendor'.
    fcat-col_pos     = i_pos.
      fcat-outputlen   = 10.
      fcat-emphasize   = 'X'.
      fcat-key = 'X'.
    fcat-do_sum = 'X'.
    fcat-edit = 'X'.
      append fcat to fcat.
      clear  fcat.
    i_pos = i_pos + 1.
      fcat-fieldname   = 'SAFETY'.
      fcat-seltext_m   = 'Safety Stock'.
      fcat-col_pos     = 2.
      fcat-outputlen   = 10.
      fcat-emphasize   = 'X'.
      fcat-do_sum = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
        fcat-fieldname   = 'ACTUAL'.
      fcat-seltext_m   = 'Actual'.
      fcat-col_pos     = 3.
      fcat-outputlen   = 10.
      fcat-emphasize   = 'X'.
      fcat-do_sum = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
        fcat-fieldname   = 'TARGET'.
      fcat-seltext_m   = 'Target'.
      fcat-col_pos     = 4.
      fcat-outputlen   = 10.
      fcat-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
        fcat-fieldname   = 'EXCESS'.
      fcat-seltext_m   = 'Excess Inv'.
      fcat-col_pos     = 5.
      fcat-outputlen   = 10.
      fcat-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
      fcat-fieldname   = 'USAFETY'.
      fcat-seltext_m   = 'Under Safety Stock'.
      fcat-col_pos     = 6.
      fcat-outputlen   = 20.
      fcat-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
      fcat-fieldname   = 'INSCR'.
      fcat-seltext_m   = 'Iventory Score'.
      fcat-col_pos     = 7.
      fcat-outputlen   = 20.
      fcat-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
      fcat-fieldname   = 'STKOT'.
      fcat-seltext_m   = 'Stock Out'.
      fcat-col_pos     = 6.
      fcat-outputlen   = 20.
      fcat-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
      fcat-fieldname   = 'IMPCT'.
      fcat-seltext_m   = 'Impact'.
      fcat-col_pos     = 6.
      fcat-outputlen   = 20.
      fcat-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
      fcat-fieldname   = 'NAFTA'.
      fcat-seltext_m   = '%Nafta'.
      fcat-col_pos     = 6.
      fcat-outputlen   = 20.
      fcat-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
      fcat-fieldname   = 'STSCR'.
      fcat-seltext_m   = 'Safety Out Score'.
      fcat-col_pos     = 6.
      fcat-outputlen   = 20.
      fcat-emphasize   = 'X'.
    fieldcatalog-key         = 'X'.
      append fcat to fcat.
      clear  fcat.
    ENDFORM.                    " Build_fieldcatalog
    *&      Form  Alv_display
          text
    -->  p1        text
    <--  p2        text
    FORM Alv_display .
    repid = sy-repid.
    *CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK              = ' '
      I_BYPASSING_BUFFER             =
      I_BUFFER_ACTIVE                = ' '
      I_CALLBACK_PROGRAM             = repid
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
      I_STRUCTURE_NAME               =
      IS_LAYOUT                      =
      IT_FIELDCAT                    = fcat[]
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
      IT_SORT                        =
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      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
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
    TABLES
       T_OUTTAB                       = 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.
    repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = repid
               i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
               i_callback_user_command = 'USER_COMMAND'
               i_grid_title           = outtext
               is_layout               = gd_layout
                it_fieldcat             = fcat[]
               it_special_groups       = gd_tabgroup
               it_events               = gt_events
               is_print                = gd_prntparams
               i_save                  = 'X'
               is_variant              = z_template
           tables
                t_outtab                = 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.
    regards
    sat

Maybe you are looking for