ALV Grid sub total issue

Hi SAP Experts,
Currently I have ALV Grid table as below as example :
FIELD1
FIELD2
Account
Amount
1. Rev
1.Rev
Acct1
100.00
1. Rev
1.Rev
Acct2
50.00
Subtotal FIELD2 (1.Rev)
150.00
Subtotal FIELD1 (1.Rev)
150.00
2. Cost
2.1 Cost1
Acct3
100.00
2. Cost
2.1 Cost1
Acct4
75.00
Subtotal FIELD2  (2.1 Cost1)
175.00
2. Cost
2.2 Cost2
Acct5
25.00
Subtotal FIELD2 (2.2 Cost 2)
25.00
| Subtotal FIELD1 (2.Cost)                | 200.00             |          
I have 2 questions.
First, as you can see, I have 2 subtotal for 1.Rev eventhough 1.Rev actually only need one subtotal because there is no subgroup for 1.Rev. Is it possible to have only one subtotal for this 1.Rev but I still maintained 2 subtotal for 2.Cost because 2.Cost has subgroup?
My 2nd issue is I need to insert another row exactly below Subtotal FIELD1 (2.Cost) row like this:
Gross Margin
(Some formula)
This row does not come from any sub total. The problem is I can not just insert this column and put Gross Margin description in FIELD1 because I will have 3 row like below :
Gross Margin
(Formula)
Subtotal FIELD2 (blank)
(Formula) sub total
Subtotal FIELD1 (Gross Margin)
(Formula) sub total
Is there any way I can insert Gross Margin Row without creating new subtotal for it so it will only have one line in the ALV Grid table? Please help. Thank you.
Regards,
Abraham

Hi Vijay.
I'm not posting this before I search everywhere and this is not the first time I post in this forum so I know what I should do before posting. If I miss something, maybe you can give me at least a hint whether it can be done or not.
This report that I am using is ALV Grid using REUSE_ALV_GRID_DISPLAY function module and not OOP using dialog module. I never said I need sample code because I only want to know is there a way to do that using ALV Grid which until now I will say that SAP ALV grid has this limitation where you can not insert row without including it in the subtotal.
So, I would be very thankful if someone can give me some clarity on this thing and Vijay, if you really don't know what is the answer, I really appreciate if you can hold your self from making that kind of reply. It does not need experienced ABAP Consultant to write such remarks. Thanks.
Regards,
Abraham

