SALV Default Column description as Column Name

By | Last Updated on August 11, 2014 | 5,156

Code snippet to set the Column Description as the Column Name when the Column description is empty in the ALV generated by SALV model.

Sometimes you want to do some quick programming. When you use the generic types to define the Itab, SALV doesn’t show any description.

Column Description as Column Name

 
*
    DATA: lo_cols     TYPE REF TO  cl_salv_columns,
          lo_column   TYPE REF TO  cl_salv_column_list,
          lt_cols     TYPE         salv_t_column_ref,
          ls_cols     LIKE LINE OF lt_cols.
 
    DATA: lv_short    TYPE scrtext_s.
    DATA: lv_med      TYPE scrtext_m.
    DATA: lv_long     TYPE scrtext_l.
 
* Columns
    lo_cols = o_salv->get_columns( ).
    lo_cols->set_optimize( 'X' ).
 
* For each column
* If Short description is not there, set Short
* If Medium description is not there, set Medium
* If Long description is not there, set Long
    lt_cols    = lo_cols->get( ).
    LOOP AT lt_cols INTO ls_cols.
      lo_column ?= ls_cols-r_column.    "Narrow casting
      IF lo_column->get_short_text( ) IS INITIAL.
        lv_short = ls_cols-columnname.
        lo_column->set_short_text( lv_short ).
      ENDIF.
      IF lo_column->get_medium_text( ) IS INITIAL.
        lv_med = ls_cols-columnname.
        lo_column->set_medium_text( lv_med ).
      ENDIF.
      IF lo_column->get_long_text( ) IS INITIAL.
        lv_long = ls_cols-columnname.
        lo_column->set_long_text( lv_long ).
      ENDIF.
    ENDLOOP.
 

More – SALV Various ways to Access Columns

Do you have a Code Snippet which you want to share, Submit Code Snippet here

Share It!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

Comments on this Post are now closed. If you have something important to share, you can always contact me.