03-19-2009 1:51 PM
Hi,
I want to display report output like below .
i want to display subtotals for only Revenues not for Expenses.
ending i want to display total like Revenues-Expenses.
is it possible in alv if possible please give me some inputs.
field1 field2 field3 field4
Revenues
productsales 100 1000 2000
Contractrevenue 200 4500 3000
totalRenues 300 5500 5000
Expenses
Cost of sales 1000 5000 6000
Selling expenses 5000 2000 1000
Research expenses 2000 2000 3000
total -7700 2000 0
Please help regarding this,
Regards,
Suresh.
03-19-2009 4:28 PM
Hello Suresh,
You can use a simple ALV. Proceed as follows:
1) Include type SLIS in your program. Create an output internal table with the fields you'd like to have in your ALV (if you haven't done that already).
2) Assemble a field catalog table with the fields (slis_t_fieldcat_alv for function module based ALV). Mark the fields you want do display totals as well those you'd like to be opened for input.
3) Define a sort table for subtotals. Here you have to indicate what fields you'd like to have subtotals. The DDic type is slis_sortinfo_alv
4) Define the layout you desire for your ALV using a data object of slis_layout_alv
5) Call function module REUSE_ALV_GRID_DISPLAY.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = <<<your_layout_structure>>>
IT_FIELDCAT = <<<your_field_catalog_table>>>
IT_SORT = <<<your_sort_criteria_table>>>
TABLES
t_outtab = <<<your_output_tabl>>>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
Hope this helps you.
Regards
Eduardo
03-19-2009 4:28 PM
Hello Suresh,
You can use a simple ALV. Proceed as follows:
1) Include type SLIS in your program. Create an output internal table with the fields you'd like to have in your ALV (if you haven't done that already).
2) Assemble a field catalog table with the fields (slis_t_fieldcat_alv for function module based ALV). Mark the fields you want do display totals as well those you'd like to be opened for input.
3) Define a sort table for subtotals. Here you have to indicate what fields you'd like to have subtotals. The DDic type is slis_sortinfo_alv
4) Define the layout you desire for your ALV using a data object of slis_layout_alv
5) Call function module REUSE_ALV_GRID_DISPLAY.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = <<<your_layout_structure>>>
IT_FIELDCAT = <<<your_field_catalog_table>>>
IT_SORT = <<<your_sort_criteria_table>>>
TABLES
t_outtab = <<<your_output_tabl>>>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
Hope this helps you.
Regards
Eduardo
03-19-2009 4:43 PM
Hi Suresh,
For which field u want to do sum.
Pass for that field DO_SUM = 'X' in the field catalog.
Thanks
03-19-2009 5:35 PM
Hi,
For any custom sub/totals use this approach (I assume you are using cl_gui_alv_grid 😞
1) in field catalog set DO_SUM = 'X' for fields field2/3/4
2) set sorting for field1
data: ls_sort type lvc_s_sort,
lt_sort type lvc_t_sort.
ls_sort-fieldname = 'FIELD1'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO lt_sort.
3) now change the sub/totals during runtime to your custom calculations:
data: r_alv type ref to cl_gui_alv_grid,
r_subtot1 type ref to data,
r_total type ref to data.
...
r_alv->set_table_for_first_display ... "first show your table (pass lt_sort here too)
"then in the same PBO change the content of sub/totals
CALL METHOD r_av->get_subtotals
IMPORTING
EP_COLLECT00 = r_total "your total
EP_COLLECT01 = r_subtotal1 "first level of subtotal
....
EP_COLLECT0X = r_subototalX "X level of subtotal (max 9)
For your example you only use Total and Subtotal level 1 so the first two data references are enough.
4) Now as you have references to sub/total lines in r_total , r_subtotal1 use field symbols to change their content (i.e. providing own calculation formula). As you do changes to references they are immediately reflecting this change in ALV
5) last step is refreshing the view in order your change can be visible
r_alv->refresh_table_display( i_soft_refresh = 'X' ).
Regards
Marcin