<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: sum in grid in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582769#M590696</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi friend  here  is the  program for  totalling  as your screen shot shows ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this  is   the fields  defiend  in the field catalog &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  "fieldcatalog-do_sum      = 'X'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;" After executeing    do   sum  by every field   using the  ICON  sigma 
" with  small  sigma  .... so that it  will give your output ..&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  zdemo_alvgrid                 .

TABLES:     ekko.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
 END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.

*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  BUILD_FIELDCATALOG
*&amp;amp;---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you  more control of the final product.

* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
*               I.e. Field type may be required in-order for
*                    the 'TOTAL' function to work.

  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  fieldcatalog-do_sum      = 'X'.

  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  fieldcatalog-do_sum      = 'X'.

  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  fieldcatalog-do_sum      = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-do_sum      = 'X'.        "Display column total
  fieldcatalog-datatype     = 'CURR'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 8.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.
endform.                    " BUILD_FIELDCATALOG


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  BUILD_LAYOUT
*&amp;amp;---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
endform.                    " BUILD_LAYOUT


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  DISPLAY_ALV_REPORT
*&amp;amp;---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = gd_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             = fieldcatalog[]
*            it_special_groups       = gd_tabgroup
*            IT_EVENTS                = GT_XEVENTS
            i_save                  = 'X'
*            is_variant              = z_template

       tables
            t_outtab                = it_ekko
       exceptions
            program_error           = 1
            others                  = 2.
  if sy-subrc &amp;lt;&amp;gt; 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
endform.                    " DISPLAY_ALV_REPORT


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  DATA_RETRIEVAL
*&amp;amp;---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.

select ebeln ebelp statu aedat matnr menge meins netpr peinh
 up to 10 rows
  from ekpo
  into table it_ekko.
endform.                    " DATA_RETRIEVAL&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward  points if it is usefull ...&lt;/P&gt;&lt;P&gt;Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Aug 2007 05:25:05 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-08-07T05:25:05Z</dc:date>
    <item>
      <title>sum in grid</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582767#M590694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi. I have a question. How to make such thing in grid:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
record 1
record 2
...
record n
SUM 1
record n+1
...
record m
SUM 2
SUM 3 = SUM 1 + SUM 2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's sth like this: &lt;A href="http://www.erpgenie.com/sap/abap/controls/alvgri3.jpg" target="test_blank"&gt;http://www.erpgenie.com/sap/abap/controls/alvgri3.jpg&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2007 12:37:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582767#M590694</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-06T12:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: sum in grid</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582768#M590695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I depends on what version of ALV you are using?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you using FM REUSE_ALV_LIST_DISPLAY?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you using class CL_GUI_ALV_GRID?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you using simplified ALV SALV class cl_salv_table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are different ways to do it based on what versin of ALV you are using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) REUSE_ALV_LIST_DISPLAY&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Set up a sort table similar to the way that you set up a field catalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This identifies the fields that you want to sort and subtotal by:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data: lt_slis_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;data: lt_slis_fcat type slis_t_fieldcat_alv WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load the appropriate fields and then call the FM:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lt_slis_sort-spos = 1.  " Sort position&lt;/P&gt;&lt;P&gt;lt_slis_sort-fieldname = 'FIELD1'.  " Name of field to sort on&lt;/P&gt;&lt;P&gt;lt_slis_sort-'GT-OUTTAB'. "internal table with ALV grid data&lt;/P&gt;&lt;P&gt;lt_slis_sort-up = 'X'.  " X = sort ascending, blank otherwise&lt;/P&gt;&lt;P&gt;lt_slis_sort-down = ' '.  " X = sort descending, blank otherwise&lt;/P&gt;&lt;P&gt;lt_slis_sort-subtot = ' X'.  " X = subtotal on breaks of this field&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; etc -- see type pool SLIS for more info on available fields&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Append lt_slis_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each field to be summed up when subtotaled are to display, set the do_sum flag in the field catalog:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lt_slis_fcat-do_sum = 'X'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_bypassing_buffer       = gs_test-bypassing_buffer
          i_buffer_active          = gs_test-buffer_active
          i_callback_program       = g_repid
          i_callback_pf_status_set = 'F01_ALV_EVENT_PF_STATUS_SET'
          i_callback_user_command  = 'F01_ALV_EVENT_USER_COMMAND'
          is_layout                = ls_slis_layo
          it_fieldcat              = lt_slis_fcat
          it_sort                  = lt_slis_sort
          it_filter                = lt_slis_filt
          i_default                = gs_test-vari_default
          i_save                   = gs_test-vari_save
          is_variant               = ls_vari
          is_print                 = ls_slis_prnt
        tables
          t_outtab                 = gt_outtab
        exceptions
          program_error            = 1
          others                   = 2.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In SE84 Information System, you can look up sample programs BALV*&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, programs BALVST02 and BALVST02_GRID have sort code.  You could adapt this to your needs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="----------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The technique is similar for CL_GUI_ALV_GRID, but the type are different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The sort table type for CL_GUI_ALV_GRID is LVC_T_SORT, the basic field names are the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The field catalog type is LVC_T_FCAT, and you would still use do_sum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pass the sort table in your method call:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;    CALL METHOD alv_list_ref-&amp;gt;set_table_for_first_display
      EXPORTING
        is_layout            = i_layout
        it_toolbar_excluding = i_toolbar_excl
      CHANGING
        it_outtab            = i_alv_grid_tab
        it_fieldcatalog      = i_fieldcat
        it_sort                 = sort_table.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="---------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If using SALV, it is a bit different, and there are methods to use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CONSTANTS: gc_true        TYPE sap_bool VALUE 'X',
           gc_false       TYPE sap_bool VALUE ' '.

  DATA: lr_sorts            TYPE REF TO cl_salv_sorts.
  DATA: lr_agg              TYPE REF TO cl_salv_aggregations.

  TRY.
      lr_sorts = gr_table-&amp;gt;get_sorts( ).
      lr_sorts-&amp;gt;add_sort( columnname = 'FIELD1'     subtotal = gc_true ).
      lr_sorts-&amp;gt;add_sort( columnname = 'FIELD2'    subtotal = gc_true ).