Similar Messages

  • ALV grid sub-totals

    Hi All,
          I have written a code to show sub totals in ALV.
    But, is there any way by which I can show *Only the sub total
    lines* and not the individual line items that form the sub total ?
    e.g.:-
    KeyField1  KeyField2  Field1  Field2
    A                  1             10       12
    A                  1             15         8
    SUBTOTAL                 25       20
    B                  2             15       12
    SUBTOTAL                 15       12
    C                  1             10         8
    C                  2               8        12
    C                  3               7         2
    SUBTOTAL                  25       22
    Now I want only the SUBTOTAL rows to be visible in ALV not the individual rows as follows :-
    KeyField1  KeyField2  Field1  Field2
    SUBTOTAL                 25       20
    SUBTOTAL                 15       12
    SUBTOTAL                  25       22
    Regards,
    Ashish

    hi check this..in this only subtotals are shown if u click on the subtotal it will show the detailed list for that subtotal..
    *& Report  ZVG_ALV_SLIST2                                              *
    report  zvg_alv_slist2                          .
    ALV
    type-pools: slis.
    G L O B A L   I N T E R N  A L   T A B L E S
    data: gt_fieldcat type slis_t_fieldcat_alv,
          gs_layout   type slis_layout_alv,
          gt_events   type slis_t_event.
    data: it_sort type slis_t_sortinfo_alv ,
          wa_sort type slis_sortinfo_alv .
    data: gs_print type slis_print_alv.
    data: begin of it_sflight occurs 0,
            carrid     like sflight-carrid,
            connid     like sflight-connid,
            fldate     like sflight-fldate,
            price      like sflight-price,
            planetype  like sflight-planetype,
            seatsmax   like sflight-seatsmax,
            seatsocc   like sflight-seatsocc,
            paymentsum like sflight-paymentsum,
         end of it_sflight.
    *DATA: GI_SFLIGHT LIKE STANDARD TABLE OF ST_SFLIGHT.
    data: g_repid like sy-repid.
    data: gt_list_top_of_page type slis_t_listheader.
    data: v_total(5).
    start-of-selection.
      g_repid = sy-repid.
      perform init_fieldcat  using gt_fieldcat[].
      perform build_eventtab using gt_events[].
      perform build_comment  using gt_list_top_of_page[].
      perform get_data.
      perform set_layout using gs_layout.
    SORTING
      clear wa_sort.
      wa_sort-fieldname = 'CARRID'.
      wa_sort-up = 'X'.
      wa_sort-group = '*'.
      wa_sort-subtot = 'X'.
      append wa_sort to it_sort.
      clear wa_sort.
      wa_sort-fieldname = 'CONNID'.
      wa_sort-up = 'X'.
      wa_sort-group = 'UL'.
      wa_sort-subtot = 'X'.
      append wa_sort to it_sort.
    DISPLAY LIST
      call function 'REUSE_ALV_LIST_DISPLAY'
        exporting
          i_interface_check       = ' '
          i_callback_program      = g_repid
          i_callback_user_command = 'USER_COMMAND'
          is_layout               = gs_layout
          it_fieldcat             = gt_fieldcat[]
          it_sort                 = it_sort[]
          it_events               = gt_events
          is_print                = gs_print
        tables
          t_outtab                = it_sflight
        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.
    *&      Form  INIT_FIELDCAT
    form init_fieldcat using    p_gt_fieldcat type slis_t_fieldcat_alv.
      data: ls_fieldcat type slis_fieldcat_alv,
            l_index type sy-tabix.
      data :rep like sy-repid.
      rep = sy-repid.
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
        exporting
          i_program_name         = rep
          i_internal_tabname     = 'IT_SFLIGHT'
          i_inclname             = rep
        changing
          ct_fieldcat            = gt_fieldcat
        exceptions
          inconsistent_interface = 1
          program_error          = 2
          others                 = 3.
      if sy-subrc <> 0.
        message id sy-msgid type 'S' number sy-msgno
             with sy-msgv1 sy-msgv2 sy-msgv3 sy-subrc.
      endif.
      sort gt_fieldcat by col_pos.
      loop at gt_fieldcat into ls_fieldcat.
        l_index = sy-tabix.
        if ls_fieldcat-fieldname = 'PRICE'.
          ls_fieldcat-do_sum = 'X'.
          ls_fieldcat-sp_group = 'X'.
          modify gt_fieldcat from ls_fieldcat index l_index .
        endif.
      endloop.
    endform.                    " INIT_FIELDCAT
    *&      Form  BUILD_EVENTTAB
    form build_eventtab using  p_gt_events type slis_t_event.
      data: ls_event type slis_alv_event.
      clear ls_event.
      ls_event-name = slis_ev_top_of_page.
      ls_event-form = 'XTOP_OF_PAGE'.
      append ls_event to p_gt_events.
      clear ls_event.
      ls_event-name = slis_ev_top_of_list.
      ls_event-form = 'XTOP_OF_LIST'.
      append ls_event to p_gt_events.
      clear ls_event.
      clear ls_event.
      ls_event-name = slis_ev_end_of_page.
      ls_event-form = 'XEND_OF_PAGE'.
      append ls_event to p_gt_events.
      ls_event-name = slis_ev_end_of_list.
      ls_event-form = 'XEND_OF_LIST'.
      append ls_event to p_gt_events.
      clear ls_event.
    endform.                    " BUILD_EVENTTAB
    *&      Form  BUILD_COMMENT
    form build_comment using   p_gt_list_top_of_page type slis_t_listheader.
      data: ls_line type slis_listheader.
      ls_line-typ = 'H'." = Header, S = Selection, A = Action
      ls_line-key = 'KEY'.
      ls_line-info = 'INFO'.
      append ls_line to p_gt_list_top_of_page.
    endform.                    " BUILD_COMMENT
    *&      Form  SELECTION
    form get_data..
    data: l_rows type i value 3.
    Read data from table SFLIGHT
      select carrid
             connid
             fldate
             price
             planetype
             seatsmax
             seatsocc
             paymentsum
         from sflight
         into table it_sflight.
        up to l_rows rows.
      sort it_sflight.
    endform.                    " SELECTION
    *&      Form  SET_LAYOUT
    form set_layout using  p_gs_layout type slis_layout_alv.
    *  P_GS_LAYOUT-F2CODE            = P_F2CODE.
      p_gs_layout-zebra          = 'X'.
      p_gs_layout-colwidth_optimize = 'X'.
      p_gs_layout-no_input          = 'X'.
      p_gs_layout-no_colhead        = space.
      p_gs_layout-totals_text       = 'Total Price'.
      p_gs_layout-subtotals_text    = 'Sub Total'.
      p_gs_layout-totals_only       = 'X'.
      p_gs_layout-key_hotspot       = 'X'.
      p_gs_layout-detail_popup      = 'X'.
      p_gs_layout-no_subtotals      = space.
      p_gs_layout-expand_all        = 'X'.
      p_gs_layout-group_buttons     = 'X'."space.
    endform.                    " SET_LAYOUT
          FORM XTOP_OF_PAGE                                             *
    form xtop_of_page.
    data : lv_page(5),
            lv_text(20).
      MOVE SY-PAGNO TO LV_PAGE.
      write:/  'X_TOP_OF_PAGE'.
    endform.                    "xtop_of_page
          FORM XTOP_OF_LIST                                             *
    form xtop_of_list.
      write:/  'X_TOP_OF_LIST'.
    endform.                    "xtop_of_list
          FORM XEND_OF_PAGE                                             *
    form xend_of_page.
      write:/  'X_END_OF_PAGE'.
    endform.                    "xend_of_page
          FORM XEND_OF_LIST                                             *
    form xend_of_list.
      write:/  'X_END_OF_LIST'.
      data : lv_page(5),
             lv_text(20).
      data : l_lines type i,
             l_line  type i.
      clear v_total.
      write sy-pagno to v_total left-justified.
    export v_total to memory id 'V_TOTAL'.
      do sy-pagno times.
        lv_page = sy-index.
        concatenate 'Page' lv_page 'of' v_total
             into lv_text separated by space.
        if sy-index = 1.
          read line 2 of page sy-index.
        else.
          read line 1 of page sy-index.
       endif.
        sy-lisel+60(20) = lv_text.
          modify current line .
      enddo.
    endform.                    "xend_of_list
          USER_COMMAND                                             *
    form user_command  using r_ucomm like sy-ucomm
                              rs_selfield type slis_selfield.
      case r_ucomm.
        when 'EXIT'.
          leave to screen 0.
        when '&IC1'.
          data: text(256),text1(6),text2(5).
          move rs_selfield-tabindex to text1.
          move rs_selfield-sumindex to text2.
          concatenate  'Double clicked on (field:'
                        rs_selfield-fieldname
                        'Value:'
                        rs_selfield-value
                        text1
                        text2
                        into text
                        separated by space.
          call function 'POPUP_TO_DISPLAY_TEXT'
            exporting
              textline1 = text.
      endcase.
    endform.                    "user_command
    regards,
    venkat.

  • Alv Grid Sub Total

    Hi All
           I am have done an object in alv grid where it is working fine but what i want i am giving a sample please do let tell me how to do
    OUTPUT
    DATE       TIME-ENTRY  ACM-NO   CHARG    SHIFT   MACHINE-SPEED STANDARD-D    ACTUALL-DIPS   DOWNTIME-MINS  DOWN-TIME-IN%
    2009/08/23 00:45:41    ACMA01   910808   B             27.090      2,167           2,120              10            2.08
    2009/08/23 08:38:45    ACMA01   910808   C             27.090      2,167           1,459             157           32.71
                                    910808                             4,334           3,579             167
    2009/08/23 08:51:59    ACMA01   910809   C             27.090      2,167             141             449           93.54
    2009/08/23 17:24:39    ACMA01   910809   A             27.090      2,167           2,113              12            2.50
                                    910809                             4,334           2,254             461
    2009/08/23 00:48:56    ACMA02   920810   B             25.700      2,056           2,015              10            2.08
    2009/08/23 09:07:02    ACMA02   920810   C             25.700      2,056           2,043               3            0.63
    2009/08/23 17:27:04    ACMA02   920810   A             25.700      2,056             421             382           79.58
    2009/08/23 17:27:12    ACMA02   920810   A             25.700      2,056             421             382           79.58
                                    920810                             8,224           4,900             777
    2009/08/23 17:30:12    ACMA02   920811   A             25.700      2,056           1,335             168           35.00
                                    920811                             2,056           1,335             168
    In Down time in %  i want to do a bit of calculation
        X = 3579(ACCTUALL DIPS)/4334(STANDARD DIPS)    
        X = .0852 * 100 = 82.5 - 100
        X = -17.4%( This should display in DOWN-TIME-IN%)
    This will be Similar Calculation only number of lines will reduce to make it clear i gave in this way
    Waiting for Reply
    Thank's In Advance
    Sravya
    Edited by: Sravya Ch on Aug 24, 2009 7:41 AM

    Hi Rajihta
           I think you did not under stand what I want clearly
      DATE       TIME-ENTRY  ACM-NO   CHARG    SHIFT   MACHINE-SPEED STANDARD-D    ACTUALL-DIPS   DOWNTIME-MINS  DOWN-TIME-IN
      2009/08/23 00:45:41    ACMA01   910808   B             27.090      2,167           2,120              10            2.08
      2009/08/23 08:38:45    ACMA01   910808   C             27.090      2,167           1,459             157           32.71
    *                                 910808                             4,334           3,579             167            *17%*
    So how to do for  that 17% .i have just eneterd it now(every thing is from SAP other than that 17%)

  • Web Dynpro ALV grid sub totals

    Hi,
    I have managed to get totals working with web dynpro ALV using code like this :
      DATA: lr_field TYPE REF TO cl_salv_wd_field.
    For total calculations...
      lo_value->if_salv_wd_std_functions~set_aggregation_allowed( abap_true ).
      lr_field = lo_value->if_salv_wd_field_settings~get_field( 'N_OF_DLRS' ).
      lr_field->if_salv_wd_aggr~create_aggr_rule( aggregation_type = if_salv_wd_c_aggregation=>aggrtype_total ).
    Please can someone advise how i can do subtotals also.  Thanks
    Edited by: Samir Vora on Jul 15, 2009 12:40 PM

    Hi,
    For creating subtotals, you can have a look at following article:
    [Tutorial for Creation Subtotals using ALV|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/user-interface-technology/wd%20abap/tutorial%20for%20creating%20totals%20and%20subtotals%20using%20alv.pdf].
    Hope this helps.
    Regards
    Manas Dua

  • ALV GRID: Sub Total of a field

    Hi All,
    Currently I am getting O/P in the following format:
    CURRENCY    QUANTITY    VALUE
        GBP                 1               10
        GBP                 2               15
         INR                 1                12
    I want the output to be:  
    CURRENCY    QUANTITY    VALUE
        GBP                 1               10
        GBP                 2               15
        GBP                                     25
        INR                 1                12
        INR                                       12
    I have already tried with:
    wa_fieldcatalog-fieldname  = 'VALUE'.
    wa_fieldcatalog-do_sum = 'X'.
    and,
    clear wa_sort.
    wa_sort-spos      = 1.
    wa_sort-fieldname = 'VALUE'.
    wa_sort-expa = 'X'.
    wa_sort-subtot = 'X'.
    wa_sort-up = 'X'.
    append wa_sort to t_sort
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = sy-repid
          is_layout       = t_layout
          it_fieldcat      = wa_fieldcatalog[]
          it_sort           = t_sort[]
          i_save           = 'A'
          it_events       = t_events[]
        TABLES
          t_outtab        = ts_final_output[]
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
    It's still not working. Request u all to plz help
    Edited by: Ajoy Chakraborty on Jan 23, 2009 11:43 AM

    Hello Ajoy,
    You can do like this..
      wa_field-fieldname = 'MENGE'.
      wa_field-tabname = 'IT_TAB'.
      wa_field-outputlen = 20.
      wa_field-seltext_l ='Quantity'.
      wa_field-input = ' '.
      wa_field-edit = ' '.
      wa_field-col_pos = '4'.
      wa_field-hotspot = 'X'.
      wa_field-do_sum = 'X'.   " In the field catalog suppose you want the subtotal of this field
      APPEND wa_field TO it_field.
    CLEAR wa_field.
      wa_field-fieldname = 'WERKS'.
      wa_field-tabname = 'IT_TAB'.
      wa_field-outputlen = 20.
      wa_field-col_pos = '5'.
      wa_field-seltext_l ='Plant'.
    wa_field-input = 'X'.
      wa_field-edit = 'X'.
    APPEND wa_field TO it_field.
    CLEAR wa_field.
    *Manintainig internal table for sorting
    wa_sort-spos = 1.
      wa_sort-fieldname = 'EBELP'.
      wa_sort-tabname = 'IT_tab'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.   " this works like an T New for this field that is on every new value of this field ,  Subtotal will get calculated through above field catalog.
      APPEND wa_sort TO itab_sort.
      CLEAR wa_sort.
    Hope it helps you
    Regards
    Mansi

  • Issue in ALV Grid Grand Totals

    Hi Friends,
       Hwo can i display  grand total text in ALV Grid? Eventhough i am using Totals_text parameter in layout i am unable to display.  any one vcan help me out in this refgard.
    if pos send the code
    Regards,
    Vijay

    <REMOVED BY MODERATOR>
    SAMPLE PROGRAM:
    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 a~vbeln = b~vbeln
    INTO TABLE gt_salesorder
    WHERE a~vbeln IN s_vbeln.
    ENDFORM. " fetch_data
    Edited by: Alvaro Tejada Galindo on Apr 11, 2008 12:24 PM

  • ALV Display - sub totals

    hi gurus,
    In my report program i have a monthly report displaying the data for that month.
    1. Now in my ALV grid i want The SUB-TOTALS for the work center wise data for a field of the alv.  there are many workcenters data in my report.  So after the end of each work center , i want the subtotal of a calculated TAT field.
    2. At the end of the report, I want the average TAT(field calculated by my report program) for that month.
    So how can i make the coding for the above.
    Iam a fresher to this field, so give me in detail.
    regards,
    chaitanya

    Hi
    i am giving a sample example for subtotals of alv.
    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.

  • ALV GRID short dump issue

    could anybody advice, ALV GRID FM(field catalog issue)is getting short dump, but workig fine for ALV LIST.
    PERFORM create_field_catalog USING:
        'TRAFFIC_LIGHT' ' ' 15 'Status'   'Status' ' ',
        'VKORG'     ' ' 15 'Sales Org'    'Sales Org' ' ',
        'VTWEG'     ' ' 15 'Dist Channel' 'Dist Channel' ' ',
        'KUNRG'     ' ' 15 'Payer'        'Payer' ' ',
        'PAYER'     ' ' 15 'Payer Name'   'Payer Name' ' ',
        'KUNAG'     ' ' 15 'Ship-To'      'Ship-To' ' ',
        'SHIPTO'    ' ' 15 'Ship-To Name' 'Ship-To Name' ' ',
        'SHIPTOPAR' ' ' 15 'Bill to Party' 'Bill To Party' ' ',
        'KDGRP'     ' ' 15 'Customer Grp' 'Customer Grp' ' ',
        'ZCUSTPO'   ' ' 15 'Customer PO'  'Customer PO' ' ',
        'VBELN'     ' ' 15 'Billing Doc'  'Billing Doc' ' ',
        'FKDAT'     ' ' 15 'Billing Date' 'Billing Date' ' ',
        'FKART'     ' ' 15 'Billing Type' 'Billing Type' ' ',
        'ZOUTPUT'   ' ' 15 'Output Type'  'Output Type' ' ',
        'NETWR'     ' ' 15 'Net Value'    'Net Value' 'X',
        'KWERT'     ' ' 15 'Total VAT'    'Total VAT' 'X',
        'WAERK'     ' ' 15 'Currency'     'Currency' ' ',
        'XBLNR'     ' ' 15 'Reference'    'Reference' ' ',
        'DELNO'     ' ' 15 'Delivery #'   'Delivery #' ' ',
        'TLINE'     ' ' 15 'Manifest #'   'Manifest #' ' ',
        'ZBOL'      ' ' 15 'Bill Of Ldng' 'Bill of Ldng' ' ',
        'LIFEX'     ' ' 15 'Ext Del #'    'Ext Del #' ' ',
        'POSNR'     ' ' 15 'Item'         'Item' ' ',
        'MATNR'     ' ' 18 'Material'     'Material' ' ',
        'KDMAT'     ' ' 15 'Cust Matl'    'Cust Matl' ' ',
        'WERKS'     ' ' 15 'Plant'        'Plant' ' ',
        'ZZPLAT'    ' ' 10 'Platform'     'Platform' ' ',
        'ZZPRONUM'  ' ' 10 'Program'      'Program' ' ',
        'ZZPROCODE' ' ' 10 'Prod Code'    'Prod Code' ' ',
        'FKIMG'     ' ' 15 'Qty'          'Qty' ' ',
        'VRKME'     ' ' 15 'UoM'          'UoM' ' ',
        'ARKTX'     ' ' 15 'Description'  'Description' ' ',
        'KBETR'     ' ' 15 'Price'        'Price' ' ',
        'VATRT'     ' ' 15 'VAT Rate'     'VAT Rate' ' ',
        'KWERT_D'   ' ' 15 'Item VAT'     'Item VAT' 'X',
        'NETWR_D'   ' ' 15 'Item Net Value' 'Item Net Value' 'X',
        'VGBEL'     ' ' 15 'Ref Document' 'Ref Document' ' ',
        'VGPOS'     ' ' 13 'Ref Doc Line' 'Ref Doc Line' ' ' .
    FORM create_field_catalog USING fieldname TYPE c
                                    inttype   TYPE c
                                    outputlen TYPE i
                                    coltext   TYPE c
                                    seltext   TYPE c
                                    do_sum    TYPE c.
      DATA: l_f_fieldcat TYPE slis_fieldcat_alv.
      l_f_fieldcat-fieldname    = fieldname.
      l_f_fieldcat-inttype      = inttype.
      l_f_fieldcat-outputlen    = outputlen.
      l_f_fieldcat-seltext_m    = coltext.
      l_f_fieldcat-seltext_l    = seltext.
      l_f_fieldcat-reptext_ddic = coltext.
      l_f_fieldcat-do_sum     = do_sum.
      APPEND l_f_fieldcat TO t_field_catalog.
      CLEAR l_f_fieldcat.
    ENDFORM.   "CREATE_FIELD_CATALOG
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
              i_callback_program      = v_repid
              i_callback_user_command = 'F_USER_COMMAND'
              i_grid_settings         = f_grid_settings
              is_layout               = f_grid_layout
              is_print                = f_print_settings
              i_background_id         = 'BACK'
              it_events               = t_events[]
              it_fieldcat             = t_field_catalog
              it_sort                 = t_sortcat[]
              i_default               = 'X'
              i_save                  = 'A'
              is_variant              = f_variant
            TABLES
              t_outtab                = t_output4
            EXCEPTIONS
              program_error           = 1
              OTHERS                  = 2.

    BEGIN OF t_output4 OCCURS 0,
            traffic_light TYPE c,
            vkorg LIKE vbrk-vkorg,
            vtweg LIKE vbrk-vtweg,
            kunrg LIKE vbrk-kunrg,
            payer LIKE adrc-name1,
            kunag LIKE vbrk-kunag,
            shipto LIKE adrc-name1,
            shiptopar LIKE likp-kunnr,
            kdgrp  LIKE vbrk-kdgrp,
            zcustpo LIKE vbkd-bstkd,
            vbeln LIKE vbrk-vbeln,
            fkdat LIKE vbrk-fkdat,
            fkart LIKE vbrk-fkart,
            zoutput LIKE dnast-kschl,
            netwr LIKE vbrk-netwr,
            kwert LIKE konv-kwert,
            waerk LIKE vbrk-waerk,
            xblnr LIKE vbrk-xblnr,
            delno LIKE likp-vbeln,
            t_line LIKE tline-tdline,
            zbol LIKE likp-bolnr,
            lifex LIKE likp-lifex,
            posnr LIKE vbrp-posnr,
            matnr LIKE vbrp-matnr,
            kdmat LIKE lips-kdmat,
            werks LIKE vbrp-werks,
            zzplat LIKE vbrp-zzplat,
            zzpronum LIKE vbrp-zzpronum,
            zzprocode LIKE a802-zzprocode,
            fkimg LIKE vbrp-fkimg,
            vrkme LIKE vbrp-vrkme,
            arktx LIKE vbrp-arktx,
            kbetr LIKE konv-kbetr,
            vatrt TYPE p DECIMALS 1,
            kwert_d LIKE konv-kwert,
            netwr_d LIKE vbrp-netwr,
            vgbel LIKE vbrp-vgbel,
            vgpos LIKE vbrp-vgpos,
          END OF t_output4,

  • Sub-Total Issue

    Is there anyway i can update subtotal KZWI6 with a value, becasuse of a configuration mistake in the pricing procedure the system took zero value into the sub-total for certain invoices.

    Hi,
    try to run report (se38) RV15B003
    Regards,
    JM

  • ALV GRID out put issue

    hi,
    how to increase the font size of the output of alv grid...
    Actually my list is printing nearly 50 lins in one page how to control it to 20 and how to increase the font size in the alv grid output
    can anyone guide me its bit urgent  plzzzzzz
    SIRI

    Ya Rich,
    Actually... While i am taking all the records on the paper i got all the records on one page so if they wanted to enter some more data in the last filed which i provided blank they were telling that its too small font and its not so easy to enter
    so they were asking me to do the above job
    how to do that can u guide me plz
    SIRI

  • In ALV  grid  report, totals of columns display at end of report

    Hi.....!
           In ALV report i want to display grand totals in end of list and also i want to output display ALV report in page by page

    Hi,
    this the code i am sending it may help you.
    DATA : wa_sort TYPE slis_sortinfo_alv.
    DATA : it_sort TYPE slis_t_sortinfo_alv. " for sorting
    PERFORM sub_total USING '<field based on wich you want sort(say key field>>'.
    FORM sub_total USING value(p_sortfld) .
      wa_sort-fieldname = p_sortfld.
      wa_sort-subtot = 'X'.
      wa_sort-up = 'X'.
      APPEND wa_sort TO it_sort
    and then is main function module for display grid or list.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            i_callback_program     = wa_pgm
            i_callback_top_of_page
            ='TOP_OF_PAGE'
            i_grid_title           = text-016
            it_fieldcat            = it_fieldcat
           <b> it_sort                = it_sort</b>
            i_default              = 'X'
            i_save                 = 'A'
          TABLES
            t_outtab               = it_final.

  • ALV Grid - Subtotal & total to be shown at the top of the table

    Hi,
    I am using function module 'REUSE_ALV_GRID_DISPLAY' to display a table, and I count subtotals and total for some fields. The total is always shown at the bottom of the table, and subtotals are always shown after the rows that subtotals are calculated for. Is there a way to make it so that the total is always shown at the top of the table, and subtotals are shown before the rows that subtotals are calculated for?
    Thank you,
    Jake Alexander

    GW_LAYOUT-TOTALS_BEFORE_ITEMS = 'X'.
    Regards
    Sreekanth

  • ALV Sub total texts. displayed in list not in grid.

    Hi,
    I am displaying data using alv and sub-totals on a particular column.
    i am getting the sub-totals but i am not getting the sub-total texts when i am displaying data in a grid.
    'REUSE_ALV_GRID_DISPLAY'.
    i am getting subtotals and subtotal texts when i am diSplAying in list.
    'REUSE_ALV_LIST_DISPLAY'.
    but i want to get subtotal texts using alv grid, is it possible, if so please send me the code.
    Any help in this regard is highly appreciated.
    Thanks in advance for your help.

    Hi,
    Actually i have wriitten the same code, in the alv. I am using Function modules. for the same code the sub-total and total text is appearing in the list output. but not in the grid output.
    code.
      wa_layout-zebra          = 'X'.
      wa_layout-subtotals_text = 'Total'.
      wa_layout-totals_text    = 'Sum of Marks'.
    alv statement.
         is_layout = wa_layout
    Declaration.
    DATA : wa_layout type slis_layout_alv.
    for the same declarations (Above) list is showing the texts but not the grid.
    Any help in this regard is highly appreciated.

  • Mix AVG and Total for the same column in ALV grid

    Hi,
    We are using CL_GUI_ALV_GRID=>SET_TABLE_FOR_FIRST_DISPLAY, and I'd like to know if the following situation is possible.
    Let's say we have a column which contains a number of hours, and we set it up to subtotal by period, but as an average rather than a total (DO_SUM = "C"). This is not a problem so far.
    The problem is that we'd like for the "Grand Total" at the bottom of the ALV grid to total all of the subtotal averages, instead of calculating an average.
    Ex:
    Period            Hours
    2010/01           6.0
    2010/02           7.0
    2010/03           2.0
                    5.0  (This is an average... 6.0 + 7.0 + 2.0 / 3)
    2011/01          12.0
    2011/02           5.0
    2011/03           4.0
                    7.0  (This is an average... 12.0 + 5.0 + 4.0 / 3)
                12.0 (We want this to be a total of 5.0 + 7.0)
    So we want the "grand total" line to be 12.0 which is the sum, but it currently comes out as an average.
    Therefore we're looking to average at the sub total level, but we want a total of the subtotal levels at the grand total level for the same column.
    Thanks,
    Denis

    Refer to the suggestion given by Naimesh here Can we modify a sub-total in ALV making use of function GET_GLOBALS_FROM_SLVC_FULLSCR and the method GET_SUBTOTALS. You can see the parameter ep_collect01 refered in case of subtotals. Can you please check ep_collect00 for grand total in your case.
    As said about EP_COLLECT00,here goes a classic example Modify grand total in ALV GRID
    BR
    Keshav
    Edited by: Keshav.T on Sep 21, 2011 9:39 AM

  • Only sub total in alv report

    hi,
    I have a report on ALV with sub totals for some fields, it is working fine but my requirement is whether i can get only the sub totals of that report.
    regards,
    Prabhu

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

