Application Development 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: 

Table control sorting...

Former Member
0 Kudos

Hi, I have a prob to solve... its a normal module pool prog with 2 screens.. 1st screen takes key fields from the user and then when user presses the display button, it shows another screen with the corr details in a table control.

Now I have added a sort function in the GUI status of this 2nd screen and i want tht when user selects a particular column in the table control and presses the sort button, it should sort the table control as per the col selected.

Can anyone plz tell me how can this be done. ... howcan i access the col field selected by the user in the control in my abap prog to chk which col is selcted n sort the itab and then display the sorted values in the control...

its urgent.. plzzz help...

1 ACCEPTED SOLUTION

Former Member

goto transcation abapdocu.

see example demo program for table control.

5 REPLIES 5

0 Kudos

Hi,

Check standard SAP Demo program RSDEMO02 for sorting function in table control.

Executethis program and there is sort button on the application tool bar. So execute this sort in debug mode and check how it is working.

Regards,

Sesh

Former Member

goto transcation abapdocu.

see example demo program for table control.

former_member491305
Active Contributor
0 Kudos

Hi,

Check out the following code to sort in the table control by ASCENDING and Descending.

Case ok_code.

WHEN 'SORT_A' OR

'SORT_D'. "sort column

PERFORM fcode_sort_tc USING p_tc_name

p_table_name

l_ok.

Endcase.

DATA:BEGIN OF x_srt_fname,

fname1(50),

fname2(50),

fname3(50),

fname4(50),

fname5(50),

fname6(50),

fname7(50),

fname8(50),

fname9(50),

fname10(50),

END OF x_srt_fname.

DATA:it_srt_fname LIKE TABLE OF x_srt_fname.

DATA :l_table_name LIKE feld-name,

n_cnt(2) TYPE n, v_fieldname LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS: <table> TYPE STANDARD TABLE,

<sort_table> TYPE STANDARD TABLE.

FIELD-SYMBOLS <wa>.

FIELD-SYMBOLS <mark_field>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc

CONCATENATE p_tc_name '-COLS' INTO l_table_name.

ASSIGN (l_table_name) TO <table>.

REFRESH it_srt_fname.CLEAR x_srt_fname.

LOOP AT <table> ASSIGNING <wa>.

ASSIGN COMPONENT 'SELECTED' OF STRUCTURE <wa> TO <mark_field>.

IF <mark_field> = 'X'.

n_cnt = n_cnt + 1.

ASSIGN COMPONENT 'SCREEN-NAME' OF STRUCTURE <wa>

TO <mark_field>.

IF n_cnt = 1.

x_srt_fname-fname1 = <mark_field>+7(43) .

ELSEIF n_cnt = 2.

x_srt_fname-fname2 = <mark_field>+7(43) .

ELSEIF n_cnt = 3.

x_srt_fname-fname3 = <mark_field>+7(43).

ELSEIF n_cnt = 4.

x_srt_fname-fname4 = <mark_field>+7(43).

ELSEIF n_cnt = 5.

x_srt_fname-fname5 = <mark_field>+7(43).

ELSEIF n_cnt = 6.

x_srt_fname-fname6 = <mark_field>+7(43).

ELSEIF n_cnt = 7.

x_srt_fname-fname7 = <mark_field>+7(43).

ELSEIF n_cnt = 8.

x_srt_fname-fname8 = <mark_field>+7(43).

ELSEIF n_cnt = 9.

x_srt_fname-fname9 = <mark_field>+7(43).

ELSEIF n_cnt = 10.

x_srt_fname-fname10 = <mark_field>+7(43).

ENDIF.

ENDIF.

ENDLOOP.

IF n_cnt > 10.

MESSAGE 'You can''t sort more than 10 fields' TYPE 'W'.

EXIT.

ENDIF.

UNASSIGN <table>.

ASSIGN (p_table_name) TO <table>.

IF p_l_ok = 'SORT_A'.

SORT <table> ASCENDING BY (x_srt_fname-fname1)

(x_srt_fname-fname2) (x_srt_fname-fname3)

(x_srt_fname-fname4) (x_srt_fname-fname5)

(x_srt_fname-fname6) (x_srt_fname-fname7)

(x_srt_fname-fname8) (x_srt_fname-fname9)

(x_srt_fname-fname10) .

ELSEIF p_l_ok = 'SORT_D'.

SORT <table> DESCENDING BY (x_srt_fname-fname1)

(x_srt_fname-fname2) (x_srt_fname-fname3)

(x_srt_fname-fname4) (x_srt_fname-fname5)

(x_srt_fname-fname6) (x_srt_fname-fname7)

(x_srt_fname-fname8) (x_srt_fname-fname9)

(x_srt_fname-fname10) .

ENDIF.

Former Member
0 Kudos

Hey thank u sooo much all of u... it was really helpful...

Former Member
0 Kudos

Thank you, it's very helped to me my issue was resolved