CL_SALV_COLUMNS_TABLE¶
Controls column visibility, titles, widths, and types for a CL_SALV_TABLE grid.
Purpose¶
CL_SALV_COLUMNS_TABLE is the column manager for a CL_SALV_TABLE grid. Obtain it from the ALV instance — never instantiate it directly. Use it to auto-fit widths, rename headers, reorder columns, hide columns, and set cell types (hotspot, button, checkbox).
Key methods¶
On the columns object (CL_SALV_COLUMNS_TABLE)¶
| Method | Signature | Effect |
|---|---|---|
set_optimize |
( value = abap_true ) |
Auto-fit all column widths to content |
get_column |
( columnname = 'FIELDNAME' ) → CL_SALV_COLUMN_TABLE |
Returns a handle to one column |
set_column_position |
( columnname position ) |
Moves a column to the given 1-based position |
On a column object (CL_SALV_COLUMN_TABLE)¶
| Method | Signature | Effect |
|---|---|---|
set_visible |
( value = abap_false ) |
Hides the column |
set_short_text |
( value = '...' ) |
Label when column is narrow (≤ ~8 chars) |
set_medium_text |
( value = '...' ) |
Label at medium width |
set_long_text |
( value = '...' ) |
Label at full width |
set_key |
( value = abap_true ) |
Fixes column to the left (like a key field) |
set_cell_type |
( value = if_salv_c_cell_type=>hotspot ) |
Marks cells as clickable hotspot, button, or checkbox |
Example¶
Optimise widths, rename two columns, and hide one:
REPORT z_salv_columns_demo.
DATA: lt_users TYPE STANDARD TABLE OF usr02,
lo_alv TYPE REF TO cl_salv_table.
START-OF-SELECTION.
SELECT bname, ustyp, gltgv, gltgb
FROM usr02
INTO CORRESPONDING FIELDS OF TABLE @lt_users
UP TO 50 ROWS.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_alv
CHANGING t_table = lt_users ).
" --- column configuration ---
DATA(lo_columns) = lo_alv->get_columns( ).
lo_columns->set_optimize( abap_true ). " auto-fit widths
" rename BNAME column
DATA(lo_col_bname) = CAST cl_salv_column_table(
lo_columns->get_column( 'BNAME' ) ).
lo_col_bname->set_short_text( 'User' ).
lo_col_bname->set_medium_text( 'User ID' ).
lo_col_bname->set_long_text( 'User Name' ).
lo_col_bname->set_key( abap_true ).
" rename USTYP column
DATA(lo_col_type) = CAST cl_salv_column_table(
lo_columns->get_column( 'USTYP' ) ).
lo_col_type->set_short_text( 'Type' ).
lo_col_type->set_medium_text( 'User Type' ).
lo_col_type->set_long_text( 'User Account Type' ).
" hide GLTGV (valid-from date — rarely needed at a glance)
DATA(lo_col_from) = CAST cl_salv_column_table(
lo_columns->get_column( 'GLTGV' ) ).
lo_col_from->set_visible( abap_false ).
lo_alv->display( ).
CATCH cx_salv_msg INTO DATA(lx_salv).
MESSAGE lx_salv->get_text( ) TYPE 'E'.
CATCH cx_salv_not_found INTO DATA(lx_not_found).
MESSAGE lx_not_found->get_text( ) TYPE 'E'.
ENDTRY.
Common pitfalls¶
Cast the result of get_column
get_column returns CL_SALV_COLUMN (the base type). You must CAST it to CL_SALV_COLUMN_TABLE before calling table-specific methods like set_cell_type. Missing the cast causes a short dump at runtime.
cx_salv_not_found on bad field names
get_column raises CX_SALV_NOT_FOUND if the field name does not exist in the table structure. Always catch it separately, especially in generic helper methods that receive field names at runtime.
Text priority
SAP picks short_text, medium_text, or long_text based on the rendered column width. Set all three for consistent labels at any zoom level. If you only set one, the DDIC label fills in for the others.
set_optimizeruns after the data is bound — calling it beforefactoryhas no effect.- Column positions are 1-based. Passing
0raises a runtime error. - Hiding a column with
set_visible( abap_false )does not remove it from the layout — users can re-add it via the personalisation dialog unless you also lock the layout.
See also¶
CL_SALV_TABLE— the parent ALV objectCL_SALV_FUNCTIONS_LIST— toolbar configurationCL_SALV_EVENTS_TABLE— handle hotspot/link clicks- Demo program:
SALV_DEMO_TABLE_COLUMNS