07-20-2006 7:31 PM
Hi all,
I want to know whether is there a sorting facility for different columns in a table control of module pool program.
I have 5 columns in table control .Is there any way that i can sort on whatever column i want.
I mean like we have in alv right. Is it possible in table control too.
If yes please let me know
07-20-2006 7:47 PM
Hi Swathi,
Please check demo program <b>DEMO_DYNPRO_TABCONT_LOOP_AT</b>.
Hope this will help.
Regards,
Ferry Lianto
07-20-2006 7:38 PM
Yes, you can, but you need to code for it. You need to find what column the users cursor is in when the user clicks the sort button in the screen.
data: cursorfield(10) type c.
GET cursor field cursorfield.
This the cursor is in the table control column, CURSORFIELD will be populated with the value 'ITAB-FLD1'. Here you need to stripp off the ITAB- and just have the FLD1. Then you can use this in a dynamic sort statement.
data: sort_table(20) type c.
data: sort_column(20) type c.
split cursorfield at '-' into sort_table sort_column.
if sort_table = 'ITAB'.
sort itab by (sort_column) ascending.
endif.
REgards,
Rich Heilman
07-20-2006 7:44 PM
07-20-2006 7:47 PM
Hi Swathi,
Please check demo program <b>DEMO_DYNPRO_TABCONT_LOOP_AT</b>.
Hope this will help.
Regards,
Ferry Lianto
07-20-2006 7:50 PM
Ok, here is the example of the user selecting the column by highlighting the column and clicking a sort button.
In the user command. Here itabcon is the name of your table control.
data:
cursor_table(5) type c,
cursor_field(10) type c,
cursor_column(20) type c ,
column_name like line of itabcon-cols.
clear: column_name, cursor_column, cursor_table, cursor_field.
loop at itabcon-cols into column_name where not selected is initial.
cursor_column = column_name.
split cursor_column at '-' into cursor_table cursor_field.
endloop.
if cursor_column is initial.
get cursor field cursor_column.
endif.
case ok_code.
when 'ASORT'.
clear ok_code.
sort itab stable by (cursor_field) ascending.
endcase.
REgards,
Rich Heilman
03-21-2012 8:47 AM
Hi Rich Heilman.,
It's Working Fine For Single Column Sorting. But I Need To Sort The Table By Multiple Column As The User Selected Order. Please Guide Me How To Do?
07-20-2006 8:00 PM
Hi Rich,
This my screEn PBO
Process before output.
module status_100.
module get_data.
loop at itab with control
cnt_abc cursor cnt_abc-top_line.
module display_data.
endloop.
I DECLARED IN module get_data.
DATA : CURSORFIELD(10) TYPE C.
GET cursor field cursorfield.
Iam retrieving data from ztable into itab
if sy-ucomm = 'SORT'.
sort itab by cursorfield. "sorting
else.
sort itab by erdat ertime.
endif.
IT GIVES ME AN ERROR SAYING
no component exists with name cursor field.
Please let me know iam wrong anywhere in the process.
07-20-2006 8:06 PM
Hi,
check the syntax:
GET CURSOR FIELD fldname VALUE fldval.
Ex:
DATA: CURSORFIELD(20) TYPE C,CURSOR(10) TYPE C.
GET CURSOR FIELD CURSORFIELD VALUE CURSOR.
Regards
Appana
07-20-2006 8:10 PM
07-20-2006 9:29 PM
Hi Rich,
I have fixed the problem with the help of your code.
I have awarded full points.
Have a nice day