cancel
Showing results for 
Search instead for 
Did you mean: 

How to set some rows in ALV to be editable or some non editable.

Former Member
0 Kudos

Dear all Gurus,

I'm facing a situation here, I need your assistance.

I'm creating a alv table where the user can enter a data and then this will be uploaded into the system. Now upon validation some records might fail and would need some changes and some records that had no problems would have been successfully posted.

When the program returns to the user i want the successful one's to be greyed out and not editable. I'm not sure on how i could acess the rows of the table. I tried few classes and an all i could manage was to change the table setting and configs.

Below i've pasted the code on how i've code my alv table. Please advice on how i could access the rows and disable the successfull ones. Please.

METHOD wddoinit .

DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage,

l_interface TYPE REF TO iwci_salv_wd_table,

  • l_model TYPE ref to cl_salv_wd_config_table, "Contains all characteristics of a table(collumns, fields, etc)

lt_columns TYPE salv_wd_t_column_ref, " Table type

lt_fields TYPE salv_wd_t_field_ref, " Table type

l_btn_ins TYPE REF TO cl_salv_wd_fe_button,

l_btn_del TYPE REF TO cl_salv_wd_fe_button,

l_btn_sell_all TYPE REF TO cl_salv_wd_fe_button,

l_btn_dell_all TYPE REF TO cl_salv_wd_fe_button,

l_btn_calc TYPE REF TO cl_salv_wd_fe_button,

l_btn_save TYPE REF TO cl_salv_wd_fe_button,

l_function TYPE REF TO cl_salv_wd_function,

l_column TYPE REF TO cl_salv_wd_column,

l_header TYPE REF TO cl_salv_wd_column_header,

lr_input_1 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_2 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_3 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_4 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_5 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_6 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_7 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_8 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_9 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_10 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_11 TYPE REF TO cl_salv_wd_uie_input_field,

lr_input_12 TYPE REF TO cl_salv_wd_uie_input_field,

l_link TYPE REF TO cl_salv_wd_uie_button.

CONSTANTS:

zzto TYPE string VALUE 'ZZTO',

zzfrom TYPE string VALUE 'ZZFROM',

takeoff_date TYPE string VALUE 'TAKEOFF_DATE',

read_date TYPE string VALUE 'READ_DATE',

takeoff_time TYPE string VALUE 'TAKEOFF_TIME',

read_time TYPE string VALUE 'READ_TIME',

ac_hrs TYPE string VALUE 'AC_HRS',

le_hrs TYPE string VALUE 'LE_HRS',

re_hrs TYPE string VALUE 'RE_HRS',

ac_cycle TYPE string VALUE 'AC_CYCLE',

re_cycle TYPE string VALUE 'RE_CYCLE',

le_cycle TYPE string VALUE 'LE_CYCLE',

ltext TYPE string VALUE 'LTEXT'.

l_ref_cmp_usage = wd_this->wd_cpuse_multi_alv( ).

IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.

l_ref_cmp_usage->create_component( ).

ENDIF.

*Map the interface.

l_interface = wd_this->wd_cpifc_multi_alv( ).

DATA:

node_mdoc TYPE REF TO if_wd_context_node,

elem_mdoc TYPE REF TO if_wd_context_element.

  • navigate from <CONTEXT> to <MDOC> via lead selection

node_mdoc = wd_context->get_child_node( name = if_create_mass_entry=>wdctx_mdoc ).

l_interface->set_data( r_node_data = node_mdoc ).

*Map the model

wd_this->l_model = l_interface->get_model( ).

*Map the columns

lt_columns = wd_this->l_model->if_salv_wd_column_settings~t_columns.

*Map the fields

lt_fields = wd_this->l_model->if_salv_wd_field_settings~t_fields.

cl_salv_wd_model_table_util=>if_salv_wd_table_util_stdfuncs~set_all(

EXPORTING r_model = wd_this->l_model

allowed = abap_false ). " try abap_true

----


