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

2 Fields sorting using slis_sortinfo_alv

Former Member
0 Likes
1,557

Hi everyone,

I would just like to know if it is possible to sort 2 fields using slis_sortinfo_alv. If yes, how do I write the code? This is my code for the slis_sortinfo_alv. Please help me.

ls_sort-fieldname = 'KHINR'.

ls_sort-fieldname = 'KOSTL'.

ls_sort-subtot = 'X'.

ls_sort-tabname = 'ITAB'.

APPEND ls_sort TO lt_sort.

Thanks a lot in advance.

Anna Bechayda

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,348

Yes it is possible.

ls_sort-fieldname = 'KOSTL'.

ls_sort-subtot = 'X'.

ls_sort-tabname = 'ITAB'.

ls_sort-up = 'X'.

APPEND ls_sort TO lt_sort.

11 REPLIES 11
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,348

Yes, but you need to write two records to the internal table.

clear ls_sort.
ls_sort-fieldname = 'KHINR'.
ls_sort-subtot = 'X'.
ls_sort-up      = 'X'.
ls_sort-tabname = 'ITAB'.
APPEND ls_sort TO lt_sort.

clear ls_sort.
ls_sort-fieldname = 'KOSTL'.
ls_sort-subtot = 'X'.
ls_sort-up      = 'X'.
ls_sort-tabname = 'ITAB'.
APPEND ls_sort TO lt_sort.

Regards,

Rich Heilman

Read only

0 Likes
1,348

Thanks for your reply sir. But my other problem is that I need to subtotal the field "KHINR" sorting KOSTL. Below is the sample output. Is this possible sir? Thanks so much in advance.

FXNAL Group RC # Basic Salary

BOARDTRUST 100 366,864.00

BOARDTRUST 101 191,304.00

BOARDTRUST 102 209,982.00

BOARDTRUST 103 187,737.00

BOARDTRUST 104 192,109.00

BOARDTRUST 105 108,129.00

BOARDTRUST 106 144,929.00

BOARDTRUST 107 191,412.00

BOARDTRUST 108 187,737.00

BOARDTRUST 110 986,307.00

BOARDTRUST 114 240,153.00

BOARDTRUST Total 3,006,663.00

Read only

0 Likes
1,348

This is a much better example of the sample. Thanks in advance.

Thanks for your reply sir. But my other problem is that I need to subtotal the field "KHINR" sorting KOSTL. Below is the sample output. Is this possible sir? Thanks so much in advance.

KHINR KOSTL Basic Salary

BOARDTRUST 100 366,864.00

BOARDTRUST 101 191,304.00

BOARDTRUST 102 209,982.00

BOARDTRUST 103 187,737.00

BOARDTRUST 104 192,109.00

BOARDTRUST 105 108,129.00

BOARDTRUST 106 144,929.00

BOARDTRUST 107 191,412.00

BOARDTRUST 108 187,737.00

BOARDTRUST 110 986,307.00

BOARDTRUST 114 240,153.00

BOARDTRUST Total 3,006,663.00

Message was edited by: Anna

Anna Bechayda

Read only

0 Likes
1,348

It is a little tricky, try.....



clear ls_sort.
ls_sort-fieldname = 'KHINR'.
ls_sort-up      = 'X'.
ls_sort-subtotal = 'X'.
ls_sort-tabname = 'ITAB'.
APPEND ls_sort TO lt_sort.
 
clear ls_sort.
ls_sort-fieldname = 'KOSTL'.
ls_sort-up      = 'X'.
ls_sort-tabname = 'ITAB'.
APPEND ls_sort TO lt_sort.


Regards,

Rich Heilman

Read only

0 Likes
1,348

Hi again. Is it possible for the field "KHINR" not to be sorted? What needs to be sorted only is the "KOSTL" and then the field "KHINR" will be sub-totalled. Is this possible?

Read only

Former Member
0 Likes
1,349

Yes it is possible.

ls_sort-fieldname = 'KOSTL'.

ls_sort-subtot = 'X'.

ls_sort-tabname = 'ITAB'.

ls_sort-up = 'X'.

APPEND ls_sort TO lt_sort.

Read only

0 Likes
1,348

Hi Ms Sadiqulla,

Thanks for your reply. The thing is if I try to sort it by field "KOSTL", it is not sub-totalled by field "KHINR" but by "KOSTL", when what i need for the sub-total is by "KHINR" but sorted by "KOSTL". Is this possible? I tried doing this code as well:

ls_sort-fieldname = 'KHINR'.

ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

ls_sort-tabname = 'ITAB'.

APPEND ls_sort TO lt_sort.

clear ls_sort.

ls_sort-fieldname = 'KOSTL'.

ls_sort-up = 'X'.

ls_sort-tabname = 'ITAB'.

APPEND ls_sort TO lt_sort.

But it sorted by KHINR. And if I do this code:

clear ls_sort.

ls_sort-fieldname = 'KOSTL'.

ls_sort-up = 'X'.

ls_sort-tabname = 'ITAB'.

APPEND ls_sort TO lt_sort.

clear ls_sort.

ls_sort-fieldname = 'KHINR'.

ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

ls_sort-tabname = 'ITAB'.

APPEND ls_sort TO lt_sort.

It sub-totalled by KOSTL.

Please help me.

Thanks in advance.

Message was edited by: Anna

Anna Bechayda

Read only

0 Likes
1,348

You try passing do_sum parameter in fieldcat.

fieldcat_temp-col_pos = 2.

fieldcat_temp-fieldname = 'KHINR'.

fieldcat_temp-do_sum = 'X'.

append fieldcat_temp to fieldcat.

Read only

0 Likes
1,348

if you want subtotal for khinr then this code is correct

ls_sort-fieldname = 'KHINR'.

*ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

ls_sort-tabname = 'ITAB'.

APPEND ls_sort TO lt_sort.

clear ls_sort.

ls_sort-fieldname = 'KOSTL'.

ls_sort-up = 'X'.

ls_sort-tabname = 'ITAB'.

APPEND ls_sort TO lt_sort.

but if you dont want to sort khinr comment that as per my above code but i dont know why you required this because it may give some thing unusual.

regards

shiba dutta

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,348

Sort by Kostl - in it_sort

ls_sort-fieldname = 'KOSTL'.

ls_sort-subtot = 'X'.

ls_sort-tabname = 'ITAB'.

ls_sort-up = 'X'.

APPEND ls_sort TO lt_sort.

sum KHINR - in it_fieldcat

lt_fieldcat-fieldname = 'KHINR'..

lt_fieldcat-datatype = 'CURR'.

it_fieldcat-do_sum = 'X'.

APPEND ls_fieldcat TO it_fieldcat.

Regards

Read only

Former Member
0 Likes
1,348

Thanks a lot guys for all your suggestions.