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

Difference between sort function & sorting performed in ALV

Former Member
0 Likes
1,226

Hi All,

I have a requirement where i need to match the sorted data of internal table, which is sorted by sort function, & sorted data that is sorted on screen,i.e.with ALV.

How can i acheieve that?

Thanks In Advance.

Regards,

Nidhi Kothiyal

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
954

Hi,

In an ALV, when we select a column and then sort, then the report is sorted based on the column selected.

Whereas in an internal table in your code you would be sorting according to some specific field.

You would ahev to ascertain as to which column is being sorted in ALV and then use similar sort statement in your code logic to get same sequence of records.

Hope this Helps!

Regards,

Mansi.

7 REPLIES 7
Read only

Former Member
0 Likes
955

Hi,

In an ALV, when we select a column and then sort, then the report is sorted based on the column selected.

Whereas in an internal table in your code you would be sorting according to some specific field.

You would ahev to ascertain as to which column is being sorted in ALV and then use similar sort statement in your code logic to get same sequence of records.

Hope this Helps!

Regards,

Mansi.

Read only

Former Member
0 Likes
954

in the user command subroutine for that ALV..

capture the SORT command and see which field its sorting.. (you need to debug a bit for this) then sort the table sabed on that field..

one more option is data_changed event.. this captures all the changes made to your table.. track it there and update your internal table..

Read only

RaymondGiuseppi
Active Contributor
0 Likes
954

By default data is sorted by internal values, no problem, the exceptions come from table ASEXDOM (from release 4.7 on) - so try to change data element or domain with another which is no exception, or use a field with external values in your ALV and hide internal values.

Regards,

Raymond

Read only

Former Member
0 Likes
954

hi,

Actually i am sorting three fields in alv, one numeric, one alphanumeric & onr character. if i sort with first two both sortings are same,, but when i sort all three the order in ALV becomes different of internal table.

any suggestion?

Regards,

Nidhi Kothiyal

Read only

0 Likes
954

So the problem is with the third field, if there is no conversion exit, did you try some SORT options that may(*) be used by ALV like STABLE or AS TEXT (language dependance)

Regards,

Raymond

(*) I'm nearly sure ALV use those options.

Read only

Former Member
0 Likes
954

hi,

Actually i am sorting three fields in alv, one numeric, one alphanumeric & onr character. if i sort with first two both sortings are same,, but when i sort all three the order in ALV becomes different of internal table.

any suggestion?

can you provide some sample code!

Regards,

Nidhi Kothiyal

Read only

0 Likes
954

Look at F1 on [SORT|http://help.sap.com/abapdocu/en/ABAPSORT_ITAB_SHORTREF.htm]

SORT gt_makt STABLE " before key fields list
  BY matnr
     spras
     maktx AS TEXT. " language dependant

Regards,

Raymond