How to rename columns in SAP ALV DISPLAY of type CL_SALV_COLUMNS_TABLE.

The columns can be renamed with the object of the class cl_salv_column_table. There are four methods available such as SET_SHORT_TEXT (), SET_MEDIUM_TEXT(), SET_LONG_TEXT and SET_TOOLTIP(). The method can be chosen based on our requirement of text length.

DATA lr_salv_columns_table TYPE REF TO cl_salv_columns_table.

DATA lr_salv_column_table TYPE REF TO cl_salv_column_table.

DATA lv_short_text TYPE scrtext_s.

DATA lv_medium_text TYPE scrtext_m.

DATA lv_long_text TYPE scrtext_l.

DATA lv_tip_text TYPE lvc_tip.

lr_salv_columns_table = lr_alv_grid -> get_columns ().

lr_salv_column_table ?= lr_salv_columns_table -> get_column(‘CONTACT_NAME’).

lv_short_text = ‘short_contact_name’.

lr_salv_column_table -> set_short_text (lv_short_text).

lv_medium_text = ‘medium_contact_name’.

lr_salv_column_table -> set_medium_text (lv_medium_text).

lv_long_text = ‘long_contact_name’.

lr_salv_column_table -> set_long_text (lv_long_text).

lv_tip_text = ‘tip_contact_name’.

lr_salv_column_table -> set_tooltip(lv_tip_text).

If you wish to force the ABAP execution to use the short text instead of other texts, then there is an easy way to achieve this. Just ignore assigning the medium and long text, then it automatically considers the short text. The other two text formats are ignored by default.

How to rename the column in the SAP ALV List through field catalog

The column names can be changed with the help of the fields REPTEXT, SCRTEXT_L, SCRTEXT_M and SCRTEXT_L of field catalog. If you wish to use only text of field ‘scrtext_l’, then fill the text only in this field ‘SCRTEXT_L’. The other texts can be ignored as the ALV takes the filled text automatically.

FIELD-SYMBOLS: <ls_field_cat> TYPE lvc_s_fcat.

LOOP AT lt_field_cat ASSIGNING <ls_field_cat> WHERE fieldname = ‘CONTACT_ADDRESS’.

              <ls_field_cat> – reptext = ‘New Contact address’.

              <ls_field_cat> – scrtext_l = ‘New Contact add’.

              <ls_field_cat> – scrtext_m = ‘New Contact’.

              <ls_field_cat> – scrtext_s = ‘New Con’.

ENDLOOP.