cancel
Showing results for 
Search instead for 
Did you mean: 

sorting using button action.

Former Member
0 Kudos

Hi,

I have 2 buttons 'SORT ASCENDING' and 'SORT DESCENDING' . also there is a table UI element. On click of any one button sorting will be done on a particular table column selected .As i am new to WDA can nybody help me with the code snippet.

thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

You want to select one Table Column and then Press Ascending or Descending. For this you can follow this approach.

Here I suppose you are displaying data in Table. That Code in in wddoinit and internal table itab.

1. To make Table Column Selectable -> Change ColSelectionState to NotSelected.

2. In onAction of Table Column C1 let us say, make an On Action - A1.

3. In A1, get the values of the Column selected in an internal table itab1.

4. Now Make buttons - Asc and Desc with action assigned to it as ASC and DESC.

5 In the On Action of Asc, Sort the Values Using :

sort itab1 Ascending.

6. Move this sorted values in another internal table itab2.

7.Fill data for other columns too. Use below mentioned Code :

loop at itab into wa1.

READ TABLE itab1 INDEX sy-tabix into wa2.

wa1-carrid = wa2-carrid.

APPEND wa1 to itab2.

ENDLOOP.

8. This way you will be having All Data for Sorted Columns and other columns in another internal table itab2.

9. Bind this internal table with Node which you have binded to table.

10. You have to do it for all Columns. Get Selected Column data in one table and then sort it and then move it to another table along with data of other columns and finally bind it.

There may be other possible situations too but i have tried this and it is working.

Thanx.

Edited by: Saurav Mago on Apr 10, 2009 3:40 PM

Answers (2)

Answers (2)

arjun_thakur
Active Contributor
0 Kudos

Hi,

Well it can be done in this way. In the onaction method of say 'SORT ASCENDING' button, just read the node that is binded to the table using code wizard, use the abap sort statement and the bind it to the node again. It will look like :

 sort itab  ASCENDING BY <column name> 

and like wise for the do it for decending button.

I want to ask how selecting the perticular column? Or the sorting is always done on a perticular column?

Regards

Arjun

Former Member
0 Kudos

hi,

Refer this link :

Thanx.

Former Member
0 Kudos

Hi Saurav.

The following code snippet is from the link that u sent.

lr_node = wd_context->get_child_node( <table_context_node> ).

l_col_name = wdevent->get_string( 'COLUMN' ).

l_sort_direction = wdevent->get_string( 'DIRECTION' ).

Can u please tell me what value should i set for 'COLUMN' and "DIRECTION'. Also if i have to sort any column how do i select that column?

Edited by: tubai123 on Apr 10, 2009 10:34 AM

arjun_thakur
Active Contributor
0 Kudos

Hi,

Refer this thread:

Regards

Arjun