Skip to Content
Author's profile photo Former Member

Working with width of columns in CL_SALV_TABLE

Yesterday I was working with SALV for one of the reports that we had developed and we were stuck with a particular issue.

We wanted to display the long text for a particular field since the customers wanted to see the full explanation for the display field.

We searched the CL_SALV_COLUMN_TABLE and found that SET_LONG_TEXT will work well for our requirement.

We gave something like this.


  SELECT * INTO TABLE ispfli FROM spfli.

      CALL METHOD cl_salv_table=>factory
          r_salv_table = gr_table
          t_table      = ispfli.
    CATCH cx_salv_msg .

  gr_funct = gr_table->get_functions( ).
  gr_funct->set_all( abap_true ).
    gr_columns = gr_table->get_columns( ).
  gr_column ?= gr_columns->get_column( ‘DISTANCE’ ).

  gr_column->set_long_text( ‘NEW LONG TEXT FOR DIST’ ).

  gr_table->display( ).

This didn’t give us the expected results.

It showed the Short text from the data element of the field.

Then we changed the code to below and started experimenting.

  gr_column ?= gr_columns->get_column( ‘DISTANCE’ ).
  gr_column->set_short_text( ‘NEW SHORT ‘ ).
  gr_column->set_medium_text( ‘NEW MEDIUM TEXT ‘ ).
  gr_column->set_long_text( ‘NEW LONG TEXT FOR DIST’ ).
  gr_table->display( ).

It took the new short text as we had given.


If I comment the set_short_text method call it again calls the short text of the data element.

Here if you use SET_OUTPUT_LENGTH and set the output length to 25, it shows the long text.

But now the columns were not optimized. We used SET_OPTIMIZE method to optimize the columns.

  gr_columns->set_optimize( ‘X’ ).

The issue came back, it had again set the short text that we had set to the field name.

So we started wondering how to give the long text?

If we use the method SET_SHORT_TEXT, it sets the field name with the text we had given.

If we comment it, it takes the short text from the data element.

Eventually, we got the solution.

You have to pass blank values in the method SET_SHORT_TEXT and SET_MEDIUM_TEXT to display the long text.

  gr_columns->set_optimize( ‘X’ ).
  gr_column ?= gr_columns->get_column( ‘DISTANCE’ ).
  gr_column->set_short_text( ‘ ‘ ).
  gr_column->set_medium_text( ‘ ‘ ).
  gr_column->set_long_text( ‘NEW LONG TEXT FOR DIST’ ).
  gr_table->display( ).

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      🙂 it was really helpful!

      Author's profile photo Ulrich Rechner
      Ulrich Rechner

      Useful hint! I haven't heard about this trick before.

      Author's profile photo Bernard Reissberg
      Bernard Reissberg

      Useful hint, but unfortunately in my case it works only as long as no standard layout was defined and assigned to all users. This overrides this hardcoded enforcement of the usage of long field names. Any idea how to solve this? 🙂

      Author's profile photo Former Member
      Former Member

      wow, it's really helpful~~~! Thanks a lot. ^^


      Author's profile photo Former Member
      Former Member

      Actually there’s a new method = SET_FIXED_HEADER_TEXT.

      Same values with DDICTXT in SLIS.


      So if you want to use Data Dictionary field labels for your column, you just need to call the said method. Else, set your desired column text type( short, med or long ) too.

      Author's profile photo François Henrotte
      François Henrotte

      Indeed the only good way to do it is to call the two methods.

              ob_column ?= ob_columns->get_column( 'MAKTX' ).
              ob_column->set_fixed_header_text( 'L' ).
              ob_column->set_long_text( 'Description' ).

      You can't rely on the behavior when one of the texts is empty.


      Author's profile photo Sandeep Rawat
      Sandeep Rawat



      Thanks for the explanation.

      I am having an issue when I pass the layout, the length considered by ALV is always short text .

      Kindly let me know if you have found solution for the same.




      Author's profile photo Ashwin Vengurlekar
      Ashwin Vengurlekar

      Apply below code instead of making short text as blank . my case it works

      lo_columns = go_alv->get_columns( ).

      lo_columns->set_optimize( abap_true ).

      Author's profile photo Kevin May
      Kevin May

      Hi, just came across this today, this is very useful as it quickly fixes an age old irritant that we never had time to solve.

      A belated but sincere thank you!