Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

SUBTOTAL in ALV

You can create subtotal for the fields required and can be displayed for each new
values on the column.

Example ,you can display the 'Airfare' for each 'carrid' in the ALV grid.

Step 1.
Create an internal table of type LVC_T_FCAT and mark the option do_sum as 'X'
for the required field .(Here PRICE).

Step 2.
Create an internal table of type LVC_T_SORT and mark the option subtot as 'X'
for the field you required.(Here CARRID).

Step 3.
Pass these internal tables to the method SET_TABLE_FOR_FIRST_DISPLAY
using parameters
it_fieldcatalog

it_sort

Example program:

REPORT zalv.
DATA:
t_sflight TYPE TABLE OF sflight,
fs_sflight TYPE sflight.
DATA:
r_container TYPE REF TO cl_gui_custom_container,
r_grid TYPE REF TO cl_gui_alv_grid.
*FIELD CATALOG
DATA:
t_fcat TYPE lvc_t_fcat,
fs_fcat TYPE lvc_s_fcat.
*SORTING THE BASIC LIST
DATA:
t_sort TYPE lvc_t_sort,
fs_sort TYPE lvc_s_sort.
fs_fcat-fieldname = 'PRICE'.
fs_fcat-do_sum = 'X'.
APPEND fs_fcat TO t_fcat.
fs_sort-spos ='1'.
fs_sort-fieldname = 'CARRID'.
fs_sort-down = 'X'.
fs_sort-group = '*'.
fs_sort-subtot = 'X'.
APPEND fs_sort TO t_sort.
SELECT * FROM sflight INTO TABLE t_sflight.
CALL SCREEN 100.
&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
&---------------------------------------------------------------------
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN1'.
SET TITLEBAR 'TITLE1'.ENDMODULE. " STATUS_0100 OUTPUT
&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
&---------------------------------------------------------------------
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------
**& Module HANDLER OUTPUT
*&---------------------------------------------------------------------

MODULE list OUTPUT.
CREATE OBJECT r_container
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT r_grid
EXPORTING
i_parent = r_container.
CALL METHOD r_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_fieldcatalog = t_fcat
it_outtab = t_sflight
it_sort = t_sort.
ENDMODULE. "list OUTPUT

  • No labels