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

regarding sort at table control

Former Member
0 Likes
719

Hay guys,

In table control i want to click particular column header and sort it.

could you tell me what setings i have to make in table control

and where i have to write code for sorting.

I am using table control wizard.

suggestion please.

thanks,

ambichan

6 REPLIES 6
Read only

Former Member
0 Likes
681

Ambi,

Is these links helps you?

rgds,

TM.

Read only

Former Member
0 Likes
681

Hi

In PAI event, before looping the internal table, write a module to sort the internal table according to the coloumn selected.

Module sort_table input.

if sy-ucomm = 'SORT'

*capture the column name

sort itab by <coloumn name>.

endif.

endmodule.

Regards

Navneeth

Read only

Former Member
0 Likes
681

Hi Ambi Chan,

this is a sample program to sort:

For this purpose we have to use the type-pools: cxtab.

see the sample code and try.

REPORT ZTEST_TX .

TYPE-POOLS: CXTAB .

DATA : BEGIN OF ITAB OCCURS 0.

INCLUDE STRUCTURE MARA.

DATA : END OF ITAB.

DATA COL TYPE CXTAB_COLUMN.

CONTROLS : TC TYPE TABLEVIEW USING SCREEN 100.

START-OF-SELECTION.

SELECT * FROM MARA INTO TABLE ITAB.

IF SY-SUBRC = 0 .

ENDIF.

END-OF-SELECTION.

CALL SCREEN 100.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'ZTEST'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& ModulE E INPUT

&----


  • tExt

----


MODULE E INPUT.

LEAVE PROGRAM.

ENDMODULE. " E INPUT

&----


*& Module read INPUT

&----


  • text

----


MODULE READ INPUT.

READ TABLE ITAB INDEX TC-CURRENT_LINE.

ENDMODULE. " read INPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

DATA: FLDNAME(100),HELP(100).

DATA : T LIKE SY-TABIX.

READ TABLE TC-COLS INTO COL WITH KEY SELECTED = 'X'.

IF SY-SUBRC = 0 .

CLEAR T.

T = SY-TABIX.

ENDIF.

SPLIT COL-SCREEN-NAME AT '-' INTO HELP FLDNAME.

CASE SY-UCOMM .

WHEN 'S+'.

SORT ITAB BY (FLDNAME) ASCENDING.

WHEN 'S-'.

  • SORT itab BY (FLDNAME) descending.

COL-INVISIBLE = 'X'.

MODIFY TC-COLS FROM COL INDEX T.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

Pls reward points if helpful.

- Selvapandian Arunachalam

Read only

0 Likes
681

HEY GUYS,

THANKS FOR YOUR REPLIES.

ACTUALLY MY REQUIREMENT IS NOT SORTING THE FIELD WITH CLICKING THE SORT BUTTON.

I HAVE TO SORT THE TABLE RECORDDS WITH RESPECT TO THE CLICK OF TABLE CONTROL HEADER.

SAY IF EXAMPLE YOU HAVE KUNNR FIELD DISPLAY IN TABLE CONTROL. IT MUST HAVE TEXT "CUSTOMER" AS HEADER IN TABLE CONTROL AT TOP.

WHEN U CLICK THE HEADER OF KUNNR OR IN PLACE OF HEADER TEXT CUSTOMER, RECORDS SHOULD BE SORTED.

I FOUND OKCODE IS NO TRIGGERED WHILE CLICKING THE HEADER BUTTON OF TABLE CONTROL. SO HOW TO FIRE THIS EVENT.

SUGGEST ME PLEASE.

THANKS.

AMBICHAN

Read only

0 Likes
681

SURELY I WILL REWARD POINTS FOR ALL.

Read only

Former Member
0 Likes
681

See what SAP says about sorting..

http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbac5e35c111d1829f0000e829fbfe/frameset.htm

You can see sorting examples in programs

<b>RSDEMO_TABLE_CONTROL

DEMO_DYNPRO_TABCONT_LOOP

DEMO_DYNPRO_TABCONT_LOOP_AT</b>

Check the below code as well

MODULE user_command INPUT.

CLEAR: ws_fld1(5),ws_fld2(5), ws_fld3(5),ws_fld4(5),
ws_col.

loop at tc_cust_micr-cols into ws_col.
if ws_col-screen-name = 'I_OUT_TAB-LOCKB' and
ws_col-selected = 'X'. 
ws_fld1 = fld1.
endif.
if ws_col-screen-name = 'I_OUT_TAB-BATCH' and
ws_col-selected = 'X'.
ws_fld2 = fld2.
endif.
if ws_col-screen-name = 'I_OUT_TAB-CHECT' and
ws_col-selected = 'X'.
ws_fld3 = fld3.
endif.
if ws_col-screen-name = 'I_OUT_TAB-KUNNR' and
ws_col-selected = 'X'.
ws_fld4 = fld4.
endif.
endloop.


CASE ws_ok_code.
WHEN c_sort_up.
CLEAR: ws_ok_code.

SORT i_out_tab BY (ws_fld1) (ws_fld2) 
(ws_fld3) (ws_fld4).

WHEN c_sort_down.
CLEAR: ws_ok_code.

SORT i_out_tab BY (ws_fld1) descending 
(ws_fld2) descending
(ws_fld3) descending 
(ws_fld4) descending.
WHEN OTHERS.
CLEAR : ws_ok_code.

ENDCASE.
ENDMODULE. " user_command INPUT

Message was edited by: Thomas Mann