04-12-2010 9:38 PM
Hi all,
I have a custom screen with table control.Now i need to provide SORT functinality in this screen for the columns in the table control.
My questins:
1.Is it possible to seelct MULTIPLE columns in a table control for SORTING?If yes,what explicit settings do i need to do while creatng the TABEL CONTROL in the screen?DO I need to select "Column selection " as MULTIPLE??
2.How do I write the code for SORT functinonality for multiple columns?
I know how to write the code for SORTING on basis of single column .
Thanks!
04-13-2010 5:28 AM
I did the same application by providing a a wort button, whenever user clicks sort a pop up window will
appear and there it displays all fields of table then i select which fields to be sorted and sort them.
SET PF-STATUS '300'.
SET TITLEBAR 'SORTING'.
WINDOW STARTING AT 10 10
ENDING AT 40 20.
w_char = space.
WRITE: w_char AS CHECKBOX, 'carrid',
/ w_char AS CHECKBOX, 'connid',
/ w_char AS CHECKBOX, 'cityfrom',
/ w_char AS CHECKBOX, 'cityto',
/ w_char AS CHECKBOX, 'airpfrom',
/ w_char AS CHECKBOX, 'airpto',
/ w_char AS CHECKBOX, 'countryfr',
/ w_char AS CHECKBOX, 'countryto'.
if the above are my table fields then i will show them in pop up window and for selection i give checkbox option
then in do loop.
READ LINE sy-index FIELD VALUE w_char.
if w_char is X then add that field to a variable..and like wise
finally sort all selected fields and push the data to table controller.
i hope it helps.
Regards and Best wishes.
04-12-2010 10:02 PM
Yes, you can sort on multiple columns, but you will have to have an additional popup to get the sort fields and the order that the fields should be sorted.
Rob
04-13-2010 1:14 AM
Hi Rob,
Thanks for the reply.
However I was thinking to apply the same logic as for single columns as follows:
types : begin of ty_fields,
c_fieldname(20),
end of ty_fields.
data : t_fields type table of ty_fields,
wa_fields like line of t_fields.
WHEN 'SORTUP'.(Ascending)
loop at TABLE tc01-cols INTO wa_tc01 where selected = 'X'.
SPLIT wa_tc01-screen-name AT '-' INTO g_help g_fieldname.
wa_fields-c_fieldname = g_fieldname.
append wa_fields to t_fields.
endloop.
describe table t_fields lines l_index.
c_count = 1.
if c_count <= l_index.
read table t_fields into wa_fields index c_count.
case c_count.
when '1'.
l_field1 = wa_fields-c_fieldname.
when '2'.
l_field2 = wa_fields-c_fieldname.
and so on depending on the no of columns in the table control...
endcase.
endif.
SORT t_tvbdpl_scr BY l_fields1 l_fields 2......l_fieldn.
Let me know if the above method will work!Also for the above method to work will the type of fields(columns on whihc sort function will be applied) matter???
Thanks again for your time.
04-13-2010 5:28 AM
I did the same application by providing a a wort button, whenever user clicks sort a pop up window will
appear and there it displays all fields of table then i select which fields to be sorted and sort them.
SET PF-STATUS '300'.
SET TITLEBAR 'SORTING'.
WINDOW STARTING AT 10 10
ENDING AT 40 20.
w_char = space.
WRITE: w_char AS CHECKBOX, 'carrid',
/ w_char AS CHECKBOX, 'connid',
/ w_char AS CHECKBOX, 'cityfrom',
/ w_char AS CHECKBOX, 'cityto',
/ w_char AS CHECKBOX, 'airpfrom',
/ w_char AS CHECKBOX, 'airpto',
/ w_char AS CHECKBOX, 'countryfr',
/ w_char AS CHECKBOX, 'countryto'.
if the above are my table fields then i will show them in pop up window and for selection i give checkbox option
then in do loop.
READ LINE sy-index FIELD VALUE w_char.
if w_char is X then add that field to a variable..and like wise
finally sort all selected fields and push the data to table controller.
i hope it helps.
Regards and Best wishes.
04-13-2010 7:10 PM
Hi Kiran,
Thanks for the sample code and sharing your solution.
However I had this doubt abt the final SORT.Once I have the list of all fields on whihc I need to perform the sort,can i use the SORT statement using all the fields together?
04-13-2010 7:56 PM
As I said earlier, you can use all the fields, but simple checkboxes may not work. You have to be able to assighn an order in which you want to sort the fields, eg. F5, F1, F8 or F1, F2, F3.
Then you have to build the sort statement dynamically.
Rob
04-13-2010 10:25 PM
Thanks Rob for the info.
However are there any useful threads/std program examples i can refer to as a pointer to getting a solution to my query.
04-14-2010 5:09 AM
Hi andy once u get all the fields then you can sort dynamycally.
example of dynamic sort;
sort t_sflight by (f1) ascending (f2) ascending <.....fn>.
I hope it helped you.
Regards and Best wishes.