Alv subtotals  and grand total for a field

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

Check this sample code may it will help u:
*& Report  Z_ALV_SUBTOTAL
REPORT z_alv_subtotal.
*& Table declaration
TABLES: ekko.
*& Type pool declaration
TYPE-POOLS: slis. " Type pool for ALV
*& Selection screen
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
*& Type declaration
* Type declaration for internal table to store EKPO data
TYPES: BEGIN OF x_data,
       ebeln  TYPE char30,  " Document no.
       ebelp  TYPE ebelp,   " Item no
       matnr  TYPE matnr,   " Material no
       matnr1 TYPE matnr,   " Material no
       werks  TYPE werks_d, " Plant
       werks1 TYPE werks_d, " Plant
       ntgew  TYPE entge,   " Net weight
       gewe   TYPE egewe,   " Unit of weight                          
       END OF x_data.
*& Internal table declaration
DATA:
* Internal table to store EKPO data
  i_ekpo TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
* Internal table for storing field catalog information
  i_fieldcat TYPE slis_t_fieldcat_alv,
* Internal table for Top of Page info. in ALV Display
  i_alv_top_of_page TYPE slis_t_listheader,
* Internal table for ALV Display events
  i_events TYPE slis_t_event,
* Internal table for storing ALV sort information
  i_sort TYPE  slis_t_sortinfo_alv,
  i_event TYPE slis_t_event.
*& Work area declaration
DATA:
  wa_ekko TYPE x_data,
  wa_layout     TYPE slis_layout_alv,
  wa_events         TYPE slis_alv_event,
  wa_sort TYPE slis_sortinfo_alv.
*& Constant declaration
CONSTANTS:
   c_header   TYPE char1
              VALUE 'H',                    "Header in ALV
   c_item     TYPE char1
              VALUE 'S'.
*& Start-of-selection event
START-OF-SELECTION.
* Select data from ekpo
  SELECT ebeln " Doc no
         ebelp " Item
         matnr " Material*
         matnr " Material*
         werks " Plant*
         werks " Plant*
         ntgew " Quantity
         gewei " Unit
         FROM ekpo
         INTO TABLE i_ekpo
         WHERE ebeln IN s_ebeln
         AND ntgew NE '0.00'.
  IF sy-subrc = 0.
    SORT i_ekpo BY ebeln ebelp matnr .
  ENDIF.
* To build the Page header
  PERFORM sub_build_header.
* To prepare field catalog
  PERFORM sub_field_catalog.
* Perform to populate the layout structure
  PERFORM sub_populate_layout.
* Perform to populate the sort table.
  PERFORM sub_populate_sort.
* Perform to populate ALV event
  PERFORM sub_get_event.
END-OF-SELECTION.
* Perform to display ALV report
  PERFORM sub_alv_report_display.
*&      Form  sub_build_header
*       To build the header
*       No Parameter
FORM sub_build_header .
* Local data declaration
  DATA: l_system     TYPE char10 ,          "System id
        l_r_line     TYPE slis_listheader,  "Hold list header
        l_date       TYPE char10,           "Date
        l_time       TYPE char10,           "Time
        l_success_records TYPE i,           "No of success records
        l_title(300) TYPE c.                " Title
* Title  Display
  l_r_line-typ = c_header.               " header
  l_title = 'Test report'(001).
  l_r_line-info = l_title.
  APPEND l_r_line TO i_alv_top_of_page.
  CLEAR l_r_line.
* Run date Display
  CLEAR l_date.
  l_r_line-typ  = c_item.                " Item
  WRITE: sy-datum  TO l_date MM/DD/YYYY.
  l_r_line-key = 'Run Date :'(002).
  l_r_line-info = l_date.
  APPEND l_r_line TO i_alv_top_of_page.
  CLEAR: l_r_line,
         l_date.
ENDFORM.                    " sub_build_header
*&      Form  sub_field_catalog
*       Build Field Catalog
*       No Parameter
FORM sub_field_catalog .
*  Build Field Catalog
  PERFORM sub_fill_alv_field_catalog USING:
     '01' '01' 'EBELN' 'I_EKPO' 'L'
     'Doc No'(003) ' ' ' ' ' ' ' ',
     '01' '02' 'EBELP' 'I_EKPO' 'L'
     'Item No'(004) 'X' 'X' ' ' ' ',
     '01' '03' 'MATNR' 'I_EKPO' 'L'
     'Material No'(005) 'X' 'X' ' ' ' ',
     '01' '03' 'MATNR1' 'I_EKPO' 'L'
     'Material No'(005) ' ' ' ' ' ' ' ',
     '01' '04' 'WERKS' 'I_EKPO' 'L'
     'Plant'(006) 'X' 'X' ' ' ' ',
     '01' '04' 'WERKS1' 'I_EKPO' 'L'
     'Plant'(006) ' ' ' ' ' ' ' ',
     '01' '05' 'NTGEW' 'I_EKPO' 'R'
     'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'.
ENDFORM.                    " sub_field_catalog
*&     Form  sub_fill_alv_field_catalog
*&     For building Field Catalog
*&     p_rowpos   Row position
*&     p_colpos   Col position
*&     p_fldnam   Fldname
*&     p_tabnam   Tabname
*&     p_justif   Justification
*&     p_seltext  Seltext
*&     p_out      no out
*&     p_tech     Technical field
*&     p_qfield   Quantity field
*&     p_qtab     Quantity table
FORM sub_fill_alv_field_catalog  USING  p_rowpos    TYPE sycurow
                                        p_colpos    TYPE sycucol
                                        p_fldnam    TYPE fieldname
                                        p_tabnam    TYPE tabname
                                        p_justif    TYPE char1
                                        p_seltext   TYPE dd03p-scrtext_l
                                        p_out       TYPE char1
                                        p_tech      TYPE char1
                                        p_qfield    TYPE slis_fieldname
                                        p_qtab      TYPE slis_tabname.
* Local declaration for field catalog
  DATA: wa_lfl_fcat    TYPE  slis_fieldcat_alv.
  wa_lfl_fcat-row_pos        =  p_rowpos.     "Row
  wa_lfl_fcat-col_pos        =  p_colpos.     "Column
  wa_lfl_fcat-fieldname      =  p_fldnam.     "Field Name
  wa_lfl_fcat-tabname        =  p_tabnam.     "Internal Table Name
  wa_lfl_fcat-just           =  p_justif.     "Screen Justified
  wa_lfl_fcat-seltext_l      =  p_seltext.    "Field Text
  wa_lfl_fcat-no_out         =  p_out.        "No output
  wa_lfl_fcat-tech           =  p_tech.       "Technical field
  wa_lfl_fcat-qfieldname     =  p_qfield.     "Quantity unit
  wa_lfl_fcat-qtabname       =  p_qtab .      "Quantity table
  IF p_fldnam = 'NTGEW'.
    wa_lfl_fcat-do_sum  = 'X'.
  ENDIF.
  APPEND wa_lfl_fcat TO i_fieldcat.
  CLEAR wa_lfl_fcat.
