2012 Apr 05 7:29 PM
Hi,
On the Selection screen i have 3 parameter fields of 1 character. And i need to sort the final output table with these 3 fields. The scenario will be like...the user will be putting the 1 to 3 numbers in these fields randomly. For e.g, if the user puts the entry for field 1 as 1, for field 2 as 2, and for field 3 as 3 in the three fields on selection screen, then i need to sort the output table in the order as: Sort ITAB by 1 2 3.
So now i want to know if the the user puts the values randomly on the selection screen..how to capture the values from the selection screen and sort the internal table.
Thanks & Regards,
Santosh.
2012 Apr 05 9:04 PM
Hi,
I guess you can use the table addition with your sort statement:
DATA: otab TYPE abap_sortorder_tab,
oline TYPE abap_sortorder.
oline-name = p1.
APPEND oline TO otab.
oline-name = p2.
APPEND oline TO otab.
oline-name = p3.
APPEND oline TO otab.
TRY.
SORT itab BY (otab).
CATCH cx_sy_dyn_table_ill_comp_val.
MESSAGE 'Wrong column name!' TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
But I would have used a select-option field instead to hold the fields name...
Or maybe I did not understood properly your request?
Kr,
Manu.
2012 Apr 05 11:02 PM
Hi,
You can use the following:
SORT itab by (otab).
otab will have the selection screen fields according to user specification.Find the order in the program and populate otab accordingly.
Hope this helps.
Regards,
Archna
2012 Apr 06 8:34 AM
Hi,
It seems you have not seen the F1 help for SORT statement. Check SORT itab. You shall get a very good example given by SAP on how to sort an internal table using BY OTAB.
Danish