<?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 Regarding subtotal in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-subtotal/m-p/4010242#M958046</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     I am using reuse_alv_list_display   and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to get subtotal for three columns.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using wa_sort-subtot    but i need other than that one.&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;Regards&lt;/P&gt;&lt;P&gt;Reddy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Jun 2008 03:41:36 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-19T03:41:36Z</dc:date>
    <item>
      <title>Regarding subtotal</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-subtotal/m-p/4010242#M958046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;     I am using reuse_alv_list_display   and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to get subtotal for three columns.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using wa_sort-subtot    but i need other than that one.&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;Regards&lt;/P&gt;&lt;P&gt;Reddy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2008 03:41:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-subtotal/m-p/4010242#M958046</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-19T03:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding subtotal</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-subtotal/m-p/4010243#M958047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code will help for the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TABLES: ekko.
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Type pool declaration
*&amp;amp;---------------------------------------------------------------------*
TYPE-POOLS: slis. " Type pool for ALV*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Selection screen
*&amp;amp;---------------------------------------------------------------------*
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Type declaration
*&amp;amp;---------------------------------------------------------------------** 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.*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Internal table declaration
*&amp;amp;---------------------------------------------------------------------*
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.*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Work area declaration
*&amp;amp;---------------------------------------------------------------------*DATA:
  wa_ekko TYPE x_data,
  wa_layout     TYPE slis_layout_alv,
  wa_events         TYPE slis_alv_event,
  wa_sort TYPE slis_sortinfo_alv.*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Constant declaration
*&amp;amp;---------------------------------------------------------------------*CONSTANTS:
   c_header   TYPE char1
              VALUE 'H',                    "Header in ALV
   c_item     TYPE char1
              VALUE 'S'.*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Start-of-selection event
*&amp;amp;---------------------------------------------------------------------*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.
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub_build_header
*&amp;amp;---------------------------------------------------------------------*
*       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
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub_field_catalog
*&amp;amp;---------------------------------------------------------------------*
*       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*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;     Form  sub_fill_alv_field_catalog
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;     For building Field Catalog
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;     p_rowpos   Row position
*&amp;amp;     p_colpos   Col position
*&amp;amp;     p_fldnam   Fldname
*&amp;amp;     p_tabnam   Tabname
*&amp;amp;     p_justif   Justification
*&amp;amp;     p_seltext  Seltext
*&amp;amp;     p_out      no out
*&amp;amp;     p_tech     Technical field
*&amp;amp;     p_qfield   Quantity field
*&amp;amp;     p_qtab     Quantity table
*&amp;amp;---------------------------------------------------------------------*
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*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub_populate_layout
*&amp;amp;---------------------------------------------------------------------*
*       Populate ALV layout
*----------------------------------------------------------------------*
*       No Parameter
*----------------------------------------------------------------------*
FORM sub_populate_layout .  CLEAR wa_layout.
  wa_layout-colwidth_optimize = 'X'." Optimization of Col widthENDFORM.                    " sub_populate_layout*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub_populate_sort
*&amp;amp;---------------------------------------------------------------------*
*       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*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub_get_event
*&amp;amp;---------------------------------------------------------------------*
*       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*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub_alv_report_display
*&amp;amp;---------------------------------------------------------------------*
*       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 &amp;lt;&amp;gt; 0.
*    MESSAGE i000 WITH 'Error in ALV report display'(055).
  ENDIF.ENDFORM.                    " sub_alv_report_display*&amp;amp;---------------------------------------------------------------------*
*       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*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  subtotal_text
*&amp;amp;---------------------------------------------------------------------*
*       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.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Plz reward if useful.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Dhanashri.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2008 03:45:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-subtotal/m-p/4010243#M958047</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-19T03:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Regarding subtotal</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-subtotal/m-p/4010244#M958048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ramireddy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check this link&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_470/helpdata/en/66/bc7b1343c211d182b30000e829fbfe/content.htm" target="test_blank"&gt;http://help.sap.com/saphelp_470/helpdata/en/66/bc7b1343c211d182b30000e829fbfe/content.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Printing Subtotals at the end of an ALV List&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.saptechnical.com/Tutorials/ALV/Subtotals/Define.htm" target="test_blank"&gt;http://www.saptechnical.com/Tutorials/ALV/Subtotals/Define.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*Step 1* 

Define an internal table of type SLIS_T_EVENT, and a work area of type SLIS_ALV_EVENT.   