*Enable or Disable the ALV desired outlook and design

----


wd_this->l_model->if_salv_wd_table_settings~delete_header( ).

wd_this->l_model->if_salv_wd_table_settings~set_selection_mode(

value = cl_wd_table=>e_selection_mode-auto ).

wd_this->l_model->if_salv_wd_table_settings~set_width( value = '100%' ).

wd_this->l_model->if_salv_wd_table_settings~set_visible_row_count( value = '10' ).

wd_this->l_model->if_salv_wd_table_settings~set_read_only( value = abap_false ).

wd_this->l_model->if_salv_wd_std_functions~set_filter_filterline_allowed( value = abap_true ).

wd_this->l_model->if_salv_wd_std_functions~set_sort_headerclick_allowed( value = abap_true ).

wd_this->l_model->if_salv_wd_std_functions~set_export_allowed( value = abap_false ).

----


*Adding functionalities to the ALV

*'Insert Row' Button

CREATE OBJECT l_btn_ins.

l_btn_ins->set_text( 'Insert Row' ).

l_btn_ins->set_tooltip( 'To enter a new row' ).

l_btn_ins->set_image_source( value = 'ICON_INSERT_ROW' ).

l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'INSERT' ).

l_function->set_position( value = '1' ).

l_function->set_editor( value = l_btn_ins ).

*'Delete Row' Button

CREATE OBJECT l_btn_del.

l_btn_del->set_text( 'Delete Row' ).

l_btn_del->set_tooltip( 'Delete the selected row' ).

l_btn_del->set_image_source( value = 'ICON_DELETE_ROW' ).

l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'DELETE' ).

l_function->set_position( value = '2' ).

l_function->set_editor( value = l_btn_del ).

*'Select All' Button

CREATE OBJECT l_btn_sell_all.

l_btn_sell_all->set_text( 'Select All' ).

l_btn_sell_all->set_tooltip( 'Select all entered record' ).

l_btn_sell_all->set_image_source( value = 'ICON_INSERT_ROW' ).

l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'SELECT' ).

l_function->set_position( value = '3' ).

l_function->set_editor( value = l_btn_sell_all ).

*'Deselect All' Button

CREATE OBJECT l_btn_dell_all.

l_btn_dell_all->set_text( 'Deselect All' ).

l_btn_dell_all->set_tooltip( 'Deselect all records selected' ).

l_btn_dell_all->set_image_source( value = 'ICON_DESELECT_ALL' ).

l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'DESELECT' ).

l_function->set_position( value = '4' ).

l_function->set_editor( value = l_btn_dell_all ).

*'Calculate' Button

CREATE OBJECT l_btn_calc.

l_btn_calc->set_text( 'Calculate Hours' ).

l_btn_calc->set_tooltip( 'Calculate hours of each record' ).

l_btn_calc->set_image_source( value = 'ICON_CALCULATION' ).

l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'CALC' ).

l_function->set_position( value = '5' ).

l_function->set_editor( value = l_btn_calc ).

*'Save' Button

CREATE OBJECT l_btn_save.

l_btn_save->set_text( 'Save All' ).

l_btn_save->set_tooltip( 'Save all' ).

l_btn_save->set_image_source( value = 'ICON_SYSTEM_SAVE' ).

l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'SAVE' ).

l_function->set_position( value = '6' ).

l_function->set_editor( value = l_btn_save ).

FIELD-SYMBOLS: <fs_column> TYPE salv_wd_s_column_ref.

LOOP AT lt_columns ASSIGNING <fs_column>.

l_column = <fs_column>-r_column.

l_column->get_header( RECEIVING value = l_header ).

l_header->set_ddic_binding_field( value = if_salv_wd_c_column_settings=>ddic_bind_none ).

CASE <fs_column>-id .

WHEN zzfrom.

CREATE OBJECT lr_input_1 EXPORTING value_fieldname = zzfrom.

l_header->set_text( value = 'Flt Fr' ).

