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

Similar Messages

  • 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 - 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

  • 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 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

  • 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

  • Alv subtotals  and grand total for a field

    Hi friends,
    I Have an internal table ITAB1
    in that i have a senario as below.
    In my GRID display iam getting values in the layou as follows
    BUKRS =  1000
    LIFNR      MATNR     STCST
    100          abc            500,00
    100          pqr             400,00
    100          xyz            200,00
                        sub total
    200         pto              700,00
    200         vbr              900,00
                        sub total
    BUKRS =  2000
    LIFNR      MATNR     STCST
    150          abc            500,00
    150          pqr             400,00
    150          xyz            200,00
                        sub total
    260         pto              700,00
    260         vbr              900,00
                        sub total
              GRAND TOTAL = 
    Now my requirement is at the end of every vendor  i need sub total for STCST field.
    and at the end of every company code i need GRAND TOTAL for STCST field.
    Its alv grid display.
    how can i do that.
    Regards,
    Priyanka.

    Check this sample code may it will help u:
    *& 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
    Edited by: Joyjit Ghosh on Aug 21, 2008 5:25 PM

  • ALV subtotals using methods

    Hi
    Please provide me sample code for subtotals using methods.
    The code is
    DATA: ls_sort TYPE lvc_s_sort.
    ls_sort-spos = '1' .
    ls_sort-fieldname = 'BWART'.
    ls_sort-up = 'X'.
    ls_sort-subtot = 'X'.
    *ls_sort-group = 'UL'.
    APPEND ls_sort TO p_gt_sort.
    endform
    but it is not working
    Please help me

    Hi,
    this is how you should do...
    CLASS lcl_event_handler DEFINITION DEFERRED.
    DATA: dg_events_receiver TYPE REF
                                TO lcl_event_handler.  "event receiver
    *       CLASS lcl_event_handler DEFINITION
    *       For Event handling                                             *
    CLASS lcl_event_handler DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS:
           subtotal_text        FOR EVENT subtotal_text
                             OF cl_gui_alv_grid
                             IMPORTING es_subtottxt_info
                                       ep_subtot_line
                                       e_event_data.
    ENDCLASS.                    "VERIFY_EVENT_HANDLER DEFINITION
    *       CLASS lcl_event_handler IMPLEMENTATION
    *       Implementation of event handler method                        *
    CLASS lcl_event_handler IMPLEMENTATION.
      METHOD subtotal_text.
        PERFORM d0100_event_subtotal_text USING es_subtottxt_info
                                                ep_subtot_line
                                                e_event_data.
      ENDMETHOD.                    "subtotal_text
    ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
    *--set event handler
      PERFORM set_event_handler.
      CALL METHOD dg_grid->set_table_for_first_display
        EXPORTING
          is_layout                     = ds_layout
        CHANGING
          it_outtab                     = <fs_f>
          it_fieldcatalog               = dt_alv_cat
          it_sort                       = dt_sort
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc <> 0.
        MESSAGE i000 WITH
             'Error in calling SET_TABLE_FOR_FIRST_DISPLAY'(026).
      ENDIF.
    *&      Form  set_event_handler
    *       event handler
    *  -->  p1        text
    *  <--  p2        text
    FORM set_event_handler .
      CREATE OBJECT dg_events_receiver.
      SET HANDLER dg_events_receiver->subtotal_text
                  FOR dg_grid.
    ENDFORM.                    " set_event_handler
    *&      Form  d0100_event_subtotal_text
    *       To handle subtotal text event
    *      -->P_ES_SUBTOTTXT_INFO  text
    *      -->P_EP_SUBTOT_LINE  text
    *      -->P_E_EVENT_DATA  text
    FORM d0100_event_subtotal_text  USING
                            p_es_subtottxt_info TYPE lvc_s_stxt
                           p_ep_subtot_line TYPE REF TO data
                           p_e_event_data TYPE REF TO cl_alv_event_data .
      FIELD-SYMBOLS: <fs> TYPE ANY.
      ASSIGN p_e_event_data->m_data->* TO <fs>.
      <fs> = 'TOTAL'(027).
    ENDFORM.                    " d0100_event_subtotal_text
    Regards
    vijay

  • Problem with alv subtotals

    i have problem with subtotals display in AVL
    actually my code is
    FORM fill_field_catalog_table USING  f d  t s I.
      DATA t_fld TYPE slis_fieldcat_alv.
      STATICS pos LIKE sy-index VALUE 0.
      pos = pos + 1.
      CLEAR t_fld.
      MOVE 1 TO   t_fld-row_pos.
      MOVE pos TO t_fld-col_pos.
      MOVE f TO   t_fld-fieldname.
      MOVE d TO   t_fld-seltext_m.
      MOVE t TO   t_fld-tabname.
      MOVE s TO   t_fld-do_sum.
      MOVE I TO   t_fld-NO_OUT.
      if not t_fld-NO_OUT is initial.      "based on a condition i am appendding the fieldcatlog
       APPEND t_fld TO it_fieldcat.
      endif.
    if i remove "if not t_fld-NO_OUT is initial."  this condition and append the fieldcat....
    subtotals is getting dispalyed.
    if i insert this code subtotals is not getting displayed...
    can any body help me out in this fashion...
    any input are required please fell free to contact me.
    madan

    Hi Madan,
    NO_OUT value range is 'SPACE' and 'X'
    check if u have gone wrong there
    SPACE is not same as INITIAL.
    Also go through the following piece of code..
    Execute it, u will understand it. At places comments will help u to understand better.
    *& Report  ZRAJ_SUBTOTAL_ALV
    REPORT  ZRAJ_SUBTOTAL_ALV.
    TYPE-POOLS: SLIS.
    DATA: G_REPID LIKE SY-REPID,
          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.
    INITIALIZATION.
      G_REPID = SY-REPID.
    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_CATALOG.
      PERFORM ALV_DISPLAY.
    *&      Form  build_catalog
    *       text
    FORM BUILD_CATALOG.
      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-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'. "This is an important statement
      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'. "Note: This should be commented
      APPEND GS_SORT TO GT_SORT.
    ENDFORM.                    "build_catalog
    *&      Form  alv_display
    *       text
    FORM ALV_DISPLAY.
      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 =
    * 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 = ITAB1
      EXCEPTIONS
      PROGRAM_ERROR = 1
      OTHERS = 2.
    ENDFORM.                    "alv_display
    hope this will solve your problem
    Regards Rajan.

  • ALV  SUBTOTALS TEXTS: how can we use 'slis_subtot_text' structure

    hi
    in SLIS type pool
    there is a structure
    <b>slis_subtot_text</b>
    i think this for custom subtotal texts
    other that standard
    but how do we use it
    where is this structure to be given as parameter

    Hi Srikant,
    You can use the subtotal text in ALV.
    Before using the subtotal,. you have to sort the List using the field for which total has to be calculated.
    DATA: lt_sort       TYPE slis_t_sortinfo_alv.
      DATA: lw_sort       TYPE slis_sortinfo_alv.
      CONSTANTS:
            lc_value_x                   TYPE  ebstyp                VALUE 'X'.
      v_repid = sy-repid.
      lw_sort-fieldname = fieldname.
      lw_sort-up = lc_value_x.
      lw_sort-subtot = lc_value_x.
    lw_sort-stext  = 'Subttotal'.
      APPEND lw_sort TO lt_sort.
    *call function to display the report
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = v_repid
          i_callback_top_of_page  = 'TOP_OF_PAGE'
          it_fieldcat             = ut_fieldcattab
          it_sort                 = lt_sort
        TABLES
          t_outtab                = ct_output_values_tab
        EXCEPTIONS
          program_error           = 1
          OTHERS                  = 2.
    Regards,
    Yogesh

Maybe you are looking for