SAP Tech Pro

SAP Technical Blog

How to Hide/Exclude one or more columns in ALV using class CL_SALV_TABLE

How to Hide/Exclude one or more columns in ALV using class CL_SALV_TABLE

We need to retrieve many columns into the internal table in order to do the data processing but we might need to display fewer columns in the ALV. So let us find out how to exclude one are more columns from the output using CL_SALV_TABLE.

All that you need to do is to get the specific column and set the column to invisible using the method set_visible( abap_false ).


* Get Columns
  o_columns = o_alv->get_columns( ).
  IF o_columns IS BOUND.
*   Exclude the column 'FLTIME'
    o_column ?= o_columns->get_column( 'FLTIME' ).
    IF o_column IS BOUND.
      o_column->set_visible( abap_false ).
    ENDIF.
  ENDIF.

 

Complete Code


*&---------------------------------------------------------------------*
*& Report  ZSTP_EXCLUDE_COLUMN_ALV
*&
*&---------------------------------------------------------------------*
*& SAPTechPro.com
*&
*&---------------------------------------------------------------------*

REPORT zstp_exclude_column_alv.

DATA: i_spfli   TYPE TABLE OF spfli,
      o_alv     TYPE REF TO cl_salv_table,
      o_funct   TYPE REF TO cl_salv_functions,
      o_columns TYPE REF TO cl_salv_columns_table,
      o_column  TYPE REF TO cl_salv_column_table.

START-OF-SELECTION.

  SELECT * INTO TABLE i_spfli FROM spfli UP TO 50 ROWS.

  TRY.
      CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table = o_alv
        CHANGING
          t_table      = i_spfli.
    CATCH cx_salv_msg .
  ENDTRY.

* Set PF Status
  o_alv->get_functions( )->set_all( abap_true ).

* Get Columns
  o_columns = o_alv->get_columns( ).
  IF o_columns IS BOUND.
*   Exclude the column 'FLTIME'
    o_column ?= o_columns->get_column( 'FLTIME' ).
    IF o_column IS BOUND.
      o_column->set_visible( abap_false ).
    ENDIF.
  ENDIF.

  o_alv->display( ).

 

Output:

How to Exclude one or more columns in ALV using class CL_SALV_TABLE

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in