l_column->set_position( value = '1' ).

l_column->set_cell_editor( lr_input_1 ).

  • l_column->set_visible( '0' ).

WHEN zzto.

CREATE OBJECT lr_input_2 EXPORTING value_fieldname = zzto.

l_header->set_text( value = 'Flt To' ).

l_column->set_position( value = '2' ).

l_column->set_cell_editor( lr_input_2 ).

WHEN takeoff_date.

CREATE OBJECT lr_input_3 EXPORTING value_fieldname = takeoff_date.

l_header->set_text( value = 'Takeoff Date' ).

l_column->set_position( value = '3' ).

l_column->set_cell_editor( lr_input_3 ).

WHEN read_date.

CREATE OBJECT lr_input_4 EXPORTING value_fieldname = read_date.

l_header->set_text( value = 'Landing Date' ).

l_column->set_position( value = '4' ).

l_column->set_cell_editor( lr_input_4 ).

WHEN takeoff_time.

CREATE OBJECT lr_input_5 EXPORTING value_fieldname = takeoff_time.

l_header->set_text( value = 'Takeoff Time' ).

l_column->set_position( value = '5' ).

l_column->set_cell_editor( lr_input_5 ).

WHEN read_time.

CREATE OBJECT lr_input_6 EXPORTING value_fieldname = read_time.

l_header->set_text( value = 'Landing Time' ).

l_column->set_position( value = '6' ).

l_column->set_cell_editor( lr_input_6 ).

WHEN ac_hrs.

CREATE OBJECT lr_input_7 EXPORTING value_fieldname = ac_hrs.

l_header->set_text( value = 'Flt Time' ).

l_column->set_position( value = '7' ).

l_column->set_cell_editor( lr_input_7 ).

WHEN le_hrs.

CREATE OBJECT lr_input_8 EXPORTING value_fieldname = le_hrs.

l_header->set_text( value = 'LH Eng Runtime' ).

l_column->set_position( value = '8' ).

l_column->set_cell_editor( lr_input_8 ).

WHEN re_hrs.

CREATE OBJECT lr_input_9 EXPORTING value_fieldname = re_hrs.

l_header->set_text( value = 'RH Eng Runtime' ).

l_column->set_position( value = '9' ).

l_column->set_cell_editor( lr_input_9 ).

WHEN ac_cycle.

CREATE OBJECT lr_input_10 EXPORTING value_fieldname = ac_cycle.

l_header->set_text( value = 'No. of Landings' ).

l_column->set_position( value = '10' ).

l_column->set_cell_editor( lr_input_10 ).

WHEN re_cycle.

CREATE OBJECT lr_input_11 EXPORTING value_fieldname = re_cycle.

l_header->set_text( value = 'RH Eng Start' ).

l_column->set_position( value = '11' ).

l_column->set_cell_editor( lr_input_11 ).

WHEN le_cycle.

CREATE OBJECT lr_input_12 EXPORTING value_fieldname = le_cycle.

l_header->set_text( value = 'LH Eng Start' ).

l_column->set_position( value = '12' ).

l_column->set_cell_editor( lr_input_12 ).

WHEN ltext.

CREATE OBJECT l_link.

l_link->set_image_source( value = 'ICON_CREATE_TEXT' ).

l_link->set_text_fieldname( ltext ).

l_link->set_tooltip( value = 'Create Log' ).

l_header->set_text( value = 'Enter Log').

l_column->set_cell_editor( l_link ).

l_column->set_h_align( cl_wd_table_column=>e_h_align-center ).

l_column->set_position( value = '13' ).

WHEN OTHERS.

l_column->set_visible( '01' ).

ENDCASE.

ENDLOOP.

ENDMETHOD.

Your any help is highly appreciated. Thank you.

Regards,

Vinod

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

In your context node that you use for the ALV, have an attribute 'read_only' of type char01.