ENDFORM.                    " sub_fill_alv_field_catalog
*&      Form  sub_populate_layout
*       Populate ALV layout
*       No Parameter
FORM sub_populate_layout .
  CLEAR wa_layout.
  wa_layout-colwidth_optimize = 'X'." Optimization of Col width
ENDFORM.                    " sub_populate_layout
*&      Form  sub_populate_sort
*       Populate ALV sort table
*       No Parameter
FORM sub_populate_sort .
* Sort on material
  wa_sort-spos = '01' .
  wa_sort-fieldname = 'MATNR'.
  wa_sort-tabname = 'I_EKPO'.
  wa_sort-up = 'X'.
  wa_sort-subtot = 'X'.
  APPEND wa_sort TO i_sort .
  CLEAR wa_sort.
* Sort on plant
  wa_sort-spos = '02'.
  wa_sort-fieldname = 'WERKS'.
  wa_sort-tabname = 'I_EKPO'.
  wa_sort-up = 'X'.
  wa_sort-subtot = 'X'.
  APPEND wa_sort TO i_sort .
  CLEAR wa_sort.
ENDFORM.                    " sub_populate_sort
*&      Form  sub_get_event
*       Get ALV grid event and pass the form name to subtotal_text
*       event
*       No Parameter
FORM sub_get_event .
  CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE
'SUBTOTAL_TEXT'.
  DATA: l_s_event TYPE slis_alv_event.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 4
    IMPORTING
      et_events       = i_event
    EXCEPTIONS
      list_type_wrong = 0
      OTHERS          = 0.
* Subtotal
  READ TABLE i_event  INTO l_s_event
                    WITH KEY name = slis_ev_subtotal_text.
  IF sy-subrc = 0.
    MOVE c_formname_subtotal_text TO l_s_event-form.
    MODIFY i_event FROM l_s_event INDEX sy-tabix.
  ENDIF.
ENDFORM.                    " sub_get_event
*&      Form  sub_alv_report_display
*       For ALV Report Display
*       No Parameter
FORM sub_alv_report_display .
  DATA: l_repid TYPE syrepid .
  l_repid = sy-repid .
* This function module for displaying the ALV report
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = l_repid
      i_callback_top_of_page   = 'SUB_ALV_TOP_OF_PAGE'
      is_layout                = wa_layout
      it_fieldcat              = i_fieldcat
      it_sort = i_sort
      it_events                = i_event
      i_default                = 'X'
      i_save                   = 'A'
    TABLES
      t_outtab                 = i_ekpo
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
*    MESSAGE i000 WITH 'Error in ALV report display'(055).
  ENDIF.
ENDFORM.                    " sub_alv_report_display
*       FORM sub_alv_top_of_page
*       Call ALV top of page
*       No parameter
FORM sub_alv_top_of_page.                                   "#EC CALLED
* To write header for the ALV
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_alv_top_of_page.
ENDFORM.                    "alv_top_of_page
*&      Form  subtotal_text
*       Build subtotal text
*       P_total  Total
*       p_subtot_text Subtotal text info
FORM subtotal_text CHANGING
               p_total TYPE any
               p_subtot_text TYPE slis_subtot_text.
* Material level sub total
  IF p_subtot_text-criteria = 'MATNR'.
    p_subtot_text-display_text_for_subtotal
    = 'Material level total'(009).
  ENDIF.
* Plant level sub total
  IF p_subtot_text-criteria = 'WERKS'.
    p_subtot_text-display_text_for_subtotal = 'Plant level total'(010).
  ENDIF.
ENDFORM.                    "subtotal_text
Edited by: Joyjit Ghosh on Aug 21, 2008 5:25 PM