DATA:	T_EVENT TYPE SLIS_T_EVENT,
	W_EVENT TYPE SLIS_ALV_EVENT.

*Step 2* 
Append  AFTER-LINE-OUTPUT event to the internal table T_EVENT.  

CLEAR W_EVENT.
W_EVENT-FORM = SLIS_EV_AFTER_LINE_OUTPUT. 
W_EVENT-NAME = SLIS_EV_AFTER_LINE_OUTPUT."AFTER_LINE_OUTPUT event
APPEND W_EVENT TO T_EVENT. 

*Step 3* 
he subtotals are calculated and displayed in the list from the subroutine AFTER_LINE_OUTPUT,
 which corresponds to the event AFTER_LINE_OUTPUT.
This subroutine uses the parameter P_RS_LINEINFO, which contains settings for each line displayed in the list. 
The actual subtotalu2019s output is created using the WRITE and FORMAT statements. 

FORM AFTER_LINE_OUTPUT
  USING P_RS_LINEINFO TYPE SLIS_LINEINFO.

* Declaration of local variables
  DATA: L_SUCCESS TYPE WRBTR,     "Total For Successful Entries
        L_ERROR   TYPE WRBTR,     "Total For Unsuccessful Entries
        L_COUNT   TYPE I.         "No. Of lines in table T_OUTPUT* Getting No. of Lines in the table T_OUTPUT
  DESCRIBE TABLE T_OUTPUT LINES L_COUNT.

* Displaying the totals after the last record of the internal
* table T_OUTPUT
  IF P_RS_LINEINFO-TABINDEX = L_COUNT.
*   Loop At the internal table T_OUTPUT
    LOOP AT T_OUTPUT INTO W_OUTPUT.    
  IF W_OUTPUT-SFLAG = C_CHECKED.
                             "Flag: Indicates error record

*       Calculate total for unsuccessful entries
        L_ERROR = L_ERROR + W_OUTPUT-WRBTR.   
   ELSE.
*       Calculate total for successful entries
        L_SUCCESS = L_SUCCESS + W_OUTPUT-WRBTR.     
 ENDIF.

*     Clear workarea W_OUTPUT
      CLEAR W_OUTPUT.    ENDLOOP.
*   Set format for the total line display
    ULINE AT (P_RS_LINEINFO-LINSZ).        "Dynamic Line Size   

 FORMAT INTENSIFIED COLOR COL_TOTAL ON. "Setting the color
                                            "For the total row
                                           "As Yellow   

 WRITE : /    SY-VLINE,                 "Vertical Line
                 TEXT-017,                 "Caption For Total

"Sum of Successful            
"Entries		
              33 L_SUCCESS,                "Total Of Successful
                                           "Entries
                 C_USD.                    "Currency Type USD   

 POSITION     P_RS_LINEINFO-LINSZ.      "Dynamic Line Size    

WRITE :      SY-VLINE.                 "Vertical Line  

  ULINE AT     (P_RS_LINEINFO-LINSZ).    "Dynamic Line Size   

 WRITE : /    SY-VLINE ,                "Vertical Line
                 TEXT-018,                 "Caption For Total

"Sum of Successful            
"Entries
              33 L_ERROR,                  "Total Of Unsuccessful
                                           "Entries
                 C_USD.                    "Currency Type USD  

  POSITION     P_RS_LINEINFO-LINSZ.      "Dynamic Line Size  

  WRITE :      SY-VLINE.                 "Vertical Line    

    FORMAT COLOR OFF.                      "Color Setting Off 
  ENDIF.
ENDFORM.                                   "AFTER_LINE_OUTPUT

*Step 4* 

The table T_EVENT is passed to the function 'REUSE_ALV_LIST_DISPLAY' while displaying the ALV Report. 
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
      I_CALLBACK_PROGRAM = L_REPID    "Program Name
      IS_LAYOUT          = W_LAYOUT   "Layout of the Report
      IT_FIELDCAT        = T_FIELDCAT "Field Catalog for Report
      IT_EVENTS          = T_EVENT    "For setting the events
   TABLES
      T_OUTTAB           = T_OUTPUT   "Report data Internal Table 
   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;Best regards,&lt;/P&gt;&lt;P&gt;raam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2008 03:45:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/regarding-subtotal/m-p/4010244#M958048</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-19T03:45:58Z</dc:date>
    </item>
  </channel>
</rss>

