Web Dynpro – Sorting Columns of Table

Home / SAP / ABAP Coding / Web Dynpro – Sorting Columns of Table

Now, in my recent experiments, I came to find just how much better the performance is when you can define the table in advance, and then manipulate it, rather than create the entire thing dynamically (check out some of my previous posts if you want to see how to do that).  So I decided create the full table in the layout tab, and then remove the columns I didn’t need.  Everything worked great, until I wanted to control the sorting columns of Table dynamically.

The first thing I found is that when you define a table using the wizard (not dynamic), it make the columns grouped columns.  I still don’t really grasp the difference, but it does force you to use a different set of methods and also has different behavior.  But thanks to Google, I found this nice little tidbit.  It showed me that you can delete the Grouped Column, and replace it with a standard column.  And with a standard column, you can define the sort order.  Here’s some sample code to get you rolling.

DATA: lo_table    TYPE REF TO cl_wd_table,
grcol         TYPE REF TO cl_wd_abstr_table_column,
tcol           TYPE REF TO cl_wd_table_column,
lc_element TYPE string VALUE ‘CTR_ITEMS’.

IF first_time EQ abap_true.
* get table reference
lo_table ?= view->get_element( id = lc_element ).
CALL METHOD lo_table->remove_grouped_column
EXPORTING
id                  = ‘COL_NAME’
index             = 1
RECEIVING
the_grouped_column = grcol.
tcol ?= grcol.

CALL METHOD lo_table->add_column
EXPORTING
index              = lv_sequence
the_column     = tcol.
ENDIF.

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike

Leave a Reply

Your email address will not be published. Required fields are marked *