*etc, as many sort field as you need.  leave out the
*subtotal parameter if no subtotal on that sort.

    CATCH cx_salv_existing.                             "#EC NO_HANDLER
    CATCH cx_salv_not_found.                            "#EC NO_HANDLER
    CATCH cx_salv_data_error.                           "#EC NO_HANDLER
  ENDTRY.

*To set the fields to sum, do the following
  TRY.
      lr_agg = gr_table-&amp;gt;get_aggregations( ).
      lr_agg-&amp;gt;add_aggregation( 'SUM_FIELD1' ).
      lr_agg-&amp;gt;add_aggregation( 'SUM_FIELD2' ).

*etc, as many sum fields as you need.  

    CATCH cx_salv_existing.                             "#EC NO_HANDLER
    CATCH cx_salv_not_found.                            "#EC NO_HANDLER
    CATCH cx_salv_data_error.                           "#EC NO_HANDLER
  ENDTRY.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;good luck&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;brian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Brian Sammond, fixed typos&lt;/P&gt;&lt;P&gt;        Brian Sammond&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        Brian Sammond&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2007 18:23:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582768#M590695</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-06T18:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: sum in grid</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582769#M590696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi friend  here  is the  program for  totalling  as your screen shot shows ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this  is   the fields  defiend  in the field catalog &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  "fieldcatalog-do_sum      = 'X'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;" After executeing    do   sum  by every field   using the  ICON  sigma 
" with  small  sigma  .... so that it  will give your output ..&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  zdemo_alvgrid                 .

TABLES:     ekko.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
 END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.

*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  BUILD_FIELDCATALOG
*&amp;amp;---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you  more control of the final product.

* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
*               I.e. Field type may be required in-order for
*                    the 'TOTAL' function to work.

  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  fieldcatalog-do_sum      = 'X'.

  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  fieldcatalog-do_sum      = 'X'.

  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  fieldcatalog-do_sum      = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-do_sum      = 'X'.        "Display column total
  fieldcatalog-datatype     = 'CURR'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 8.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.
endform.                    " BUILD_FIELDCATALOG


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  BUILD_LAYOUT
*&amp;amp;---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
endform.                    " BUILD_LAYOUT


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  DISPLAY_ALV_REPORT
*&amp;amp;---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = gd_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             = fieldcatalog[]
*            it_special_groups       = gd_tabgroup
*            IT_EVENTS                = GT_XEVENTS
            i_save                  = 'X'
*            is_variant              = z_template

       tables
            t_outtab                = it_ekko
       exceptions
            program_error           = 1
            others                  = 2.
  if sy-subrc &amp;lt;&amp;gt; 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
