Skip to Content

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.

  START-OF-SELECTION.

  SELECT * INTO TABLE ispfli FROM spfli.

  TRY.
      CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table = gr_table
        CHANGING
          t_table      = ispfli.
    CATCH cx_salv_msg .
  ENDTRY.

  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.

untitled.GIF

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( ).

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. 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? 🙂

    (0) 
  2. eleazar gutierrez

    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.

    (0) 
  3. 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.

     

    (0) 
  4. sandeep rawat

    Hi

     

    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.

     

    Thanks

    Sandeep

    (0) 

Leave a Reply