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.

Similar Messages

  • 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

    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

  • 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

  • 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 report -  output download

    Hi Friends,
    I am having one issue reg download of  ALV (Grid display) report output. we are having vendor number at 1st colomn. It's displaying correctly in output.
    (eg:0000100069). But, when I download the output into a excel file, last digit of the vendor number getting truncated. (eg: 100069 becomes 10006). 
    Kindly help me regarding this ..
    Thanks in advance.
    Regards,
    Bharat.

    Hi,
    The problem is in formatting in Excel. U download the data. Then select the column u want to format, right click and select format cells. In that, choose Number and assign decimal places to 0. U will get according to the format u needed.
    I worked in this, and got as per the specified format.
    Reward if found useful.

  • 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

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

  • Reg. alv and interactive reports

    Hi Friends,
    What is the difference between alv and interactive reports?.
    rewards are helpful answers.

    Hi,
    ABAP List Viewer
    The common features of report are column alignment, sorting, filtering, subtotals, totals etc. To implement these, a lot of coding and logic is to be put. To avoid that we can use a concept called ABAP List Viewer (ALV).
    Using ALV, we can have three types of reports:
    1. Simple Report
    2. Block Report
    3. Hierarchical Sequential Report
    Interactive Reports
    As the name suggests, the user can Interact with the report. We can have a drill down into the report data.
    Purpose
        Interactive report provides you with comfortable functions for navigating through your data.
    Use
    Interactive report are used to display multiple list in one single report
    It has basic list and then you can  navigate to one or other screens in one single report
    Enhance the efficiency & transparency of Business Processes
    Example :  Column one of the report displays the material numbers, and the user feels that he needs some more specific data about the vendor for that material, he can HIDE that data under those material numbers.
    And when the user clicks the material number, another report (actually sub report/secondary list) which displays the vendor details.
    Advantage of ALV over Interactive:--
    1> Graphic Can be added
    2> Less Amount Of coding
    Reward If Helpful

  • 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

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

Maybe you are looking for