SALV Table 7 – Changing Column settings

By | September 27, 2008 | SALV Table, SALV Tutorial, Tutorials | 80,623 | 0

Today in the SALV model tutorial series, we will see how we can change the Column properites. You can find all the previous discussion in this series can be found at Tutorials > SALV Table Display .

To change the propeties of the Columns first we need to get the Column object from the SALV Object. The reference of the column object would be CL_SALV_COLUMNS. This object reference would provide us the access to the properties of all the columns. For example, if we need to set the column width optimization for the table, we can set using this columns reference.

To change the individual column properties, we need to get the individual column reference from the reference created using the CL_SALV_COLUMNS. The individual column property can be changed by the getting the reference of CL_SALV_COLUMN. Like, to change the column heading, we need to first get the column from the Columns object and than we need to set specific property.

Here is the code snippet to which provides the ADD-ON code to our Base program. The base program can be found in the SALV Model 1: Normal ALV Table Display .

UML Diagram would be like:

Code Snippet

*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
*    In this section we will define the private methods which can
*      be implemented to set the properties of the ALV and can be
*      called in the
*
  PRIVATE SECTION.
*   Set the various column properties
    METHODS:
      set_columns
        CHANGING
          co_alv TYPE REF TO cl_salv_table.
*
*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*
*
*    In this area we will call the methods which will set the
*      different properties to the ALV
*
* Setting up the Columns
    CALL METHOD me->set_columns
      CHANGING
        co_alv o_alv.
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*
*
*    In this area we will implement the methods which are defined in
*      the class definition
*
  METHOD set_columns.
*
*...Get all the Columns
    DATAlo_cols TYPE REF TO cl_salv_columns.
    lo_cols o_alv->get_columns).
*
*   set the Column optimization
    lo_cols->set_optimize'X' ).
*
*...Process individual columns
    DATAlo_column TYPE REF TO cl_salv_column.
*
*   Change the properties of the Columns KUNNR
    TRY.
        lo_column lo_cols->get_column'KUNNR' ).
        lo_column->set_long_text'Sold-To Party' ).
        lo_column->set_medium_text'Sold-To Party' ).
        lo_column->set_short_text'Sold-To' ).
        lo_column->set_output_length10 ).
      CATCH cx_salv_not_found.                          "#EC NO_HANDLER
    ENDTRY.
*
  ENDMETHOD.                    "SET_COLUMNS
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*

This code snippet will generat output like this:

Like It? Share!!

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.

You seem to be new here. Subscribe to stay connected.