Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Webdynpro ABAP - Disable certain columns in editable ALV

Former Member
0 Kudos
514

Hi,

I am new to WD ABAP application. I have a screen with 2 radiobuttons - Create and Display

On clicking display, data from db will be displayed in ALV in disable mode based on the input parameters.

On clicking create, ALV should be editable with all fields for input. Then, when the user inputs data in one of the field, say FLAG as 'NO', 2 other columns should be disabled for input automatically. So initially, all the fields in the ALV should be editable, later based on a input value, few cells should be disabled for input.

I have done the following:

Step 1: On selecting the radio button, in action - I have made all the cells of the ALV editable.

DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
DATA lv_value TYPE REF TO cl_salv_wd_config_table.

 lo_cmp_usage = wd_this->wd_cpuse_alv_proj( ).
 IF lo_cmp_usage->has_active_component( ) IS INITIAL.
 lo_cmp_usage->create_component( ).
 ENDIF.

lo_interfacecontroller = wd_this->wd_cpifc_alv_proj( ).
lv_value = lo_interfacecontroller->get_model( ).

 DATA : lr_columns TYPE salv_wd_t_column_ref .
 DATA : ls_columns TYPE salv_wd_s_column_ref .

 CALL METHOD lv_value->if_salv_wd_column_settings~get_columns
 RECEIVING
 value = lr_columns. 

DATA : lr_input TYPE REF TO cl_salv_wd_uie_input_field .

LOOP AT lr_columns INTO ls_columns.
CREATE OBJECT lr_input
 EXPORTING
 value_fieldname = ls_columns-id. 

 CALL METHOD ls_columns-r_column->set_cell_editor
 EXPORTING
 value = lr_input.

CALL METHOD lv_value->if_salv_wd_table_settings~set_read_only
 EXPORTING
 value = abap_FALSE.
ENDLOOP.

Step 2: Created an event handler method ON_CELL_ACTION_ALV to recognize the data change in ALV on pressing ENTER. Here, I have called the method - DATA_CHECK

DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
 lo_interfacecontroller = wd_this->wd_cpifc_alv_proj( ).
 lo_interfacecontroller->data_check( ).	

Step 3: Triggered the ON_CELL_ACTION event in WDDOMODIFYVIEW

DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
DATA lv_value TYPE REF TO cl_salv_wd_config_table.

 lo_cmp_usage = wd_this->wd_cpuse_alv_proj( ).
 IF lo_cmp_usage->has_active_component( ) IS INITIAL.
 lo_cmp_usage->create_component( ).
 ENDIF.

 lo_interfacecontroller = wd_this->wd_cpifc_alv_proj( ).
 lv_value = lo_interfacecontroller->get_model( ).

 CALL METHOD lv_value->if_salv_wd_table_settings~set_cell_action_event_enabled
 EXPORTING
 value = abap_true.

Step 4: Added a READ_ONLY attribute in the node created for alv

Step 5: Created an event handler method ON_DATA_CHECK_ALV for checking any data change in ALV

 DATA : wa_param LIKE LINE OF r_param->t_modified_cells.
 DATA lo_nd_prj_item TYPE REF TO if_wd_context_node.
 DATA lo_el_prj_item TYPE REF TO if_wd_context_element.
 DATA lt_prj_item TYPE wd_this->elements_prj_item.
 DATA ls_prj_item LIKE LINE OF lt_prj_item.
 DATA lo_api_controller TYPE REF TO if_wd_controller.
 lo_nd_prj_item = wd_context->get_child_node( name = wd_this->wdctx_prj_item ).
 lo_el_prj_item = lo_nd_prj_item->get_element( ).
 lo_nd_prj_item->get_static_attributes_table( IMPORTING table = lt_prj_item ).

LOOP AT r_param->t_modified_cells INTO wa_param WHERE attribute = 'FLAG'.
 READ TABLE lt_prj_item INTO ls_prj_item INDEX wa_param-index.
 IF ls_prj_item-flag = 'N'.
   ls_prj_item-read_only = 'X'.
 ELSE.
   ls_prj_item-read_only = ' '.
 ENDIF.
 ENDLOOP.

 DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
 lo_cmp_usage = wd_this->wd_cpuse_alv_proj( ).
 IF lo_cmp_usage->has_active_component( ) IS INITIAL.
 lo_cmp_usage->create_component( ).
 ENDIF.

 DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
 lo_interfacecontroller = wd_this->wd_cpifc_alv_proj( ).

 DATA lv_value TYPE REF TO cl_salv_wd_config_table.
 lv_value = lo_interfacecontroller->get_model( ).

 DATA : lr_columns TYPE salv_wd_t_column_ref . 
 DATA : ls_columns TYPE salv_wd_s_column_ref .

CALL METHOD lv_value->if_salv_wd_column_settings~get_columns
 RECEIVING
 value = lr_columns.

DATA : lr_input TYPE REF TO cl_salv_wd_uie_input_field .

 LOOP AT lr_columns INTO ls_columns
 WHERE id = 'DISABLE_COLUMN_1' OR id = 'DISABLE_COLUMN_2'.
 CREATE OBJECT lr_input
 EXPORTING
 value_fieldname = ls_columns-id. 

 lr_input->set_read_only_fieldname( 'READ_ONLY' ).

 CALL METHOD ls_columns-r_column->set_cell_editor
 EXPORTING
 value = lr_input.

CALL METHOD lv_value->if_salv_wd_table_settings~set_read_only
EXPORTING
value = abap_true.
ENDLOOP.

But all the editable cells now go in disable mode instead of the two columns DISABLE_COLUMN_1 and DISABLE_COLUMN_2.

Kindly help.

2 REPLIES 2

pokrakam
Active Contributor
0 Kudos
252

Please format code as code so that it's readable.

Former Member
0 Kudos
252

Hi Mike,

Kindly check now