Tip

Web Dynpro ABAP Quick Tip: Table column sorting in four steps

This tip is for those of you who are very new to Web Dynpro ABAP and need help sorting table columns.

This tip is for those who are very new to Web Dynpro ABAP and want to learn about the quick tips which can help solve issues. In today’s edition we will be covering table column sorting in four steps.

 

Most of us are familiar with the Table UI element and when we create a normal table and bind it to the context node, during the run time it appears like above. But in this case , the data is not complex or confusing. But sometimes these tables may have more number of columns with numerical values. So to make better sense of the values, most of the customers prefer to have sorting at the column level. Initially the sorting may seem to be a complex process, but no need to worry, Web Dynpro has provided us a table handler to carry out the sorting functionality.

 

1. Create an attribute in the view.

In your view, which holds the table UI element, create an attribute of type IF_WD_TABLE_METHOD_HNDL.

 

2. Populate the instance of the table method handler.

In the WDDOMODIFY , of your view method .Populate the table method handler to the newly created view attribute.

****Code in WDDOMODIFY****************** 

data wd_table type ref to cl_wd_table.

check first_time = abap_true.

* Name of the table UI element to be provided

wd_table ?= view->get_element( 'TBL_AUTHOR' ).

wd_this->table_control ?= wd_table->_method_handler.

*Name of the key attribute of the context node to which the table binding is done to be  provided

wd_this->table_control->set_key_attribute_name( 'USER_ID' ).

 

3. Create an action for the onSort event of the table.

Now we need to create an action for the onSort event of the table UI element. Create a new action and call the apply_sorting method available in the table method handler attribute.

*****code in the onSort event********* 

wd_this->table_control->apply_sorting( ).

 

4.Activate your view and test.

Now you can activate your view and test the application. The new table header will look like follows.

Now on click of the sort icon

The sorting functionality will be available to all the columns of the table.

Mohammed Anzy SWorking as a Development Specialist in SAP Labs.

This content is reposted from the SAP Developer Network.
Copyright 2007, SAP Developer Network


SAP Developer Network (SDN) is an active online community where ABAP, Java, .NET, and other cutting-edge technologies converge to form a resource and collaboration channel for SAP developers, consultants, integrators, and business analysts. SDN hosts a technical library, expert blogs, exclusive downloads and code samples, an extensive eLearning catalog, and active, moderated discussion forums. SDN membership is free.

Want to read more from this author? Click here to read Mohammed Anzy's Weblog. Click here to read more about ABAP on the SDN.



Dig Deeper on SAP development and programming languages

ERP
SearchOracle
Data Management
SearchAWS
Business Analytics
Content Management
HRSoftware
Close