Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 
Former Member
This is about dynamically sorting the contents of a column in a table maintenance generator and in turn within a table control.
1 : Consider a table ZTESTL with columns for Material , Language & Material Description.

Generate a TMG for this table. Now go to to SM30 and maintain some entries for this table .
Next go To  SYSTEM-> STATUS .

Note down the the program(GUI) and GUI status .

2: Maintain the event 'ST'  for this TMG. FORM routine will accept only the Program GUI as seen above. Utilities-> Table Maintenance Generator -> Environment-> Modification-> Events

Double click on the editor and this will take you to SE41 screen of MENU painter. Enter the GUI status as EULG and edit the program .

Maintain the SORT push button and activate the function code.This will define that you need a SORT push button on the screen with function code 'SORT'.

3: Go to the table control to define column select. Click on the overview screen '2' from the TMG .

Click on layout and go to change mode and maintain the below settings in 'Table Control ' settings.

Line Sel: Multiple : Means - We can select multiple lines
Column Sel: Single : Means - We can select only one column at a time.
w/SelColumn : Check this field and define a value. This will tell us if a column is selected or not.

4: Now that we have the push button 'SORT' defined and also have the column selection enabled in the table control, lets define what should happen once the push button is clicked.In the PAI of the screen add a module SORT.

Add code to SORT Module based on column names.

DATA : gt_ztest TYPE STANDARD TABLE OF ztestl.
DATA : table_control_col TYPE LINE OF  scxtab_column_it.
DATA : col_sel    TYPE scxtab_column, lv_col_pos TYPE int4.

CASE function.
WHEN 'SORT'. "  Function Code
READ TABLE tctrl_ztestl-cols INTO table_control_col WITH KEY selected = 'X'.
IF sy-subrc = 0.
CASE table_control_col-index .
WHEN '1'.
gt_ztest[] = total[].
SORT gt_ztest[] ASCENDING BY matnr.
total[] = gt_ztest[].
extract[] = total[].
WHEN '2'.
gt_ztest[] = total[].
SORT gt_ztest[] ASCENDING BY spras.
total[] = gt_ztest[].
extract[] = total[].
WHEN '3'.
gt_ztest[] = total[].
SORT gt_ztest[] ASCENDING BY maktx.
total[] = gt_ztest[].
extract[] = total[].
" When no column selected for SORT, pop up displays a message to select a column to sort
titel =  'Information'
txt1  = 'Please Select a Column to Sort!'
txt2  = mark_extract.

5: Now table is available for Sort operation. Just click on any column and press the SORT push button . You can select any column dynamically for SORT operation.
Labels in this area