SALV hide field/column

The SALV hide column/field or cell functionality is much the same as changing the header text you simply use the column variable and set_visible to false to hide it. If you install the example SALV report which includes the basic code below for hiding field SEATSOCC_F, along with how to set the colour of individual rows, columns or fields.

  
      column = salv_columns->get_column( 'SEATSOCC_F' ).
      column->set_visible( if_salv_c_bool_sap=>false ). " hide a specifi SALV column

Hide multiple fields of a SALV report

But we could just as easily hide multiple fields by adding the following code to the program

column = salv_columns->get_column( ‘FLDATE’ ).
column->set_visible( if_salv_c_bool_sap=>false ).

column = salv_columns->get_column( ‘PRICE’ ).
column->set_visible( if_salv_c_bool_sap=>false ).

column = salv_columns->get_column( ‘CURRENCY’ ).
column->set_visible( if_salv_c_bool_sap=>false ).

column = salv_columns->get_column( ‘PLANETYPE’ ).
column->set_visible( if_salv_c_bool_sap=>false ).

“Existing code
column = salv_columns->get_column( ‘SEATSOCC_F’ ).
column->set_visible( if_salv_c_bool_sap=>false ).

If using the example the code should now look like this

screen shot of ABAP code to hide SALV fields

And the report should output without the hidden fields

columns hidden in SALV report

Why use SALV hide to remove a field/column/cell

The question is why to use the hide functionality within instead of just deleting the field from the grid altogether. The main benefit of hiding SALV fields instead of deleting them is that they still exist on the report and can be added back onto the report by a user at any point, by simply using the built-in change layout functionality of standard SAP ALV and SALV reports.

How to restore hidden fields to the ALV report

To do this first click on the change layout icon
ALV change layout

The hidden fields will then appear in the righthand side of the change layout popup for you to select from
choose ALV hidden to add

Simply select the fields you want to add and use the arrows to move the fields acrosss
hidden fields to add to ALV

Click the green tick and the selected fields will be added to the output report
hidden fields restored to SALV