Similar Messages

  • Subtotal and grand total for two fields(iseg-buchm and iseg-erfmg)

    hi experts,
        how to do subtotal and grand total for two fields (iseg-buchm and iseg-erfmg).please help me on solving the problem.

    subtotal & grand total can be done in folowing way in ALV.
    1.Pass it_sort parametere to REUSE_ALV_GRID_DISPLAY
    2.Give the field name for sorting in it_sort-fieldname. it can be any field name  u want to sort ur data with.
    3.For iseg-buchm & iseg-erfmg mark do_sum = 'X'. in fieldcat
      gs_sort-spos = 1.
      gs_sort-fieldname = 'ANY FIELD NAME'.
      gs_sort-up = 'X'.
      gs_sort-subtot = 'X'.
      APPEND gs_sort TO et_sort.
      IF iv_fieldname = 'BUCHM'
      OR iv_fieldname = 'ERFMG'.
        gs_fieldcat-do_sum = 'X'.
      ENDIF.
      APPEND gs_fieldcat TO gt_fieldcat.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
           is_variant              = ev_variant
          it_fieldcat             = gt_fieldcat[]

  • COMPUTE function: How to get subtotals and GRAND total together?

    I am wrtiting a report using SQL and SQL*Plus to get subtotals and a grand total. The COMPUTE function allows me to COMPUTE SUM on a group, but it only gives me subtotals. I'm interested in getting a report with the SUBTOTALS and a final GRAND TOTAL. Can this be done using SQL*Plus?
    Here is my current code that gives me subtotals:
    COMPUTE SUM LABEL subtotal OF sal ON deptno
    SELECT ename, sal, deptno
    FROM emp
    ORDER BY deptno;
    ENAME             SAL     DEPTNO
    CLARK            2450         10
    VOLLMAN          5000
    MILLER           1300
                     8750 subtotal
    SMITH             800         20
    ADAMS            1100
    FORD             3000
    SCOTT            3000
    JONES            2975
                    10875 subtotal
    ALLEN            1600         30
    BLAKE            2850
    MARTIN           1250
    JAMES             950
    TURNER           1500
    WARD             1250
                     9400 subtotalHere is the code to give one grand total:
    Column DUMMY NOPRINT
    COMPUTE SUM OF sal ON DUMMY
    BREAK ON DUMMY
    SELECT NULL DUMMY, ename, sal, deptno
    FROM emp
    ORDER BY deptno;
    ENAME             SAL     DEPTNO
    CLARK            2450              10
    VOLLMAN          5000          10
    MILLER           1300          10
    SMITH             800              20
    ADAMS            1100          20
    FORD             3000          20
    SCOTT            3000          20
    JONES            2975          20
    ALLEN            1600              30
    BLAKE            2850          30
    MARTIN           1250          30
    JAMES             950          30
    TURNER           1500          30
    WARD             1250          30
                    29025
    How can I combine both on one report?

    Massimo Ruocchio wrote:
    Do you like this?I believe OP is looking for both department totals and grand total. Frank already showed how to do it in SQL*Plus. To do it in SQL:
    SELECT  CASE GROUPING_ID(real_deptno,real_ename)
              WHEN 0 then real_ename
              WHEN 1 then 'Department ' || real_deptno || ' total'
              ELSE 'All department total'
            END ename,
            SUM(sal),
            deptno
      FROM  (
             SELECT  deptno real_deptno,
                     ename real_ename,
                     sal,
                     CASE ROW_NUMBER() OVER(PARTITION BY deptno order by ename) WHEN 1 THEN deptno end deptno
               FROM  emp
      GROUP BY GROUPING SETS((),real_deptno,(real_deptno,deptno,real_ename))
      ORDER BY real_deptno nulls last,
               real_ename nulls last
    ENAME                  SUM(SAL)     DEPTNO
    CLARK                      2450         10
    KING                       5000
    MILLER                     1300
    Department 10 total        8750
    ADAMS                      1100         20
    FORD                       3000
    JONES                      2975
    SCOTT                      3000
    SMITH                       800
    Department 20 total       10875
    ALLEN                      1600         30
    ENAME                  SUM(SAL)     DEPTNO
    BLAKE                      2850
    JAMES                       950
    MARTIN                     1250
    TURNER                     1500
    WARD                       1250
    Department 30 total        9400
    All department total      29025
    18 rows selected.
    SQL> SY.

  • Calculated members In Excel 2013 - subtotals and grand totals missing

    I am using Excel 2013 to query an SSAS OLAP cube. I have selected 2 dimensions in the row area, and I need to consolidate specific combinations of members values of each dimension. To do this I have created calculated members which combine sets of members
    of each dimension, as in the code example below.
    These members produce the desired results except that I do not have any subtotals on a 3rd dimension in the row area (Internal segment name, cf. image below), nor grand totals in the pivot table.
    I am fairly new that MDX and would appreciate any advice on how to correct the code below.
    Code for the member [Manufacturing Item].[Item Type].[All].[Cards Contact]
    AGGREGATE(
    CROSSJOIN(
    {[Manufacturing Item].[Item Type].&[CARD BODY OTHER],
    [Manufacturing Item].[Item Type].&[CARD BODY],
    [Manufacturing Item].[Item Type].&[SMART CARD]},
    [Techno cards contact]

    In my previous post, the solution happened to work because the combination of the calculated members was equal to the whole dimension. But I found a cleaner method: subtotals need to be calculated for the combination of all the calculated members, so the
    logic is to create a set that contains all of them. Then aggregate the measure for this set only for subtotals. To do this, I have created the following calculated measure: 
    IIF(
    ISLEAF([Manufacturing Item].[Item Type].CurrentMember),
    [Measures].[Manufacturing Volume],
    SUM({[CalcMembers]},[Measures].[Manufacturing Volume])

  • XML Publisher - Multi Level group totals, subtotals and grand totals

    Hi Experts,
    I have a question in BI Publisher report in R12 Projects. The report has the following information: Project Parent Org -> Project Org -> Supervisor name(An employee who might be owning multiple projects)  -> Project -> Task -> Expenditure and Revenue amounts.
    I am able to generate the RTF report considering the above hierarchy. I am able to list Expenditure, Revenue, profit margin and few other calculated fields in the report.
    Now, user is looking for the total of the amount at various levels:
    Task Level
    Project Level
    Supervisor Level
    Project Org level
    Parent Org level
    In my Data Definition, I have data something like this:
    <group name="G_PROJECT_DETAILS"  source="Q_PROJECT_DETAILS">
      <element name="PROJECT_TYPE"             value="PROJECT_TYPE"/>
      <element name="AREA"                     value="AREA"/>
      <element name="PARENT_ORG"                value="PARENT_ORG"/>
      <group name="G_SUPERVISOR_DETAILS"   source="Q_PROJECT_DETAILS">
      <element name="CHILD_ORG"                 value="CHILD_ORG"/>
      <element name="SUPERVISOR"           value="SUPERVISOR"/>
      <group name="G_DETAILS"  source="Q_PROJECT_DETAILS">
      <element name="PROJECT_TYPE"              value="PROJECT_TYPE"/>
      <element name="PRJ_NUMBER"                value="PRJ_NUMBER"/>
      <element name="CREW"                      value="CREW"/>
      <element name="TOTAL_REVENUE_YTD"         value="G_REVENUE_DETAILS.TOTAL_REVENUE_YTD_C"       function="SUM()"/>
      <element name="TOTAL_DIRECT_COST_YTD"     value="G_EXPENDITURE_DETAILS.TOTAL_DIRECT_COST_YTD_C"    function="SUM()"/>
      <element name="HOUR_YTD"                  value="G_EXPENDITURE_DETAILS.HOUR_YTD_C"       function="SUM()"/>
      <group name="G_REVENUE_DETAILS"  source="Q_REVENUE_DETAILS">
      <element name="TOTAL_REVENUE_YTD_C"         datatype="NUMBER" value="TOTAL_REVENUE_YTD"/>
      </group>
      <group name="G_EXPENDITURE_DETAILS"  source="Q_EXPENDITURE_DETAILS">
      <element name="TOTAL_DIRECT_COST_YTD_C"     datatype="NUMBER" value="TOTAL_DIRECT_COST_YTD"/>
      <element name="HOUR_YTD_C"                  datatype="NUMBER" value="HOUR_YTD" />
      </group>
      </group>
      </group>
    </group>
    I am trying to calculate SUM for 'TOTAL_REVENUE_YTD', 'TOTAL_DIRECT_COST_YTD' fields at a higher level (i.e. Child and Parent Org level containing multiple projects). I tried accessing them like
      <element name="TOTAL_REVENUE_YTD_C"         value="G_DETAILS.TOTAL_REVENUE_YTD"       function="SUM()"/>
      <element name="TOTAL_DIRECT_COST_YTD_C"     value="G_DETAILS.TOTAL_DIRECT_COST_YTD"    function="SUM()"/>
    using the group name G_DETAILS. But, I am not able to get the sum of all entries (i.e. grand child of current group). I also tried using SUM() with <group1>.<group2>.elementname to get grand-total of all grand child. But, its not working.
    Please suggest how to calculate totals for grand-child.
    Thanks in advance
    Rathnam

    Try by creating a formula like this :
    Whileprintingrecords;
    Col1 + Col2 + Col3 + Col4

  • Using Rollup to get subtotals and grand total - missing right pren error

    Hello,
    I am trying to create sub totals by person_id and a grand total row in my APEX report but I get a "missing right pren error." I finally figure out that I need to eliminate column alias names to fix this problem, however, I now get an ambigous column reference. I am making this change in my main SQL report statement, however, I was wondering if I should be using the "group by Rollup" somewhere else while using "Break Formatting."
    I would appreciate any help.
    Thanks
    leh

    Can you post the Query please?

  • Calculating subtotals and grand totals in a report without grouping

    I am trying to write a script in SQL Plus that will produce page totals on every 35 lines (that is, break on every 35 lines regardless of a data item). Also, I would like the report total to generate on the last page of the report.
    Thank you

    exemple, every 8 lines + grant total
    SCOTT@LSC01> col p nopri
    SCOTT@LSC01> bre on p ski 2 on report ski 2
    SCOTT@LSC01> comp sum of sal on p
    SCOTT@LSC01> comp sum of sal on report
    SCOTT@LSC01> select ename, sal, trunc(rownum/8)+1 p from emp;
    ENAME             SAL
    SMITH             800
    ALLEN            1600
    WARD             1250
    JONES            2975
    MARTIN           1250
    BLAKE            2850
    CLARK            2450
                    13175
    SCOTT            3000
    KING             5000
    TURNER           1500
    ADAMS            1100
    JAMES             950
    FORD             3000
    MILLER           1300
                    15850
    sum             29025
    [/pre]
    HTH
    Laurent                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • I need the grand total for particular coulumn for ALV grid report(OOPs).

    Hello,
    I have used the following code,
    But i m not getting the grand total by default.No error but not getting the desired result.
    Could you please help me in this regard.
    FORM  display_simple_alv.
      DATA :  lr_msg  TYPE   REF   TO  cx_salv_msg.
      DATA : lv_header   TYPE   REF   TO  cl_salv_form_layout_grid,
             lv_h_label  TYPE   REF   TO  cl_salv_form_label,
             lv_h_flow   TYPE   REF   TO  cl_salv_form_layout_flow.
      DATA: gr_sorts TYPE REF TO cl_salv_sorts.
      DATA: gr_agg TYPE REF TO cl_salv_aggregations.
      TRY .
          cl_salv_table=>factory(  IMPORTING  r_salv_table = gr_salv_table
                                   CHANGING  t_table = gt_invdetails4 ).
        CATCH  cx_salv_msg  INTO  lr_msg.
      ENDTRY  .
    Display Basic Toolbar
      gr_functions = gr_salv_table->get_functions( ).
      gr_functions->set_all( abap_true ).
      TRY .
          gr_columns = gr_salv_table->get_columns(  ).
          gr_columns->set_optimize( ).
        CATCH  cx_salv_not_found.
      ENDTRY .
      TRY .
          gr_column ?= gr_columns->get_column(  'KUNNR'  ).
          gr_column->set_long_text(  text-009 ).
          gr_column->set_medium_text(  text-009 ).
          gr_column->set_short_text(  text-009 ).
          gr_column ?= gr_columns->get_column(  'NAME1'  ).
          gr_column->set_long_text(  text-010 ).
          gr_column->set_medium_text(  text-010 ).
          gr_column->set_short_text(  text-011 ).
          gr_column ?= gr_columns->get_column(  'AMOUNT'  ).
          gr_column->set_long_text(  text-012 ).
          gr_column->set_medium_text(  text-012 ).
          gr_column->set_short_text(  text-012 ).
          gr_column ?= gr_columns->get_column(  'TAX'  ).
          gr_column->set_long_text(  text-013 ).
          gr_column->set_medium_text(  text-013 ).
          gr_column->set_short_text(  text-013 ).
          gr_column ?= gr_columns->get_column(  'IVA'  ).
          gr_column->set_long_text(  text-014 ).
          gr_column->set_medium_text(  text-014 ).
          gr_column->set_short_text(  text-015 ).
          gr_column ?= gr_columns->get_column(  'TOTAL_AMOUNT'  ).
          gr_column->set_long_text(  text-016 ).
          gr_column->set_medium_text(  text-016 ).
          gr_column->set_short_text(  text-017 ).
          gr_column ?= gr_columns->get_column(  'CURRENCY'  ).
          gr_column->set_long_text(  text-018 ).
          gr_column->set_medium_text(  text-018 ).
          gr_column->set_short_text(  text-018 ).
          gr_column ?= gr_columns->get_column(  'ZINTERNAL_REFNO'  ).
          gr_column->set_long_text(  text-019 ).
          gr_column->set_medium_text(  text-019 ).
          gr_column->set_short_text(  text-019 ).
          gr_column ?= gr_columns->get_column(  'MATERIAL_AMOUNT'  ).
          gr_column->set_long_text(  text-020 ).
          gr_column->set_medium_text(  text-020 ).
          gr_column->set_short_text(  text-021 ).
          gr_column ?= gr_columns->get_column(  'LABOUR_VALUE'  ).
          gr_column->set_long_text(  text-022 ).
          gr_column->set_medium_text(  text-022 ).
          gr_column->set_short_text(  text-023 ).
          gr_column ?= gr_columns->get_column(  'FAILURE_COST'  ).
          gr_column->set_long_text(  text-024 ).
          gr_column->set_medium_text(  text-024 ).
          gr_column->set_short_text(  text-021 ).
          gr_sorts = gr_salv_table->get_sorts( ).
          gr_sorts->add_sort( columnname = 'AMOUNT' subtotal = abap_true ). "for subtotal
          gr_agg = gr_salv_table->get_aggregations( ).
          gr_agg->add_aggregation( 'AMOUNT' ).
        CATCH  cx_salv_not_found cx_salv_data_error cx_salv_existing.
      ENDTRY .
    Set top of page
      CREATE OBJECT lv_header.
      lv_h_label = lv_header->create_label( row =  1  column =  1  ).
      lv_h_label->set_text(  text-001  ).
      lv_h_label = lv_header->create_label( row =  1  column = 5  ).
      lv_h_label->set_text(  text-002  ).
      lv_h_label = lv_header->create_label( row =  1  column = 14  ).
      lv_h_label->set_text(  text-003  ).
      lv_h_flow = lv_header->create_flow( row =  3  column =  04  ).
      lv_h_flow->create_text(  text  =  text-004  ).
      lv_h_flow = lv_header->create_flow( row =  3  column =  05  ).
      lv_h_flow->create_text(  text  =  text-005  ).
      lv_h_flow = lv_header->create_flow( row =  3  column =  06  ).
      lv_h_flow->create_text(  text  =  name  ).
      set the top of list using the header for Online.
      gr_salv_table->set_top_of_list( lv_header ).
    ALV Display
      gr_salv_table->display( ).
    ENDFORM .                     " DISPLAY_SIMPLE_ALV

    Hi Sridevi,
    To get the grand total, you need to pass the SORT itab to the function module. You need to populate the internal table with the fields on which you want the total or subtotal. If you donu2019t pass this table, you wonu2019t get it.
    For ex:
       ls_sort_wa-spos = 1.
      ls_sort_wa-fieldname = gs_plant-werks.
      ls_sort_wa-up = 'X'.
      ls_sort_wa-subtot = 'X'.
      APPEND ls_sort_wa TO gt_sort.
    So the above code, gives the sub total plant wise.
    and if you want the sum(grand total) you can set the DO_SUM to u2018Xu2019 for that particular field in the field catalog.
    So with this approach, you can get the sub total and grand total for a particular field.
    If you donu2019t want the subtotal, just set DO_SUM, you will get the total.
    Thanks,
    Srini.

  • How to do subtotal and grand total as per currency in a tree ALV

    Hi Experts,
    I am doing a tree ALV for SD output. I met an urgent problem that is how to do subtotal and grand total on the field (netwr) as per currency (waerk) in the tree ALV. I am using below codes to create the tree ALV.
        l_tree_container_name = 'CCONTAINER1'.
        CREATE OBJECT objCustomContainer
            EXPORTING
                  container_name = l_tree_container_name
            EXCEPTIONS
                  cntl_error                  = 1
                  cntl_system_error      = 2
                  create_error               = 3
                  lifetime_error              = 4
                  lifetime_dynpro_dynpro_link = 5.
    create tree control
        CREATE OBJECT objTree1
          EXPORTING
              parent              = objCustomContainer
              node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
              item_selection      = ' '
              no_html_header      = 'X'
              no_toolbar          = ''
          EXCEPTIONS
              cntl_error                   = 1
              cntl_system_error       = 2
              create_error                = 3
              lifetime_error               = 4
              illegal_node_selection_mode  = 5
              failed                       = 6
              illegal_column_name          = 7.
        DATA l_hierarchy_header TYPE treev_hhdr.
        call method buildHierarchyHeader
          IMPORTING
            p_hierarchy_header = l_hierarchy_header.
    Build fieldcatalog
        call method buildFieldcatalog.
        CALL METHOD objTree1->set_table_for_first_display
            EXPORTING
              is_hierarchy_header = l_hierarchy_header
            CHANGING
              it_fieldcatalog     = l_fieldcatalog
              it_outtab            = lt_order.             
        CALL METHOD objTree1->update_calculations.
        CALL METHOD objTree1->frontend_update.
    filling fieldcatalog,
          LS_FIELDCATALOG-FIELDNAME = 'NETWR'.
          LS_FIELDCATALOG-SCRTEXT_S = 'Net Value'.
          LS_FIELDCATALOG-COL_POS = l_pos.
          LS_FIELDCATALOG-OUTPUTLEN = 15.
          LS_fieldcatalog-do_dum= 'X'.
          LS_FIELDCATALOG-DATATYPE = 'CURR'.
          APPEND LS_FIELDCATALOG TO l_FIELDCATALOG.
          CLEAR LS_FIELDCATALOG.
          l_pos = l_pos + 1.
    I could see the subtotal and grandtotal in tree ALV but they are simply sumed up  regardless different currency.
    Thank you very much for your kindly helps.
    Yu

    hi
    good
    go through this report and work accordingly.
    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.
    thanks
    mrutyun^

  • How to create a sub total and grand total using my query.

    How can I create a sub total for each section and grand total for using my query like this.  your help is appreciated. I am working with 9g
    WITH  BidItemsInformation  AS
    ( SELECT DISTINCT q.iplineno "Line Number", q.section "Section Number",
             i.item "Item Number",
             initcap(i.idescr) "Description" ,
             i.iunits "Unit",
             q.qty "Quantity" ,q.price  "Engineers Unit Price",
           (q.price * q.qty) "Engineers Estimate"
         FROM letprop l,
            proposal p,
            propitem q,
            bidlet b,
            bidtabs c,
            itemlist i,
            vendor v,
            bidders d 
         WHERE(l.letting = b.letting
                And b.letting = c.letting
                And p.cspecyr = i.ispecyr)
                AND q.prpitem = i.item
                AND p.contid = l.lcontid
                AND q.contid = p.contid
                AND c.vendor = l.avendor
                AND l.CALL = c.CALL
                AND q.lineflag = c.lineflag
                AND q.iplineno = c.iplineno
                AND l.letting = d.letting 
                AND c.letting = l.letting
                AND c.CALL = d.CALL
                AND v.vendor = d.vendor
                --  AND AND l.letstat = 'A'
                AND c.lineflag = 'L'
                AND  l.letting ='&letting'
                AND l.CALL = '&call'
    ), BiddersInformation  AS
    -- This is where you make your changes for vendor name and vendor number Do not touch the above code
    -- It is always the same for any call number and letting date
    ( SELECT IPLINENO "BLine Number",
            MAX(CASE WHEN VENDOR='K020'  THEN bidprice ELSE NULL END) "K020:: Unit Price",
            MAX(CASE WHEN VENDOR='K020'  THEN bidprice ELSE NULL END) K,
            MAX(CASE WHEN VENDOR='H438'  THEN bidprice ELSE NULL END) "H438:: Unit Price",
            MAX(CASE WHEN VENDOR='H438'  THEN bidprice ELSE NULL END) H,
            MAX(CASE WHEN VENDOR='U010'  THEN bidprice ELSE NULL END) "U010:: Unit Price",
            MAX(CASE WHEN VENDOR='U010'  THEN bidprice ELSE NULL END) U,
            MAX(CASE WHEN VENDOR='G110'  THEN bidprice ELSE NULL END) "G110:: Unit Price",
            MAX(CASE WHEN VENDOR='G110'  THEN bidprice ELSE NULL END) G,
            MAX(CASE WHEN VENDOR='H530'  THEN bidprice ELSE NULL END) "H530:: Unit Price",
            MAX(CASE WHEN VENDOR='H530'  THEN bidprice ELSE NULL END) H1
        FROM  BIDTABS
        WHERE LETTING='&letting'
              AND CALL='&call'
              AND BIDPRICE <> 0
        GROUP BY IPLINENO
    SELECT BidItemsInformation."Line Number",
           BidItemsInformation."Section Number",
           BidItemsInformation."Item Number",
           BidItemsInformation."Description",
           BidItemsInformation."Unit",
           BidItemsInformation."Quantity",
           BidItemsInformation."Engineers Unit Price",
           BidItemsInformation."Engineers Estimate",
           BiddersInformation."K020:: Unit Price",
            (BidItemsInformation."Quantity" * K) "KGM CONTRACTORS INC",
           BiddersInformation."H438:: Unit Price",       
            (BidItemsInformation."Quantity" * H) "HOFFMAN CONSTRUCTION COMPAN",
           BiddersInformation."U010:: Unit Price",       
            (BidItemsInformation."Quantity" * U) "ULLAND BROTHERS INC",
           BiddersInformation."G110:: Unit Price",      
            (BidItemsInformation."Quantity" * G) "GLADEN CONSTRUCTION INC",
           BiddersInformation."H530:: Unit Price",      
            (BidItemsInformation."Quantity" * H1) "HOOVER CONSTRUCTION CO"
    FROM   BidItemsInformation,BiddersInformation
    WHERE  BidItemsInformation."Line Number" = BiddersInformation."BLine Number";
    Line Number     Section Number     Item Number     Description     Unit     Quantity     Engineers Unit Price     Engineers Estimate     K020:: Unit Price     
    0010     0001     2011601/00003     Construction Surveying     LS       1     143,000     143,000     75,000     75,000     67,080     67,080
    0013     0001     2013601/00010     Survey Equipment     LS       1     25,000     25,000     25,000     25,000     30,000     30,000
    0020     0001     2015601/00030     Blast Monitor/Survey     LS       1     50,000     50,000     30,000     30,000     35,000     35,000
    0030     0001     2021501/00010     Mobilization     LS       1     382,250     382,250     809,000     809,000     704,000     704,000
    0040     0001     2021602/00010     Well Survey     EACH     60     500     30,000     2,150     129,000     1,600     96,000
    0050     0001     2031501/00040     Field Office Type D     EACH     1     6,367     6,367     4,000     4,000     25,000     25,000
    sub total:
    1610     0002     2401501/01143     Structural Concrete (1a43)     C Y      46     350     16,100     408     18,768     400     18,400
    1620     0002     2401501/01362     Structural Concrete (1c62)     C Y      68     200     13,600     204     13,872     200     13,600
    1630     0002     2401501/03643     Structural Concrete (3y43)     C Y      60     600     36,000     592     35,520     580     34,800
    1640     0002     2401512/03633     Bridge Slab Concrete (3y33)     S F      1,876     24     45,024     28     51,778     27     50,652
    1650     0002     2401521/00030     Structure Excavation Class R     C Y      17     125     2,125     1,000     17,000     500     8,500
    1660     0002     2401541/00010     Reinforcement Bars     LB       2,490     2     3,735     1     3,312     1     3,237
    1670     0002     2401541/00011     Reinforcement Bars (Epoxy Coated)     LB       12,380     2     18,570     1     17,703     1     17,332
    1680     0002     2401601/00010     Structure Excavation     LS       1     2,500     2,500     2,000     2,000     5,000     5,000
    1690     0002     2402583/00020     Ornamental Metal Railing Type Special     L F      284     150     42,600     194     55,096     190     53,960
    sub total
    1820     0003     2401513/00346     Type Curb Railing Concrete (3y46)     L F      135     25     3,375     16     2,093     15     2,025
    1830     0003     2401513/07447     Type Mod P-4 (Tl-4) Railing Conc (3y46)     L F      302     85     25,670     72     21,593     70     21,140
    1840     0003     2401541/00010     Reinforcement Bars     LB       14,780     1     18,475     1     13,598     1     13,302
    1850     0003     2401541/00011     Reinforcement Bars (Epoxy Coated)     LB       76,720     1     103,572     1     85,926     1     84,392
    1860     0003     2401601/00010     Structure Excavation     LS       1     10,000     10,000     116,000     116,000     115,000     115,000
    1870     0003     2402583/00020     Ornamental Metal Railing Type Special     L F      132     150     19,800     184     24,288     180     23,760
    sub total
    total

    You can accomplish that using decode with the grouping function. It returns 1 when that column passed as argument was grouped (or is in some total) and 0 otherwise.
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> with t as
      2  (select 'New York' city, 'US' country, 1 num from dual
      3  union all select 'Los Angeles' city, 'US' country, 2 num from dual
      4  union all select 'London' city, 'GB' country, 2 num from dual
      5  union all select 'London' city, 'GB' country, 2 num from dual
      6  union all select 'London' city, 'GB' country, 7 num from dual)
      7  select decode(grouping(country), 0, country, 'GRAND TOTAL') country,
      8         decode(grouping(city), 0, city, decode(grouping(country), 0, 'SUBTOTAL')) city,
      9         sum(num) num_total
    10   from t
    11  group by rollup(country, city)
    12  /
    COUNTRY     CITY         NUM_TOTAL
    GB          London              11
    GB          SUBTOTAL            11
    US          New York             1
    US          Los Angeles          2
    US          SUBTOTAL             3
    GRAND TOTAL                     14
    6 linhas selecionadas.
    SQL>

  • How to display subtotal and grand total with a top 10 condistion ?

    Hello,
    I would like to display a Top 10 list with subtotal for Top 10 and grand total for all the lines.
    I succeed to display top 10 subtotal with "calculations/total" parameter but my question is How to display also the grand total for all the lines ?
    Thank you in advance.
    Best regards
    Nicolas

    Calculate Results/not defined gives grand total and calculation / total gives top 10 sum. As far as I know, you can't display both at the same time.

  • Subtotal in ALV grid for a particular type and Grand total in ALV

    Hi,
    I need to have sub total for a particular type(eg: goods, services).. and grand total at end in ALV grid..
    ALV output required as below:
    Type     VAT registration number     Country      Total Gross Amounts       Total Tax Amounts       Total Amount, ex-tax
    Goods     ATU12345678     AT                  222.42      0         222.42
    Goods     NL123456789B02     NL               3,417.00      0      3,417.00
         Goods Total                    3,639.42                -         3,639.42
    Services     ATU12345678     AT               2,342.34      0      2,342.34
    Services     NL123456789B02     NL                  223.33      0         223.33
         Services Total                    2,565.67                -         2,565.67
         Grand Total                    6,205.09                -         6,205.09
    Let me as to how to achieve the above type in ALV grid...
    Regards
    Shiva

    check this link..
    Grand Totals in ALV grid disply function module
    or do like this..
    REPORT  ZALVTESTFORSUBTOTAL.
    tables:pa0008.
    type-pools:slis.
    types:begin of ty_pa0008,
          pernr like pa0008-pernr,
          begda like pa0008-begda,
          endda like pa0008-endda,
          ansal like pa0008-ansal,
          lga01 like pa0008-lga01,
          bet01 like pa0008-bet01,
          end of ty_pa0008.
    data:it_pa0008 type standard table of ty_pa0008 with header line.
    data:it_fieldcat type SLIS_T_FIELDCAT_ALV,
         wa_fieldcat type slis_fieldcat_alv,
         it_layout type slis_layout_alv,
         WA_events TYPE slis_alv_event,
         it_events TYPE slis_t_event.
    select-options:s_pernr for pa0008-pernr.
    start-of-selection.
    perform getD_data.
    perform disp_alv.
    *&      Form  getD_data
          text
    -->  p1        text
    <--  p2        text
    form getD_data .
    select pernr
           begda
           endda
           ansal
           lga01
           bet01
           from pa0008
           into table it_pa0008
           where pernr in s_pernr.
    sort it_pa0008 by pernr begda descending.
    endform.                    " getD_data
    *&      Form  disp_alv
          text
    -->  p1        text
    <--  p2        text
    form disp_alv .
    wa_fieldcat-fieldname = 'PERNR'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Personnel no'.
    *WA_FIELDCAT-no_subtotals = 'X'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'BEGDA'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Start date'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'ENDDA'.
    wa_FIELDCAT-REPTEXT_DDIC = 'End date'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'ANSAL'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Annula salary'.
    wa_fieldcat-do_sum = 'X'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'LGA01'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Wage Type'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'BET01'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Amount for wagetype'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    DATA: sort TYPE slis_sortinfo_alv,
    it_sort TYPE slis_t_sortinfo_alv.
    sort-fieldname = 'PERNR'.
    sort-subtot = 'X'.
    SORT-UP = 'X'.
    APPEND sort TO it_sort.
    *sort-fieldname = 'BEGDA'.
    *SORT-NO_SUBTOTS = 'X'.
    *APPEND sort TO it_sort.
    IT_layout-totals_text = 'total text'.
    IT_layout-subtotals_text = 'Subtotal text'.
    *WA_EVENTS-NAME = 'SUBTOTAL TEXT'.
    *WA_EVENTS-FORM = 'SUBTOTAL TEXT'.
    *APPEND WA_EVENTS TO IT_EVENTS.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM             = sy-repid
       IS_LAYOUT                      = it_LAYOUT
       IT_FIELDCAT                    = IT_FIELDCAT
       it_sort                        = it_sort
      it_events                      = it_events
       TABLES
        t_outtab                       = it_pa0008 .
    endform.                    " disp_alv

  • Setting currency and measurement unit for a field in an ALV report

    Plz give sample code to set currency and measurement unit for a field in an ALV report

    dear friend
    i am seanding you
    the display form
    if you need select form
    and process form also pls keep in touch.
    if help full rewards are expecting.
    yours
    vivek
    FORM build_field_catalog .
      DATA: w_dthigh(10).
      CLEAR fcat.
      fcat-fieldname = 'VBELN'.
      fcat-outputlen = 10.
      fcat-seltext_s = 'COMMERCIAL INVOICE'.
      fcat-seltext_m = 'Commercial Invoice'.
      fcat-seltext_l = 'COMMERCIAL INVOICE'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      fcat-key = 'X'.
      fcat-hotspot = 'X'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'EXNUM'.
      fcat-outputlen = 10.
      fcat-seltext_s = 'EXCISE INVOICE'.
      fcat-seltext_m = 'Excise Invoice'.
      fcat-seltext_l = 'EXCISE INVOICE'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      fcat-hotspot = 'X'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'EXDAT'.
      fcat-outputlen = 10.
      fcat-seltext_s = 'EXCISE DATE'.
      fcat-seltext_m = 'Excise Date'.
      fcat-seltext_l = 'EXCISE DATE'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'D'.
      fcat-datatype = 'DATS'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'NAME1'.
      fcat-outputlen = 30.
      fcat-seltext_s = 'CUSTOMER'.
      fcat-seltext_m = 'Customer'.
      fcat-seltext_l = 'CUSTOMER'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      fcat-lowercase = 'X'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'ZZPD'.
      fcat-outputlen = 15.
      fcat-seltext_s = 'COUNTRY'.
      fcat-seltext_m = 'COUNTRY'.
      fcat-seltext_l = 'COUNTRY'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      fcat-lowercase = 'X'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'WERKS'.
      fcat-outputlen = 4.
      fcat-seltext_s = 'PLANT'.
      fcat-seltext_m = 'Plant'.
      fcat-seltext_l = 'PLANT'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      fcat-key = 'X'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'ARKTX'.
      fcat-outputlen = 40.
      fcat-seltext_s = 'MATERIAL DESCRIPTION'.
      fcat-seltext_m = 'Material Description'.
      fcat-seltext_l = 'MATERIAL DESCRIPTION'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      fcat-lowercase = 'X'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'FKART'.
      fcat-outputlen = 4.
      fcat-seltext_s = 'Billing type'.
      fcat-seltext_m = 'Billing type'.
      fcat-seltext_l = 'Billing type'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      fcat-key = 'X'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'INCO1'.
      fcat-outputlen = 5.
      fcat-seltext_s = 'INCO TERMS'.
      fcat-seltext_m = 'INCO TERMS'.
      fcat-seltext_l = 'INCO TERMS'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'INCO2'.
      fcat-outputlen = 10.
      fcat-seltext_s = 'INCO TERMS DES'.
      fcat-seltext_m = 'INCO TERMS DES'.
      fcat-seltext_l = 'INCO TERMS DES'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      APPEND fcat.
    CLEAR fcat.
    fcat-fieldname = 'FKIMG'.
    fcat-outputlen = 14.
    fcat-seltext_s = 'QUANTITY'.
    fcat-seltext_m = 'Quantity'.
    fcat-seltext_l = 'QUANTITY'.
    fcat-ddictxt = 'M'.
    fcat-inttype = 'P'.
    fcat-datatype = 'QUAN'.
    APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'FKLMG'.
      fcat-outputlen = 10.
      fcat-seltext_s = 'QUANTITY'.
      fcat-seltext_m = 'QUANTITY'.
      fcat-seltext_l = 'QUANTITY'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'P'.
      fcat-datatype = 'QUAN'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'MEINS'.
      fcat-outputlen = 5.
      fcat-seltext_s = 'UNIT'.
      fcat-seltext_m = 'UNIT'.
      fcat-seltext_l = 'UNIT'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CHAR'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'KBETR'.
      fcat-outputlen = 8.
      fcat-seltext_s = 'RATE'.
      fcat-seltext_m = 'Rate'.
      fcat-seltext_l = 'RATE'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'P'.
      fcat-datatype = 'CURR'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'NSR'.
      fcat-outputlen = 8.
      fcat-seltext_s = 'Exmill'.
      fcat-seltext_m = 'Exmill'.
      fcat-seltext_l = 'Exmill'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'P'.
      fcat-datatype = 'CURR'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'KURSK'.
      fcat-outputlen = 8.
      fcat-seltext_s = 'EXCHANGE RATE'.
      fcat-seltext_m = 'Exchange Rate'.
      fcat-seltext_l = 'Exchange Rate'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'P'.
      fcat-datatype = 'CURR'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'WAERK'.
      fcat-outputlen = 5.
      fcat-seltext_s = 'CURRENCY'.
      fcat-seltext_m = 'Currency'.
      fcat-seltext_l = 'CURRENCY'.
      fcat-ddictxt = 'M'.
      fcat-inttype = 'C'.
      fcat-datatype = 'CUKY'.
      APPEND fcat.
      CLEAR fcat.
      fcat-fieldname = 'LCURR1'.
      fcat-outputlen = 14.
      fcat-seltext_s = 'GROSS AMT'.
      fcat-seltext_m = 'Gross Amt'.
      fcat-seltext_l = 'GROSS AMT'.
      fcat-ddictxt = 'L'.
      fcat-inttype = 'P'.
      fcat-datatype = 'CURR'.
    fcat-do_sum = 'X'.
      APPEND fcat.
    ================================= *****************
      fheader-typ = 'H'.
      SELECT SINGLE butxt
        FROM t001
        INTO fheader-info
       WHERE bukrs EQ '1000'.
      APPEND fheader.
      CLEAR fheader.
      fheader-typ = 'H'.
      fheader-info = 'Daily Shipments For Exp'.
      APPEND fheader.
      CLEAR fheader.
    Plant
      SORT s_werks BY low.
      READ TABLE s_werks INDEX 1.
      fheader-typ = 'S'.
      WRITE s_werks-low TO fheader-key.
      SORT s_werks BY high DESCENDING.
      READ TABLE s_werks INDEX 1.
      IF s_werks-high NE space.
        CONCATENATE fheader-key 'TO' s_werks-high INTO fheader-info
                                SEPARATED BY space.
      ELSE.
        WRITE fheader-key TO fheader-info.
      ENDIF.
      CLEAR fheader-key.
      fheader-key = 'PLANT : '.
      APPEND fheader.
      CLEAR fheader.
    Billing Typ
    SORT S_FKART BY LOW.
    READ TABLE S_FKART INDEX 1.
    FHEADER-TYP = 'S'.
    WRITE S_FKART-LOW TO FHEADER-KEY.
    SORT S_FKART BY HIGH DESCENDING.
    READ TABLE S_FKART INDEX 1.
    IF S_FKART-HIGH NE SPACE.
    CONCATENATE FHEADER-KEY 'TO' S_FKART-HIGH INTO FHEADER-INFO
                             SEPARATED BY SPACE.
    ELSE.
       WRITE FHEADER-KEY TO FHEADER-INFO.
    ENDIF.
    CLEAR FHEADER-KEY.
    FHEADER-KEY = 'DOCUMENT TYPE : '.
    APPEND FHEADER.
    CLEAR FHEADER.
    Date...
      fheader-typ = 'S'.
    FHEADER-KEY = S_FKDAT-LOW.
      WRITE s_fkdat-low  TO fheader-key.
      WRITE s_fkdat-high TO w_dthigh.
      CONCATENATE fheader-key 'TO' w_dthigh INTO fheader-info
                              SEPARATED BY space.
      CLEAR fheader-key.
      fheader-key = 'PERIOD : '.
      APPEND fheader.
      CLEAR fheader.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = fevents[]
        EXCEPTIONS
          list_type_wrong = 1
          OTHERS          = 2.
      READ TABLE fevents WITH KEY name = 'TOP_OF_PAGE'.
      IF sy-subrc = 0.
        fevents-form = 'TOPOFPAGE'.
        MODIFY fevents INDEX sy-tabix.
        CLEAR fevents.
      ENDIF.
      rptname = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
                        EXPORTING
                          i_callback_program                = rptname
                          it_fieldcat                       = fcat[]
                          i_default                         = 'S'
                          it_events                         = fevents[]
                          i_save                            = 'X'
                         TABLES
                           t_outtab                          = it_output[]
                      EXCEPTIONS
                        PROGRAM_ERROR                     = 1
                        OTHERS                            = 2
    ENDFORM.                    " BUILD_FIELD_CATALOG

  • Can we get subtotal and grand total by own calculation in a hierarchy ALV?

    Can we get subtotal and grand total by own calculation in a hierarchy ALV? I can get them by setting DO_SUM = 'X' by standard summation, but now I need to do my own summation on subtotal and total, can I?

    Can we get subtotal and grand total by own calculation in a hierarchy ALV? I can get them by setting DO_SUM = 'X' by standard summation, but now I need to do my own summation on subtotal and total, can I?

  • Grand Totals for GOURL columns

    We are having an issue showing Grand Totals for GOURL enabled columns
    We have enabled GOURL on the amount columns, To enable hyperlink we had to convert the the number column to character. Enabling the Grand total in the Table View is thorwing error "Function Report_Sum does not support non-numeric types".
    Any input on the above would be of great help.
    We are using OBIEE version 10.1.3.4
    Thanks
    Kranthi

    You can try the following..
    1) Keep the same name for all the amount fields in each column. (for example, first amount column field name is "Amount1" and second column field name is "Amount2").
    2) Then write the code in the Calculate event of the Total field. (Use FormCalc)
         Total1.rawValue = Sum(Table1.Row1[*].Amount1);
    3) Similarly for Second column
         Total2.rawValue = Sum(Table1.Row1[*].Amount2);
    4) For the total of Amount1 and Amount2.
         LoanTotal = Sum(Total1.rawValue + Total2.rawValue);
    Hope this helps.
    Thanks
    Srini

Maybe you are looking for

  • Do Not Buy From Sony

    Do not buy from Sony if you work. After 3 delivery attempts FedEx is required by Sony to ship it back to them. You CANNOT go to a FedEx facility to pick it up. After 5 phone calls with Sony support no one was willing to help me. I don't know how peop

  • How can I add the new project? (for mac)

    I can't add the new project. Who can help to do this action?

  • ISync 3, Leopard 10.5.2 & Sony Ericsson W880i

    I have the SE W880i which worked just lovely with the Feisar plug-in but now, while iSync goes all through the process and completes and everything - iCal doesn't update the phone's calendar nor do events created on the phone update to iCal. It looks

  • Delivery route determination

    Hi All, Diffrent Route determine in  sales order and delivery. Ship to party is same in both the document

  • How to create a new data warehouse?

    Hi, I have a set up where multiple SCOM management groups all report to a shared data warehouse database. For various reasons, we need to "unplug" the management groups from this shared resource and give them each their own data warehouse to use (loc