‎2009 Dec 04 5:33 AM
hi all,
i am doing ALV report using class object. to create a ALV grid , i used CALL METHOD cl_salv_table=>factory.
now my requirement is to find the total and subtotal. so the table should be sorted then do subtotal.
i check in some site and they have mentioned CALL METHOD c_alv1->set_table_for_first_display using screen..but my report is without screens..
how can i sort and subtoat using the method CALL METHOD cl_salv_table=>factory.
help please
thanks
‎2009 Dec 04 5:55 AM
Hi,
The following code also performs SUBTOTAL along with SORT
DATA : w_ref TYPE REF TO cl_salv_table, "Refernce to ALV class
lr_sorts TYPE REF TO cl_salv_sorts, "Reference to ALV sort class
lr_columns TYPE REF TO cl_salv_columns_table, "Reference to set ALV column properties
lr_aggregations TYPE REF TO cl_salv_aggregations, "Reference to set ALV totals
lr_content TYPE REF TO cl_salv_form_element, "Reference to set ALV display properties
lw_long TYPE scrtext_l, "Long text
lw_medium TYPE scrtext_m, "Medium text
lw_short TYPE scrtext_s, "Short text
lw_days TYPE string. "String to concatenate days
CONSTANTS: lc_hyphen TYPE c VALUE '-',
lc_pos type i value 1 , "Sort position
lc_seq type SALV_DE_SORT_SEQUENCE value '1', "Sort sequence
lc_tot type sap_bool value 'X', "Subtotal
lc_grp type SALV_DE_SORT_GROUP value '2'. "Group *... set
sort lr_sorts = w_ref->get_sorts( ).
PERFORM f008_set_sorts USING lr_sorts 'LIFNR' lc_pos lc_seq lc_tot lc_grp.
PERFORM f008_set_sorts USING lr_sorts 'NAME' lc_pos lc_seq SPACE lc_grp.
w_ref->display( ).
*&------------------* *& Form f008_set_sorts *&------------------------------
-------------------------* * Sort and grouping the ALV *---------------------------------------------
*------------------------
FORM f008_set_sorts USING ir_sorts TYPE REF TO cl_salv_sorts
lw_col type any
lc_pos type i lc_seq type SALV_DE_SORT_SEQUENCE
lc_tot type sap_bool lc_grp type SALV_DE_SORT_GROUP.
TRY.
ir_sorts->set_group_active( abap_true ).
TRY.
** Group grid on Vendor number
ir_sorts->add_sort( columnname = lw_col position = lc_pos sequence = lc_seq subtotal = lc_tot group = lc_grp ).
CATCH cx_salv_data_error cx_salv_existing cx_salv_not_found.
MESSAGE i023(salv_exception).
CATCH cx_salv_method_not_supported.
MESSAGE i028(salv_exception) WITH space space space space.
ENDTRY.
CATCH cx_salv_method_not_supported.
MESSAGE i028(salv_exception) WITH space space space space.
ENDTRY.
ENDFORM. "f008_set_sorts
Hope this helps.
‎2009 Dec 04 5:38 AM
‎2009 Dec 04 5:46 AM
Try this way
DATA: gr_sorts TYPE REF TO cl_salv_sorts.
data: gr_agg type ref to cl_salv_aggregations.
gr_sorts = go_alv->get_sorts( ).
gr_sorts->add_sort( columnname = 'CARRID' subtotal = abap_true ).
gr_sorts->add_sort( columnname = 'CONNID' subtotal = abap_true ).
gr_agg = go_alv->get_aggregations( ).
gr_agg->add_aggregation( 'PAYMENTSUM' ).
go_alv->display( ).
a®
‎2009 Dec 04 5:55 AM
Hi,
The following code also performs SUBTOTAL along with SORT
DATA : w_ref TYPE REF TO cl_salv_table, "Refernce to ALV class
lr_sorts TYPE REF TO cl_salv_sorts, "Reference to ALV sort class
lr_columns TYPE REF TO cl_salv_columns_table, "Reference to set ALV column properties
lr_aggregations TYPE REF TO cl_salv_aggregations, "Reference to set ALV totals
lr_content TYPE REF TO cl_salv_form_element, "Reference to set ALV display properties
lw_long TYPE scrtext_l, "Long text
lw_medium TYPE scrtext_m, "Medium text
lw_short TYPE scrtext_s, "Short text
lw_days TYPE string. "String to concatenate days
CONSTANTS: lc_hyphen TYPE c VALUE '-',
lc_pos type i value 1 , "Sort position
lc_seq type SALV_DE_SORT_SEQUENCE value '1', "Sort sequence
lc_tot type sap_bool value 'X', "Subtotal
lc_grp type SALV_DE_SORT_GROUP value '2'. "Group *... set
sort lr_sorts = w_ref->get_sorts( ).
PERFORM f008_set_sorts USING lr_sorts 'LIFNR' lc_pos lc_seq lc_tot lc_grp.
PERFORM f008_set_sorts USING lr_sorts 'NAME' lc_pos lc_seq SPACE lc_grp.
w_ref->display( ).
*&------------------* *& Form f008_set_sorts *&------------------------------
-------------------------* * Sort and grouping the ALV *---------------------------------------------
*------------------------
FORM f008_set_sorts USING ir_sorts TYPE REF TO cl_salv_sorts
lw_col type any
lc_pos type i lc_seq type SALV_DE_SORT_SEQUENCE
lc_tot type sap_bool lc_grp type SALV_DE_SORT_GROUP.
TRY.
ir_sorts->set_group_active( abap_true ).
TRY.
** Group grid on Vendor number
ir_sorts->add_sort( columnname = lw_col position = lc_pos sequence = lc_seq subtotal = lc_tot group = lc_grp ).
CATCH cx_salv_data_error cx_salv_existing cx_salv_not_found.
MESSAGE i023(salv_exception).
CATCH cx_salv_method_not_supported.
MESSAGE i028(salv_exception) WITH space space space space.
ENDTRY.
CATCH cx_salv_method_not_supported.
MESSAGE i028(salv_exception) WITH space space space space.
ENDTRY.
ENDFORM. "f008_set_sorts
Hope this helps.