cancel
Showing results for 
Search instead for 
Did you mean: 

Hiding the col in ALV by Configuring ALV

ArtiBhat
Associate
Associate
0 Kudos

Hi All,

Our requirement is that depending on the user selection from tree we have to display Columns in ALV.

We have created different variants of ALV also.

The problem is that once i add any col in Displayed ALV Columns through settings button i cannot make it invisible thru configure ALV.

The settings done in ALV always wins.

Could you please tell me is there any way to hide and display columns even though the column will be added in Displayed Col list thru settings button.

Regards,

Arti.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

suppose i have a column named 'OBJ_ID' AND 'OBJTP'and i want to hide then use the following code

DATA:

lr_comp_alv TYPE REF TO if_wd_component_usage,

lr_comp_if_alv TYPE REF TO iwci_salv_wd_table,

lr_config TYPE REF TO cl_salv_wd_config_table,

lr_column TYPE REF TO cl_salv_wd_column,

ls_column TYPE salv_wd_s_column_ref,

lt_columns TYPE salv_wd_t_column_ref.

*... ALV Component Usage

lr_comp_alv = wd_this->wd_cpuse_alv( ).

IF lr_comp_alv->has_active_component( ) IS INITIAL.

lr_comp_alv->create_component( ).

ENDIF.

lr_comp_if_alv = wd_this->wd_cpifc_alv( ).

*... Configure ALV

lr_config = lr_comp_if_alv->get_model( ).

  • lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).

  • lr_config->if_salv_wd_std_functions~set_edit_insert_row_allowed( ).

lr_config->if_salv_wd_std_functions~set_view_list_allowed( abap_false ).

lr_config->if_salv_wd_std_functions~set_export_allowed( abap_true ).

lt_columns = lr_config->if_salv_wd_column_settings~get_columns( ).

lr_column = lr_config->if_salv_wd_column_settings~get_column('OBJID' ).

LOOP AT lt_columns INTO ls_column.

CASE ls_column-id.

  • when 'OBJID'.

  • ls_column-r_column->set_visible( value = '99' ).

when 'OBJTP'.

ls_column-r_column->set_visible( value = '99' ).

ENDCASE.

ENDLOOP.

Former Member
0 Kudos

Hi Arti,

While configuring the ALV, read the existing columns, and set each one to 'visible' or 'invisible' as required. This should ideally work. If it doesn't work, try the following:

When creating the ALV, do not use the old existing instance of the ALV, each time, create a new instance and configure the instance again.

Hope this helps.

Wenonah

ArtiBhat
Associate
Associate
0 Kudos

Hi,

Thanks for reply.

But my qn is different.

I am handling the visibiity of cols inside the configure ALV .

The problem is that once u add some col thru settings button of ALV in UI, u cannot make it invisible in Configure ALV.

I want the col to be present in Displayed col list of ALV settings but i should also make it visible or invisiblr thru configure ALV.

This is not happening.

Once i add some col manually in settings of ALV UI, i cannot make it invisible thru configure ALV.

Rgds,

Arti.

Former Member
0 Kudos

Hi Arti,

your ALV is binded to some context right.

and that context has columns.

in method where you are configuring alv.

declare all columns.

and use a flag to set the visibility at runtime.

use the following code:

DATA : lr_alv_if type ref to iwci_salv_wd_table,

lr_alv_model type ref to cl_salv_wd_config_table,

lr_cmp_usage type ref to if_wd_component_usage,

lr_column_settings TYPE REF TO if_salv_wd_column_settings,

lt_columns TYPE salv_wd_t_column_ref,

ls_column TYPE salv_wd_s_column_ref,

lr_table_settings TYPE REF TO if_salv_wd_table_settings,

lr_header type ref to cl_salv_wd_column_header,

lr_cmp_usage = wd_this->wd_cpuse_appr_alv( ).

IF lr_cmp_usage->has_active_component( ) is initial.

lr_cmp_usage->create_component( ).

ENDIF.

*... Invoke a Method of the ALV Interfacecontroller

lr_alv_if = wd_this->wd_cpifc_appr_alv( ).

*... Get Model

lr_alv_model = lr_alv_if->get_model( ).

lr_column_settings ?= lr_alv_model.

      • Set ALV as editable

  • lr_column_settings->set_read_only( abap_false ).

  • get table of column settings - each line one column

lt_columns = lr_column_settings->get_columns( ).

  • loop over table - in each loop another column can be modified

LOOP AT lt_columns INTO ls_column.

CASE ls_column-id.

WHEN 'COLUMN NAME'.

"Setting Cell Editor Property

CREATE OBJECT lr_checkbox EXPORTING

checked_fieldname = 'COLUMN NAME'.

lr_checkbox->set_read_only( abap_true ).

"Setting Column Property

ls_column-r_column->SET_CELL_EDITOR( lr_checkbox ).

ls_column-r_column->SET_VISIBLE( EXPORTING value = FLAG ).

......

.......

and call your method by passing the value of flag as 'X' or ' ' as you require.

this will work.

plz feel free to ask any further help if required.

Regards,

Ritwik.

Yashpal
Active Contributor
0 Kudos

Hi Arti ,

You have used the personalization for that column ,so it will be used at runtime instead of all the coding stuff u have done for column . so better way is to do not allow personlization for the application . delete the personlization u have created .

Regards

Yash

ArtiBhat
Associate
Associate
0 Kudos

Hi,

My qn is still not solved.

In settngs of ALV UI, add one col in Displayed cols list, make the same col invisible in configure .

Test ur Application one more time.

U will see that the col is still visible even though u have made it invisible in Configure ALV.

Regards,

arti

ArtiBhat
Associate
Associate
0 Kudos

Hi Yash,

For variants we are using &sap-config-mode=X, This mode we have used for global settings.

I cannot delete the variants as we need them.

We have created different views of ALV for user convenience.

Rgds,

Arti.

Former Member
0 Kudos

Hi Aarti,

it dose work.

your column gets hidden.

you have to make a call to your method at appropriate place.

if you need any further help or clarification regarding it please mail.

Regards,

Ritwik.

Yashpal
Active Contributor
0 Kudos

Yes , that's the configuration you are doing , if that column is displayed in the configuration than coding will not override it .

As the columns will be avaliable for the enduser to personalize , disable that feature.

Regards

Yash