endform.                    " DISPLAY_ALV_REPORT


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  DATA_RETRIEVAL
*&amp;amp;---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.

select ebeln ebelp statu aedat matnr menge meins netpr peinh
 up to 10 rows
  from ekpo
  into table it_ekko.
endform.                    " DATA_RETRIEVAL&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward  points if it is usefull ...&lt;/P&gt;&lt;P&gt;Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2007 05:25:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582769#M590696</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-07T05:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: sum in grid</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582770#M590697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;  This example shows the use of the method GET_SUBTOTALS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;report zkiran_0006.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;tables: mara.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;type-pools: slis, icon.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Internal Tables&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;data: begin of ialv occurs 0,&lt;/P&gt;&lt;P&gt;      matnr type mara-matnr,&lt;/P&gt;&lt;P&gt;      maktx type makt-maktx,&lt;/P&gt;&lt;P&gt;      brgew type mara-brgew,&lt;/P&gt;&lt;P&gt;      end of ialv .&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;data: alv_container type ref to cl_gui_custom_container,&lt;/P&gt;&lt;P&gt;      alv_grid type ref to cl_gui_alv_grid,&lt;/P&gt;&lt;P&gt;      ok_code like sy-ucomm,&lt;/P&gt;&lt;P&gt;      layout    type lvc_s_layo,&lt;/P&gt;&lt;P&gt;      fieldcat type lvc_t_fcat.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;select-options: s_matnr for mara-matnr.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;start-of-selection.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  perform get_data.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  call screen 100.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     Module  status_0100  OUTPUT&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;P&gt;module status_0100 output.&lt;/P&gt;&lt;P&gt;  set pf-status '0100'.&lt;/P&gt;&lt;P&gt;  set titlebar '0100'.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  data: variant type  disvariant.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  variant-report = sy-repid.&lt;/P&gt;&lt;P&gt;  variant-username = sy-uname.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create Controls&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  create object alv_container&lt;/P&gt;&lt;P&gt;         exporting container_name = 'ALV_CONTAINER'.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  create object alv_grid&lt;/P&gt;&lt;P&gt;         exporting  i_parent =  alv_container.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; Populate Field Catalog&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  perform get_fieldcatalog.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  call method alv_grid-&amp;gt;set_table_for_first_display&lt;/P&gt;&lt;P&gt;      exporting&lt;/P&gt;&lt;P&gt;           is_layout              = layout&lt;/P&gt;&lt;P&gt;           is_variant             = variant&lt;/P&gt;&lt;P&gt;           i_save                 = 'U'&lt;/P&gt;&lt;P&gt;           i_structure_name       = 'IALV'&lt;/P&gt;&lt;P&gt;      changing&lt;/P&gt;&lt;P&gt;           it_outtab       = ialv[]&lt;/P&gt;&lt;P&gt;           it_fieldcatalog = fieldcat[].&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;endmodule.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     Module  USER_COMMAND_0100  INPUT&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;P&gt;module user_command_0100 input.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  case sy-ucomm.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    when 'BACK' or 'CANC'.&lt;/P&gt;&lt;P&gt;      perform free_containers.&lt;/P&gt;&lt;P&gt;      if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;        set screen 0.&lt;/P&gt;&lt;P&gt;        leave screen.&lt;/P&gt;&lt;P&gt;      else.&lt;/P&gt;&lt;P&gt;        leave program.&lt;/P&gt;&lt;P&gt;      endif.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    when 'EXIT'.&lt;/P&gt;&lt;P&gt;      perform free_containers.&lt;/P&gt;&lt;P&gt;      leave program.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    when 'ENTER'.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;      data: grandtots type ref to data.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;      call method alv_grid-&amp;gt;get_subtotals&lt;/P&gt;&lt;P&gt;        importing&lt;/P&gt;&lt;P&gt;          ep_collect00   = grandtots&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT01   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT02   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT03   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT04   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT05   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT06   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT07   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT08   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   EP_COLLECT09   =&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   ET_GROUPLEVELS =&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;          .&lt;/P&gt;&lt;P&gt;      check sy-subrc = 0.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  endcase.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;endmodule.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;*********************************************************************&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      FORM GET_DATA.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;*********************************************************************&lt;/P&gt;&lt;P&gt;form get_data.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  select mara&lt;SUB&gt;matnr mara&lt;/SUB&gt;brgew makt~maktx&lt;/P&gt;&lt;P&gt;             into corresponding fields of table ialv&lt;/P&gt;&lt;P&gt;                 from mara&lt;/P&gt;&lt;P&gt;                      inner join makt&lt;/P&gt;&lt;P&gt;                         on mara&lt;SUB&gt;matnr = makt&lt;/SUB&gt;matnr&lt;/P&gt;&lt;P&gt;                                where mara~matnr in s_matnr&lt;/P&gt;&lt;P&gt;                                  and makt~spras = sy-langu.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  sort ialv ascending by matnr.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;endform.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     Form  FREE_CONTAINERS&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;P&gt;form free_containers.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  if not alv_container is initial.&lt;/P&gt;&lt;P&gt;    call method alv_container-&amp;gt;free.&lt;/P&gt;&lt;P&gt;    clear: alv_container.&lt;/P&gt;&lt;P&gt;    free : alv_container.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;endform.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     Form  Get_Fieldcatalog - Set Up Columns/Headers&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;P&gt;form get_fieldcatalog.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  data: ls_fcat type lvc_s_fcat.&lt;/P&gt;&lt;P&gt;  data: columnno(3) type n value '0'.&lt;/P&gt;&lt;P&gt;  refresh: fieldcat.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  clear: ls_fcat.&lt;/P&gt;&lt;P&gt;  ls_fcat-reptext    = 'Material Number'.&lt;/P&gt;&lt;P&gt;  ls_fcat-coltext    = 'Material Number'.&lt;/P&gt;&lt;P&gt;  ls_fcat-fieldname  = 'MATNR'.&lt;/P&gt;&lt;P&gt;  ls_fcat-ref_table  = 'IALV'.&lt;/P&gt;&lt;P&gt;  ls_fcat-outputlen  = '18'.&lt;/P&gt;&lt;P&gt;  ls_fcat-col_pos    = 1.&lt;/P&gt;&lt;P&gt;  append ls_fcat to fieldcat.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  clear: ls_fcat.&lt;/P&gt;&lt;P&gt;  ls_fcat-reptext    = 'Material Description'.&lt;/P&gt;&lt;P&gt;  ls_fcat-coltext    = 'Material Description'.&lt;/P&gt;&lt;P&gt;  ls_fcat-fieldname  = 'MAKTX'.&lt;/P&gt;&lt;P&gt;  ls_fcat-ref_table  = 'IALV'.&lt;/P&gt;&lt;P&gt;  ls_fcat-outputlen  = '40'.&lt;/P&gt;&lt;P&gt;  ls_fcat-col_pos    = 2.&lt;/P&gt;&lt;P&gt;  append ls_fcat to fieldcat.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;  clear: ls_fcat.&lt;/P&gt;&lt;P&gt;  ls_fcat-reptext    = 'Material Description'.&lt;/P&gt;&lt;P&gt;  ls_fcat-coltext    = 'Material Description'.&lt;/P&gt;&lt;P&gt;  ls_fcat-fieldname  = 'BRGEW'.&lt;/P&gt;&lt;P&gt;  ls_fcat-ref_table  = 'IALV'.&lt;/P&gt;&lt;P&gt;  ls_fcat-do_sum     = 'X'.&lt;/P&gt;&lt;P&gt;  ls_fcat-just       = 'R'.&lt;/P&gt;&lt;P&gt;  ls_fcat-datatype   = 'QUAN'.&lt;/P&gt;&lt;P&gt;  ls_fcat-outputlen  = '15'.&lt;/P&gt;&lt;P&gt;  ls_fcat-col_pos    = 2.&lt;/P&gt;&lt;P&gt;  append ls_fcat to fieldcat.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;endform.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Refer&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.sdn.sap.com/click.jspa?searchID=4359508&amp;amp;messageID=1793643" target="test_blank"&gt;https://forums.sdn.sap.com/click.jspa?searchID=4359508&amp;amp;messageID=1793643&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.sdn.sap.com/click.jspa?searchID=4359508&amp;amp;messageID=1116661" target="test_blank"&gt;https://forums.sdn.sap.com/click.jspa?searchID=4359508&amp;amp;messageID=1116661&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2007 05:37:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sum-in-grid/m-p/2582770#M590697</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-07T05:37:26Z</dc:date>
    </item>
  </channel>
</rss>

