Alv subtotal calculation

hi gurus,
my query is :
i have to calculate rate per min , p3 =  p1/p2 in subtotal column.but in the scenario given below it is just adding all the rpm and giving the total = 0.56 ,
but -3612/13940 = 0.26 is correct.
EX:
  amt(P1)     minutes (p2)   rpm(rate per min)(p3)
9,500.00-       5233             1.82-
1,500.00        3235              0.46
4,388.00        5472              0.80
3,612.00-      13940              0.56-   -
subtotal of above rows
so i want the subtotal value of p3 as p1/p2  and not just sum
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Apr 21, 2008 5:47 PM

This you can do using the Subtotal_text event of alv.
Check the sample code below..
in the event you will have the SUB TOTAL ROW INFORMATION, now divide the P1/P2  and get the P3 value.
modify the P3 value with value calculated , this will show the Changed value.
For information:-
you can find 2 programs one using class, one using Grid Function.
Re: SubTotal Text in ALV?

Similar Messages

  • Alv subtotal

    HI all,
    I need subtotal based on 2 fields one is matnr and the other one is vben but i am getting subtotals based on only matnr but not on vbeln what could be the problem?
    it_sort-fieldname = 'VBELN'.
    IT_SORT-TABNAME = 'GI_FINAL'.
    IT-SORT-SPOS = '1'.
    IT_SORT-SUBTOT = 'X'.
    IT-SORT-UP = 'X'.
    APPEND IT-SORT.
    it_sort-fieldname = 'MATNR'.
    IT_SORT-TABNAME = 'GI_FINAL'.
    IT-SORT-SPOS = '1'.
    IT_SORT-SUBTOT = 'X'.
    IT-SORT-UP = 'X'.
    APPEND IT-SORT.
    Please refer the above code and suggest me
    what exact purpose of spos here?
    Thanks&Regards
    mahsh

    Hi,
    Herewith i am sending the sample coding for the ALV SUBTOTAL report.
    REPORT  YMS_ALVSUBTOTAL.
    *REPORT z_alv_sub_totals .
    TYPE-POOLS: slis.
    DATA: BEGIN OF it_output OCCURS 0,
              var1(8) TYPE n,
              var2(10),
              var3 TYPE I,
          END OF it_output.
    DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
           t_fieldcat TYPE slis_fieldcat_alv,
          it_sort TYPE slis_t_sortinfo_alv,
          t_sort TYPE slis_sortinfo_alv,
          v_repid LIKE sy-repid.
    INITIALIZATION.
      v_repid = sy-repid.
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM sort_fields.
      PERFORM fill_fieldcat.
      PERFORM list_display.
    *&      Form  GET_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM get_data.
      it_output-var1 = 1000.
      it_output-var2 = 'anupama'.
      it_output-var3 = '10000'.
      APPEND it_output.
      CLEAR it_output.
      it_output-var1 = 1000.
      it_output-var2 = 'siddhu'.
      it_output-var3 = '20000'.
      APPEND it_output.
      CLEAR it_output.
      it_output-var1 = 1000.
      it_output-var2 = 'chinni'.
      it_output-var3 = '100000'.
      APPEND it_output.
      CLEAR it_output.
      it_output-var1 = 2000.
      it_output-var2 = 'chicchu'.
      it_output-var3 = '10000'.
      APPEND it_output.
      CLEAR it_output.
      it_output-var1 = 2000.
      it_output-var2 = 'candy'.
      it_output-var3 = '10000'.
      APPEND it_output.
      CLEAR it_output.
      it_output-var1 = 1000.
      it_output-var2 = 'anupama'.
      it_output-var3 = '10000'.
      APPEND it_output.
      CLEAR it_output.
      it_output-var1 = 4000.
      it_output-var2 = 'anupama'.
      it_output-var3 = '10000'.
      APPEND it_output.
      CLEAR it_output.
    ENDFORM.                    " GET_DATA
    *&      Form  fill_fieldcat
          text
    -->  p1        text
    <--  p2        text
    FORM fill_fieldcat.
      PERFORM fill_fields USING: 'IT_OUTPUT' 'VAR1' 'Variable 1' ' ',
                                 'IT_OUTPUT' 'VAR2' 'Variable 2' ' ',
                                 'IT_OUTPUT' 'VAR3' 'Variable 3' 'X'.
    ENDFORM.                    " fill_fieldcat
    *&      Form  fill_fields
          text
         -->P_0146   text
         -->P_0147   text
         -->P_0148   text
         -->P_0149   text
    FORM fill_fields USING    value(tabname) TYPE slis_tabname
                              value(fieldname) TYPE slis_fieldname
                              value(seltext_m) LIKE dd03p-scrtext_m
                              value(do_sum) TYPE c.
      t_fieldcat-tabname = tabname.
      t_fieldcat-fieldname = fieldname.
      t_fieldcat-seltext_m  = seltext_m.
      IF do_sum = 'X'.
        t_fieldcat-datatype = 'CURR'.
      ENDIF.
      t_fieldcat-do_sum = do_sum.
      APPEND t_fieldcat TO it_fieldcat.
      CLEAR t_fieldcat.
    ENDFORM.                    " fill_fields
    *&      Form  list_display
          text
    -->  p1        text
    <--  p2        text
    FORM list_display.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
         i_callback_program             = v_repid
         it_fieldcat                    = it_fieldcat
         it_sort                        = it_sort[]
       TABLES
          t_outtab                       = it_output
       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.                    " list_display
    *&      Form  sort_fields
          text
    -->  p1        text
    <--  p2        text
    FORM sort_fields.
      t_sort-fieldname = 'VAR1'.
      t_sort-tabname = 'IT_OUTPUT'.
      t_sort-spos = 1.
      t_sort-up = 'X'.
      t_sort-subtot = 'X'.
      APPEND t_sort TO it_sort.
      CLEAR t_sort.
      t_sort-fieldname = 'VAR3'.
      t_sort-tabname = 'IT_OUTPUT'.
      t_sort-spos = 2.
      t_sort-up = 'X'.
      APPEND t_sort TO it_sort.
      CLEAR t_sort.
    ENDFORM.                    " sort_fields
    Hope it will helps to u.
    Thanks,
    Shankar

  • A question about ALV subtotal

    Hello Expert,
    I have a question about ALV subtotal
    In my ALV output, there are three columns: SalesOrder, Item, Sales Volumn. Suppose there are following data in the ALV output
    SalesOrder   Item   Volumn
    123              10      100.00
    123              20      300.00
    456              10      200.00
    456              20      500.00
    What I want in the ALV outpu is as below:
    SalesOrder   Item   Volumn
    123              10      100.00
    123              20      300.00
                     subtotal  400.00
    456              10      200.00
    456              20      500.00
                     Subtotal 700.00
    Total                       1100.00
    Is this possible, and how can I achieve that result?
    Thanks & Regards, Johnny

    You can use sortinfo structure of ALV.
      Data:GT_SORT TYPE slis_t_sortinfo_alv.
      GTT_SORT-FIELDNAME = 'VBELN'.
      GTT_SORT-UP = 'X'.
      GTT_SORT-SUBTOT = 'X'.
      APPEND GTT_SORT TO GT_SORT.

  • Problem with subtotal calculation in ALV reports

    Hi All,
       I am doing one program for calculating subtoals in ALV . For this i want to display subtotal text at each envey subtotal 's row.
    For that i have created one form 'SUB_SUBTOT_TEXT' and it has given to IT_EVENTS-FORM. But SUB_SUBTOT_TEXT Form is not called by IT_EVENTS event.
    what are all the mandatories for displaying subtotal text.
    Can any one please help me.
    Thanks in Advance.

    Hi Sree,
    *& 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 widthENDFORM.                    " 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
    Hopes its helpful.
    Regards,
    Raj.

  • Subtotal calculation display in ALV report

    hi,
    i had made a report n alv which is almost complete but i want to add the feature that when i click on a field when output is displayed den the subtotal of all qty fields should be shown also.
    plz provide me with useful example as i am using the concept of INTERNAL TABLES.
    plzz reply fast as it is important to me and definately rewarded.

    Hi ric,
    check out this code.
    *& Report  ZST_ALV
    REPORT  ZST_ALV.
    type-POOLs: slis.
    --ALV Related Variables--
    DATA: lt_fcat          TYPE slis_t_fieldcat_alv,
          lw_fcat          TYPE slis_fieldcat_alv,
          lv_variant       TYPE disvariant,
          lv_layout        TYPE slis_layout_alv,
          lt_sort          type slis_t_sortinfo_alv,
          lw_sort          type slis_sortinfo_alv.
    types: begin of ty_vbap,
           vbeln type vbap-vbeln,
           posnr type vbap-posnr,
           zmeng type vbap-zmeng,
           end  of ty_vbap.
    data: lt_vbap type table of ty_vbap.
    start-of-selection.
    select vbeln posnr zmeng
           from  vbap
           into  table lt_vbap.
    sort lt_vbap descending.
    clear lw_fcat.
    lw_fcat-fieldname = 'VBELN'.
    lw_fcat-seltext_l = 'Sales document'.
    append lw_fcat to lt_fcat.
    clear lw_fcat.
    lw_fcat-fieldname = 'POSNR'.
    lw_fcat-seltext_l = 'Sales document'.
    append lw_fcat to lt_fcat.
    clear lw_fcat.
    lw_fcat-fieldname = 'ZMENG'.
    lw_fcat-seltext_l = 'Sales document'.
    lw_fcat-do_sum = 'X'.
    append lw_fcat to lt_fcat.
    lw_sort-spos = 1.
    lw_sort-fieldname = 'VBELN'.
    LW_SORT-Up = 'X'.
    append lw_sort to lt_sort.
    clear lw_sort.
    lw_sort-spos = 3.
    lw_sort-fieldname = 'ZMENG'.
    LW_SORT-Up = 'X'.
    lw_sort-subtot = 'X'.
    append lw_sort to lt_sort.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
      I_CALLBACK_PROGRAM                = ' '
      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                       = lt_fcat[]
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
       IT_SORT                           = lt_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
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        T_OUTTAB                          = lt_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.
    regards,
    Santosh Thorat

  • Subtotal calculation in ALV

    hi all,
    i need to calculate montly subtotal value of a field  in ALV ( OO),
    how can i do that.
    plz send the code also.
    thanks in advance.
    regards
    sushant  singh

    Hi,
    1) Create a sort internal table for you to do sub totaling based on the field change..In this example..I have created a sort internal table and it will sum for every change in the field VBELN.
    data: gs_sort     type lvc_s_sort.
    data: gt_sort     type lvc_t_sort.
      gs_sort-fieldname = 'VBELN'.
      gs_sort-UP          = 'X'.
      gs_sort-SUBTOT  = 'X'.
      append gs_sort to gt_sort.
    Pass the internal table GT_SORT to the parameter                   
    it_sort = gt_sort
    of the method set_table_for_first_display..
    2) For the field you have to do sum in the field catalog have the field DO_SUM = 'X'..
    Thanks,
    Naren

  • Calculation in ALV subtotal field

    Hi,
    I have a requirement to display the percentage field in the subtotal and total field in ALV display.
    ie, I have 3 fields, say, A, B and percent. (percent = A/B * 100)
    A              B                     percent
    10             10                     100
    5               10                     50
    15              20                     75
    Currently I am getting like below:-
    A              B                     percent
    10             10                     100
    5               10                     50
    15              20                     150
    Is there any way to display the proper percentage in subtotal field in ALV?
    Thanks in advance.
    Regards,
    Arun Mohan

    Hi,
    As you have mentioned in the question
    A B percent
    10 10 100
    5 10 50
    15 20 75
    Here you can divide the percentage field by the number of rows you have in the report. E.g here you have 2 rows, so sum is 150/2 = 75
    HTH
    Regards,
    Dhruv Shah

  • ALV: conditional total / subtotal calculation

    Dear colleagues,
    I am using the REUSE_ALV_GRID_DISPLAY_LVC function. My ALV has character columns only. There are 5 key columns and up to 120 day columns (one per day). The day columns containing "real character" values or blank. Does anybody know if it is possible to implement the following requirement? And if yes, how?
    The toolbar should contain the total and subtotal button. When (i.e.) the subtotal button is pressed, for every day column the number of cells containing "real characters" (not blank only) should be displayed grouped by the marked key col. ?
    Thank you for your help,
    Peter

    Hi,
    You need to have an field which is an integer type i.e. type i in the structure and make the subtotal as 'X' in the Field layout.
    Thanks & Regards
    Sarves Sombhatla

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

  • OBIEE subtotal Calculation

    Hi,
    I have a OBIEE pivot table report which shows Projects Information and it has the following fields:
    1.Customer
    2. Master Project
    3. Child Projects under Master project
    4.  Task details by Child Project
    5.  Contract Hours (this is by Task Details(4)  and Child Project (3))
    6.  Total Budget Hours (this is by Task Details(4)  and Child Project (3))
    The above 6 columns are included at the pivot table rows section.
    In the measures sections, we have following fields
    1. Forecast Hours,
    2. Actual Hours
    Both will be displayed by month as cross tab.
    ***now the issue is we need to do a subtotal based on Master project which will be a calculation i.e., Total Budget Hours/Contract Hours.
    These two field are in the row level and cannot be included in the measures section of the pivot table.
    can you please help in this?

    Hi,
    Here the requirement is to show Subtotal values in the Pivot table on Hierarchy columns (along with other columns also in Pivot table)
    Below is the sample table which shows the issue.
    When I place Hierarchy column (Region) in Pivot table then "Show Subtotal" option will not comes. But for normal columns I am able to get Subtotal values.
    Region (Hierarchy column)
    Product Type
    Amount(Measure)
    Europe
    A
    100
    B
    200
    Sub Total
    300
    Asia
    A
    150
    B
    250
    Sub Total
    400
    Grand Total
    70
    Hope this clarifies my issue. Let me know if I get any help.

  • ALV subtotal & grand total

    Hi experts,
    I have a ALV display which displays subtotals & grandtotals. I only want the subtotals, How can I supress the grantotal?
    ex.
    DOC num 50003859
    200 USD
    300 USD
    subtotal = 500
    DOC num 50005469
    600 USD
    subtotal = 600
    Grandtotal = 1100 <- I dont want this to show.

    Hi,
    You can do as below for Subtotal and suppress the grand total.
    data :gt_sort TYPE slis_t_sortinfo_alv,
    DATA: ls_sort TYPE slis_sortinfo_alv.
    CLEAR ls_sort.
    ls_sort-fieldname = 'BELNR'.
    ls_sort-up = 'X'.
    ls_sort-subtot = 'X'.
    APPEND ls_sort TO gt_sort.
    And pass gt_sort to grid display export parameter IT_sort.
    And to suppress the grandtotal.
    in the layout use the below code :
    wa_layout-no_totalline = 'X'.
    Thanks,
    Sriram Ponna.

  • ABAP Query - ALV Grid Calculation

    Can anybody tell me whether in ABAP Query when you execute the Query in SQ01 its shows the report in ALV Grid format. In ALV Grid format there are some standard calculation are available like
    TOtal
    Mean value
    Minmum
    Maximum
    Count
    The above calculation can be done for each column.
    My Query is it possible to put our own simple calculation
    through some coding for overall summation fields instead of this std. calculation.
    Example : Unrestricted moved Qty Summation divided by INspection lot qty summation * 100
    The output of this calculation is called First pass yield.
    This calculation i done for each line item by creating a Additional field with ABAP coding.The overall meanvalue calcualtion of this addtional fields column is not suits the customer expectation.They want the calculation to be done by the system like what i had explained in the example.

    Hi,
    Here is a code for a single grid.
    In the screen layout,make a custom container (Icon with C ) and name it in Capital letters as CONTAINER.The code below in bold letters is what exactly you want.I ve given a small example on how to use ALV:
    REPORT SAMPLE.
    DATA: alv type ref to cl_gui_alv_GRID,
    cont type ref to cl_gui_custom_container,
    itab_spfli type table of spfli.
    START-OF-SELECTION.
    select * from spfli into table itab_spfli.
    call screen 100.
    END-OF-SELECTION.
    *& Module STATUS_0100 OUTPUT
    text
    MODULE STATUS_0100 OUTPUT.
    seT PF-STATUS 'GUI'.
    SET TITLEBAR 'xxx'.
    if cont is initial.
    CREATE OBJECT cont
    EXPORTING
    CONTAINER_NAME = 'CONTAINER'.
    CREATE OBJECT ALV
    EXPORTING
    I_PARENT = CONT.
    CALL METHOD ALV->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
    I_STRUCTURE_NAME = 'SPFLI'
    CHANGING
    IT_OUTTAB = itab_spfli
    Now for your requirement,you can create two custom containers in the screen layout and two different alv grid instances.ie:
    DATA: alv1 type ref to cl_gui_alv_GRID,
    cont1 type ref to cl_gui_custom_container
    alv2 type ref to cl_gui_alv_GRID,
    cont2 type ref to cl_gui_custom_container.
    To select data from first grid,you can use events on double_click and fetch information and then display it in the second grid.
    <b>SOME MATERIAL REGARDING ALV:</b>
    www.abap4.it/download/ALV.pdf <b>(very useful)</b>
    http://www.sapdevelopment.co.uk/reporting/alvhome.htm
    <b>-->download the PDF from following link.</b>
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf
    http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
    <b>SAMPLE PROGRAMS IN ALV:</b>http://www.geocities.com/victorav15/sapr3/abap_ood.html#d_grid
    <b>DEMO PROGRAMS IN ALV:</b>BCALV*
    Regards,
    Beejal
    **Reward if this helps

  • In ALV Subtotal line with Color

    Hi,
    I am working on ALV Grid and the output and all are ok.
    Only the problem is User expecting Subtotal in row should be in color.
    Can you pls advise me.
    Thank You,
    Sri.

    Hi,
    plz refer this link.
    Color the sub-total row in an alv-grid
    saptechnical/Tutorials/ALV/Subtotals/Define.htm
    sap.niraj.tripod.com/id64.html
    Regards,
    Pravin

  • 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 SUBTOTAL (Change at summation Level)

    Hi All,
    I need to add some code at the subtotal level of the ALV report output. My output shound look something like this.
         FLD1     FLD2     FLD3     FLD4
         A1     B1     1     AA
         A1     B1     2     BB
    <i><b>Sum     A1     B1     3     C</b></i>
         A1     B2     11     D1
         A1     B2     22     D2
    <i><b>Sum     A1     B2     33     CD</b></i>
         B1     B1     1     D1
    <i><b>Sum     B1     B1     1     CCD</b></i>
         B1     B2     5     D1     
    <i><b>Sum     B1     B2     5     CCDD</b></i>
    I should be able insert a summation level into the output so that the FLD4 can be changed based on the total of FLD3 at the summation level.
    Please let me know if this is a possibility atleast.
    Thanks in advance..!
    Jr.
    Message was edited by: Jr Abaper

    You need to build a sort table with feild you want to have for subtoal by setting one of attributes subtot    = 'X'.
    Data:
          dt_sortcat TYPE slis_t_sortinfo_alv,    "table - sort table
           ds_sortcat LIKE LINE OF dt_sortcat,     "structure-sort structure
      ds_sortcat-spos      = '1'.
      ds_sortcat-fieldname = 'VBELN'.
      ds_sortcat-tabname   = 'IT_DATA'.
      ds_sortcat-up        = 'X'.
      ds_sortcat-down      = space.
      ds_sortcat-subtot    = 'X'.
      APPEND ds_sortcat TO dt_sortcat.
       ds_sortcat-spos      = '2'.
      ds_sortcat-fieldname = 'POSNR'.
      ds_sortcat-tabname   = 'IT_DATA'.
      ds_sortcat-up        = 'X'.
      ds_sortcat-down      = space.
      APPEND ds_sortcat TO dt_sortcat.
    and pass the sort table to the exporting parameter IT_SORT of the REUSE_ALV_GRID_DISPLAY function module.
    For Demo programs: Go to se38 and enter BCALV* and press F4 key you will get list of ALV demo programs
    Message was edited by: Sid

Maybe you are looking for

  • Customizing ODBC errors in OBIEE 11g

    Hi, I have a requirement where the user is expecting to see some Custom error messages instead of the Default ODBC errors OBIEE throws. Like the one below. Error generating view. Error getting cursor in GenerateHead   Error Details Error Codes: OAMP2

  • Running Safari 6.0.2 - Mac OS 10.7.5

    My MBP will not update Adobe flash player - What is the story here? I am not particularly adept at stuff like this.  I need a step by step list or is there something to buy to fix this for me. Very frustrating. Thanks for any help.

  • Error in Displaying table.

    Hello Friends,                       I am populating a in a table in one view, getting values in another view. I am using separate context node for getting the value and adding these values into another context node, which is the source for the table

  • Dial chart

    Hello everybody... I want to create a percent dial chart. This chart should show a 'performance', expressed by a percentage. This value is obtained by the ratio between two values: 1-the first value (i'll call it "VALUE") derives from a sql query 2-t

  • Customizing Contact Sheets in iPhoto

    We used to be able to customize the order of the photos on the contact sheets in iPhoto by moving them around the actual sheet. I am unable to do find a way to do this with the current version of iPhoto. The only thing it allows me to customize is ho