Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Obtaining subtotals based on 2 fields.(ALV using oops concept)

Former Member
0 Likes
437

Need help on how to apply sort on 2 fields and obtain subtotals.For example if I have some records for similar tax code and some more records for a similar tax jurisdiction (under which all tax codes come).I need to calculate subtotals for same tax code as well as same tax jurisdiction code.Currently I am able to generate subtotals by sorting on 1 field only ,using OOPs concept.How do I apply for both the fields? This is what is being done currently with regard to sorting and subtotaling :

METHOD set_sorts.

lr_sorts = gr_alv_data->get_sorts( ).

TRY.

lr_sorts->add_sort( 'TXJCD' ). ---sorting based on tax jurisdiction

CATCH: cx_salv_not_found,

cx_salv_existing,

cx_salv_data_error.

ENDTRY.

TRY.

lr_sorts->add_sort( columnname = 'MSKWZ'

subtotal = if_salv_c_bool_sap=>true ).

CATCH cx_salv_data_error cx_salv_not_found

cx_salv_existing.

ENDTRY.

ENDMETHOD. "set_sorts

Thanks & Regards,

Savitha

Need help on how to apply sort on 2 fields and obtain subtotals.For example if I have some records for similar tax code and some more records for a similar tax jurisdiction (under which all tax codes come).I need to calculate subtotals for same tax code as well as same tax jurisdiction code.Currently I am able to generate subtotals by sorting on 1 field only ,using OOPs concept.How do I apply for both the fields? This is what is being done currently with regard to sorting and subtotaling :

METHOD set_sorts.

lr_sorts = gr_alv_data->get_sorts( ).

TRY.

lr_sorts->add_sort( 'TXJCD' ). ---sorting based on tax jurisdiction

CATCH: cx_salv_not_found,

cx_salv_existing,

cx_salv_data_error.

ENDTRY.

TRY.

lr_sorts->add_sort( columnname = 'MSKWZ'

subtotal = if_salv_c_bool_sap=>true ).

CATCH cx_salv_data_error cx_salv_not_found

cx_salv_existing.

ENDTRY.

ENDMETHOD. "set_sorts

Thanks & Regards,

Savitha

1 REPLY 1
Read only

Former Member
0 Likes
413

Hi Savitha,

Use the other paramenters like POSITION, SEQUENCE, SUBTOTAL for both fields like as follows. Then it will work fine.

TRY.
lr_sorts->add_sort( columnname = 'TXJCD' 
sequence = 1
Position = 1
subtotal = if_salv_c_bool_sap=>true ).
CATCH cx_salv_data_error cx_salv_not_found
cx_salv_existing. 
ENDTRY.

TRY.
lr_sorts->add_sort( columnname = 'MSKWZ' 
sequence = 2
Position = 1
subtotal = if_salv_c_bool_sap=>true ).
CATCH cx_salv_data_error cx_salv_not_found
cx_salv_existing. 
ENDTRY.