cancel
Showing results for 
Search instead for 
Did you mean: 

Making Alv fields editable

Former Member
0 Kudos

Hi All,

I wrote the following code to generate dynamic alv. But I want to make some of the fields editable. I am able to generate the dynamic alv, but my code is not working for making the fields editable can any one help me solve this issue please.

DATA lo_nd_node TYPE REF TO if_wd_context_node.

DATA lo_el_node TYPE REF TO if_wd_context_element.

DATA ls_node TYPE wd_this->element_node-attr1.

lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ).

lo_el_node = lo_nd_node->get_element( ).

lo_el_node->get_attribute(

EXPORTING name = `ATTR1` IMPORTING value = ls_node ).

data: concat type c value 'R',

compfield type c length 5.

data:

rootnode_info type ref to if_wd_context_node_info,

dyn_node type ref to if_wd_context_node,

tabname_node type ref to if_wd_context_node,

struct_type type ref to cl_abap_structdescr,

comp_tab type cl_abap_structdescr=>component_table,

comp like line of comp_tab,

col_counter type n value '1'.

data lo_componentcontroller type ref to ig_componentcontroller.

data lo_cmp_usage type ref to if_wd_component_usage.

data : l_view_controller_api type ref to if_wd_view_controller,

lr_column type ref to cl_salv_wd_column, " Table fo rcolumn ref

ls_columns type salv_wd_s_column_ref, " Structure for column ref

lt_columns type salv_wd_t_column_ref, " Structure for column ref

lr_input type ref to cl_salv_wd_uie_input_field,

l_value type ref to cl_salv_wd_config_table,

lr_column_settings type ref to if_salv_wd_column_settings,

lr_table_settings type ref to if_salv_wd_table_settings,

DATA LO_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .

LO_INTERFACECONTROLLER = WD_THIS->WD_CPIFC_region_ALV( ).

comp-name = 'PHASE'.

comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).

append comp to comp_tab.

col_counter = 1.

clear: compfield.

do ls_node times.

clear comp.

concatenate concat col_counter into compfield.

comp-name = compfield.

comp-type ?= cl_abap_datadescr=>describe_by_name( 'zregions-region' ).

append comp to comp_tab.

col_counter = col_counter + 1.

enddo.

rootnode_info = wd_context->get_node_info( ).

struct_type = cl_abap_structdescr=>create( comp_tab ).

lo_componentcontroller = wd_this->get_componentcontroller_ctr( ).

rootnode_info = rootnode_info->add_new_child_node(

name = 'NODE_NAME'

is_mandatory = abap_false

is_multiple = abap_true

static_element_rtti = struct_type

is_static = abap_false

is_initialize_lead_selection = abap_false

).

dyn_node = wd_context->get_child_node( name = 'NODE_NAME' ).

lo_cmp_usage = wd_this->wd_cpuse_region_alv( ).

if lo_cmp_usage->has_active_component( ) is initial.

lo_cmp_usage->create_component( ).

endif.

lo_interfacecontroller->set_data( dyn_node ).

l_value = lo_interfacecontroller->get_model( ).

CALL METHOD L_VALUE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMNS

RECEIVING

VALUE = LT_COLUMNS.

LOOP AT LT_COLUMNS INTO LS_COLUMNS.

case ls_columns-id.

WHEN 'PHASE'.

" Non Editable field

LR_COLUMN = LS_COLUMNS-R_COLUMN.

CREATE OBJECT LR_INPUT

EXPORTING

VALUE_FIELDNAME = LS_COLUMNS-ID.

CALL METHOD LR_COLUMN->SET_CELL_EDITOR

EXPORTING

VALUE = LR_INPUT.

LR_INPUT->SET_READ_ONLY_FIELDNAME( VALUE = 'READ_ONLY' ).

when others.

LR_COLUMN = LS_COLUMNS-R_COLUMN.

CREATE OBJECT LR_INPUT

EXPORTING

VALUE_FIELDNAME = LS_COLUMNS-ID.

CALL METHOD LR_COLUMN->SET_CELL_EDITOR

EXPORTING

VALUE = LR_INPUT.

LR_TABLE_SETTINGS ?= L_VALUE.

LR_TABLE_SETTINGS->SET_READ_ONLY( ABAP_FALSE ).

ENDcase.

ENDLOOP.

Accepted Solutions (0)

Answers (3)

Answers (3)

gill367
Active Contributor
0 Kudos

Try this modified code ..

you dont need to do anything for non editable fields they will be like tat by default.

DATA lo_nd_node TYPE REF TO if_wd_context_node.
DATA lo_el_node TYPE REF TO if_wd_context_element.
DATA ls_node TYPE wd_this->element_node-attr1.
lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ).
lo_el_node = lo_nd_node->get_element( ).
lo_el_node->get_attribute(

EXPORTING name = `ATTR1` IMPORTING value = ls_node ).

data: concat type c value 'R',
compfield type c length 5.