Have an input field as cell editor for your editable column. Bind the read_only property of your input field to that context attribute read_only. Depending on the validation, just set this field to read only or editable and do a bind_elements to your node. It should work.

Regards,

Nithya

Former Member
0 Kudos

Do you happen to have a sample code?

I already have input fields for the cells. and right now the whole table is editable.

If you have a sample code would be very helpful. Meanwhile i'll do some trial error now. Thanks Nithya

Former Member
0 Kudos

Hi Vinod,

I do not have a sample code as I have done this only with tables and not with ALVs. There is a method set_read_only_fieldname in the class cl_salv_wd_uie_input_field. In your column settings, when you set the cell editor as a reference to this class, set the field name that holds the property of the read_only attribute. In other words, your input field will be read only if this field is X and editable if this field is space.

Now in your internal table, all you have to do is set the value of the read only field and not your actual column field. When you bind, it will be set.

I can try and give you sample code in some time perhaps.

Regards,

Nithya

Former Member
0 Kudos

Ok, here you go.

In your context, apart from your display fields, add another attribute READ_ONLY, type char01. And lets assume you want the field by name field_1 to be editable or not based on some validation. Your code will be like this to initialize the ALV.

DATA:

l_alv_model TYPE REF TO cl_salv_wd_config_table,

lr_column_settings TYPE REF TO if_salv_wd_column_settings,

lr_column TYPE REF TO cl_salv_wd_column,

lt_col TYPE SALV_WD_T_COLUMN_REF,

ls_col TYPE SALV_WD_S_COLUMN_REF,

lr_input_field type ref to cl_salv_wd_uie_input_field.

l_alv_model = l_ref_interfacecontroller->get_model( ).

l_alv_model->IF_SALV_WD_TABLE_SETTINGS~SET_READ_ONLY( abap_false ).

lr_column_settings ?= l_alv_model.

lt_col = lr_column_settings->get_columns( ).

LOOP AT lt_col INTO ls_col where ID = 'FIELD_1'.

create object lr_input_field exporting value_fieldname = ls_col-id.

lr_input_field->set_read_only_fieldname( 'READ_ONLY' ).

ls_col-r_column->set_cell_editor( lr_input_field ).

ENDLOOP.

In your event handler, you read your node, do a get_static_attributes_table. Perform all validations. Loop through your internal table and set the field READ_ONLY as 'X' when validation succeeds. Do READ_ONLY = space when validation fails. Then do a bind_elements. Now the rows for which read_only is false, will be editable and vice versa.

Hope I was clear enough. Get back if you have any doubts.

Regards,

Nithya

Former Member
0 Kudos

Hi Nithya,

My current code is something like the example you have given. but this set the column for all the rows editable.

I'm sorry if i was not clear before. I only need all columns in some rows to be non editable and other will be as per normal (editable).

THank you

Vinod

Former Member
0 Kudos

Hi Vinod,

This will not set the column for all rows as editable. Your internal table that you will be binding to the context node will have the field set for each row. You should loop through the table and set the value of this read_only field. Depending on it, it will set the value as editable or not.

The method <b>lr_column->set_read_only_fieldname</b> is the difference between your existing code and mine. Thats what makes it work at a row level.

Some code like this should be in your check event handler:

loop at itab into wa.

if wa is <valid>. "Assuming you are doing validation based on the row's content

wa-read_only = 'X'.

else.

wa_read_only = ''.

endif.

modify itab from wa.

endloop.

When you are filling the context initially, make the field space for all the rows.

Regards,

Nithya

Former Member
0 Kudos

Thanks buddy...

IT HELP ALOT!!

Former Member
0 Kudos

Sure you're welcome:-)

Former Member
0 Kudos

Hi Vinod,

Since you have closed the thread, I assume you're problem is solved. Please award points if its done.

Regards,

Nithya

Former Member
0 Kudos

hi nithya,

thanks for your thread - it offers a lot of information! i have another question, hope you can help me: it is possible to make a column/field of an alv-list wrappable?

dieter