Maybe you are looking for

  • Problem with scriplet variable as tag attribute

              This question was already treated here but it doesn't help me.           I have a .jsp page where I am using a custom tag written by me like this :           <%! String thecategory= request.getParameter("category");%>           <gamemarket:

  • Please Help my iPhone is not charging properly

    lastnight i put my iphone4 on charge at 11% when i plugged it into the wall and swithed on the power it had no reaction at all it didnt light up make a noise at all so i plugged it into a different outlet it still done the same thing so i left it ove

  • Sync Error message reprocessing in MI server

    In MI 2.5 server, all sync error messages with staus I-Error need to be resolved manually and then reprocessed. Errors are generally data issues(Equipment type mismatch etc). In MI 7.1 , there are better data monitoring and administration capabilitie

  • RFC_ERROR_LOGON_FAILURE: This system rejects all logons using SSO tickets

    hello again, i manage to restart my server and applications but now when i try to start : http://host:port/b2b/b2b/init.do and i can't the logs show these line which i don't understand : 1}#2#parameters: [client]='null' [user]='null' [language]='null

  • When do I need to redeploy a Shared Variable?

    I am using 2 network shared variables to share data between cfp-2220s.  The shared variables are both clusters of several deifferent data types.  Do I need to redeploy the shared variable everytime I add or remove a variable from one of these cluster