data:
rootnode_info type ref to if_wd_context_node_info,
dyn_node type ref to if_wd_context_node,
tabname_node type ref to if_wd_context_node,
struct_type type ref to cl_abap_structdescr,
comp_tab type cl_abap_structdescr=>component_table,
comp like line of comp_tab,
col_counter type n value '1'.

data lo_componentcontroller type ref to ig_componentcontroller.
data lo_cmp_usage type ref to if_wd_component_usage.
data : l_view_controller_api type ref to if_wd_view_controller,
lr_column type ref to cl_salv_wd_column, " Table fo rcolumn ref
ls_columns type salv_wd_s_column_ref, " Structure for column ref
lt_columns type salv_wd_t_column_ref, " Structure for column ref
lr_input type ref to cl_salv_wd_uie_input_field,
l_value type ref to cl_salv_wd_config_table,
lr_column_settings type ref to if_salv_wd_column_settings,
lr_table_settings type ref to if_salv_wd_table_settings,


DATA LO_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
LO_INTERFACECONTROLLER = WD_THIS->WD_CPIFC_region_ALV( ).

comp-name = 'PHASE'.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).
append comp to comp_tab.

col_counter = 1.
clear: compfield.
do ls_node times.
clear comp.
concatenate concat col_counter into compfield.
comp-name = compfield.
comp-type ?= cl_abap_datadescr=>describe_by_name( 'zregions-region' ).
append comp to comp_tab.
col_counter = col_counter + 1.
enddo.

rootnode_info = wd_context->get_node_info( ).
struct_type = cl_abap_structdescr=>create( comp_tab ).

lo_componentcontroller = wd_this->get_componentcontroller_ctr( ).

rootnode_info = rootnode_info->add_new_child_node(
name = 'NODE_NAME'
is_mandatory = abap_false
is_multiple = abap_true
static_element_rtti = struct_type
is_static = abap_false
is_initialize_lead_selection = abap_false
).

dyn_node = wd_context->get_child_node( name = 'NODE_NAME' ).

lo_cmp_usage = wd_this->wd_cpuse_region_alv( ).

if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.

lo_interfacecontroller->set_data( dyn_node ).
l_value = lo_interfacecontroller->get_model( ).

CALL METHOD L_VALUE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMNS
RECEIVING
VALUE = LT_COLUMNS.
LOOP AT LT_COLUMNS INTO LS_COLUMNS.
case ls_columns-id.
WHEN 'PHASE'.
" Non Editable field
" dont do anything here by default the col will be non editable
when others.
LR_COLUMN = LS_COLUMNS-R_COLUMN.
CREATE OBJECT LR_INPUT
EXPORTING
VALUE_FIELDNAME = LS_COLUMNS-ID.
CALL METHOD LR_COLUMN->SET_CELL_EDITOR
EXPORTING
VALUE = LR_INPUT.
LR_TABLE_SETTINGS ?= L_VALUE.
LR_TABLE_SETTINGS->SET_READ_ONLY( ABAP_FALSE ).
ENDcase.
ENDLOOP.

thanks

sarbjeet singh

Former Member
0 Kudos

Hi All,

Thanks for all your valuable replies. I went through all the forums and tried changing my code but still i dont know why the fields are non editable. I even tried changing the code as Sabarjeet said but its not working. When i debugged i found it is getting the column name but it is not being set to editable dont know why. Kindly please help me solve this issue.

gill367
Active Contributor
0 Kudos
if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.
 
lo_interfacecontroller->set_data( dyn_node ).
l_value = lo_interfacecontroller->get_model( ).
 
CALL METHOD L_VALUE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMNS
RECEIVING
VALUE = LT_COLUMNS.
LOOP AT LT_COLUMNS INTO LS_COLUMNS.
case ls_columns-id.
WHEN 'PHASE'.
" Non Editable field
" dont do anything here by default the col will be non editable
when others.
LR_COLUMN = LS_COLUMNS-R_COLUMN.

CREATE OBJECT LR_INPUT
EXPORTING
VALUE_FIELDNAME = LS_COLUMNS-ID.
CALL METHOD LR_COLUMN->SET_CELL_EDITOR
EXPORTING
VALUE = LR_INPUT.
LR_TABLE_SETTINGS ?= L_VALUE.
ENDcase.
ENDLOOP.
LR_TABLE_SETTINGS->SET_READ_ONLY( ABAP_FALSE ).  "write it outside the loop.

when you change the celleditor of anycol to input field

it will automatically become editable.

thanks

sarbjeet singh

former_member199125
Active Contributor
0 Kudos

If you set the alv cells as input field cells, then you can say alv table is editable.

So set the all the cells as input fields

Regards

Srinivas

Former Member
0 Kudos

Hi Maha,

Please go through this.. check Lekhas reply.

Cheers,

Kris.

Edited by: kissnas on May 16, 2011 6:10 AM