简体   繁体   中英

Display only certain fields in ALV

My table has around 300 columns and I want to display only 10 out of them with specifying which ones. I am working with CL_SALV_TABLE .

Can anybody help me with this problem or give me a hint? Thank you very much in advance!

You need to use the method SET_VISIBLE of the Column object (class CL_SALV_COLUMN ). For more information, see the chapter "Set the Visibility of the Column" of page "Columns (General)" .

This Minimal reproducible example shows only the columns SPRAS and LAISO from the table T002 , all other ones are hidden:

  DATA: t002_lines  TYPE TABLE OF t002,
        salv        TYPE REF TO cl_salv_table,
        columns     TYPE salv_t_column_ref.
  FIELD-SYMBOLS <column> TYPE salv_s_column_ref.

  SELECT * FROM t002 INTO TABLE t002_lines.
  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table = salv
    CHANGING
      t_table      = t002_lines.

  LOOP AT salv->get_columns( )->get( ) ASSIGNING <column>.
    CASE <column>-columnname.
      WHEN 'SPRAS' OR 'LAISO'.
        <column>-r_column->set_visible( if_salv_c_bool_sap=>true ).
      WHEN OTHERS.
        <column>-r_column->set_visible( if_salv_c_bool_sap=>false ).
    ENDCASE.
  ENDLOOP.

  salv->display( ).

This code is used to hide all columns of a table except the ones specified.

  1. The table is passed as a "t002" type table of lines, and then an instance of the "CL_SALV_TABLE" class is created by calling its "factory" method.
  2. Then, all columns of the table are iterated through using the "get_columns" method, and each column is assigned to a field symbol.
  3. For each column, its name is checked, and if it is "SPRAS" or "LAISO", it is made visible using the "set_visible" method of the "Column" object and passing "true" as a parameter.
  4. If the column is not "SPRAS" or "LAISO", it is hidden by passing "false" as a parameter.
  5. Finally, the "display" method of the "salv" the object is called to show the table with the hidden columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM