cancel
Showing results for 
Search instead for 
Did you mean: 

How to Edit selected row in ALV

Former Member
0 Kudos

Hi Experts,

I new to webdynpro ABAP. How to Edit the entire selected row in ALV. Please suggest?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Edit a single row in ALV -

check out my reply in the above thread

Regards,

Lekha.

Former Member
0 Kudos

Hi Lekha,

Thanks for ur reply. I read ur link but I used dynamic internal table for generating ALV grid using component SALV_WD_TABLE.How to make selected row as editable when button click ?

Thanks.

Former Member
0 Kudos

Hi,

I guess you have created the node as dynamic and also set this to the ALV..

1. Have you created READ_ONLY attribute of type wdy_boolean inside the node to which the ALV is bound..If not create it first and set the default value for this readonly as abap_true...ie X.

2. Got the contents in the internal table.

bind the table to the node..

3.Instantiate the ALV.

4. Now get teh column refrences of this ALV using the cl_salv_wd_config_table..and for columns

use the cell editor type as cl_salv_wd_uie_input_field...

loop through the column references and for all refrences create an object of type Input field and inside this class

use the method set_read_only_field_name ( 'READ_ONLY' ).

For the table settings if_salv_wd_table_settings of cl_salv_wd-config_table.. set the read only mode as abap_false..

5 create the custom button in the ALV using the cl_salv_wd_fe_button..

6 In this go for the events ON_FUCNTION and inside this method..do the coding

7 .Initially the table will be set to non editable..

In the button handler....

Get the refernece of this node to which the ALV is bound.....

lr_node = wd_context->get_child_node( 'VBAK' ).  "dynamic node name
lv_index  = lr_node->get_lead_selection_index ( ).

loop at it_table into ls_table.
if sy-tabix eq lv_index.
ls_table-read_only = abap_false.  "editable
else.
ls_table-read_only = abap_true. "non editable
endif.
modify table
endloop.

lr_node->bind_table( lt_table ).

If you have any doutbs just refer the previous thread posted on the same..

You can follow the above steps to acheive thjs..

Regards,

Lekha.

Edited by: Lekha on Dec 17, 2009 6:10 PM

Former Member
0 Kudos

Hi Lekha,

How to create READ_ONLY attribute and I am using dynamic context node creation for creating ALV.

How can I make a selected row as editable on button click?

Refer Using an ALV with Dynamic Context Nodes in Web Dynpro in saptechnical tutorials

Thanks.

Former Member
0 Kudos

HI,

When you are creating/building the IT table or dynamic fieldcatalog include this feild as one of them..

Creating dynamic node you can refer that tutorial..

For dynamic node creation -

https://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/201ddd3b-b4ce-2b10-8883-880ae8147f89&overri...

Bind a dynamic attribute to context node -

Everything is same ...Instantion of ALV and create an action for it....and all..

First try to do step by step.....you will get to know...

Edited by: Lekha on Dec 18, 2009 11:09 AM

Former Member
0 Kudos

Hi Lekha,

Thanks for your suggestion, I have created dynamic node, but it can visible with in a method (dropdown on select).I couldnu2019t access that node with dynamic attributes (attributes created using dynamic structure with one static attribute). How can retrieve that dyn node in another method?

Thanks.

Former Member
0 Kudos

When ever you create the dynamic node, store it in global variable in component controller and later use this whereevr required..

Edited by: Lekha on Dec 28, 2009 11:25 AM

Answers (2)

Answers (2)

0 Kudos

*&---------------------------------------------------------------------*

*& Report ZDEMO_PROG1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZDEMO_PROG1.
TABLES: ekko.

TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
field_style TYPE lvc_t_styl, "FOR DISABLE
END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.

*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA: it_fieldcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv WITH HEADER LINE,
wa_fieldcat TYPE lvc_s_fcat,

gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE lvc_s_layo, "slis_layout_alv,
gd_repid LIKE sy-repid.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

PERFORM data_retrieval.
PERFORM set_specific_field_attributes.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.


*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
FORM build_fieldcatalog.

wa_fieldcat-fieldname = 'EBELN'.
wa_fieldcat-scrtext_m = 'Purchase Order'.
wa_fieldcat-col_pos = 0.
wa_fieldcat-outputlen = 10.
wa_fieldcat-emphasize = 'X'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'EBELP'.
wa_fieldcat-scrtext_m = 'PO Item'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'STATU'.
wa_fieldcat-scrtext_m = 'Status'.
wa_fieldcat-col_pos = 2.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'AEDAT'.
wa_fieldcat-scrtext_m = 'Item change date'.
wa_fieldcat-col_pos = 3.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-scrtext_m = 'Material Number'.
wa_fieldcat-col_pos = 4.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MENGE'.
wa_fieldcat-scrtext_m = 'PO quantity'.
wa_fieldcat-col_pos = 5.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_m = 'Order Unit'.
wa_fieldcat-col_pos = 6.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'NETPR'.
wa_fieldcat-scrtext_m = 'Net Price'.
wa_fieldcat-edit = 'X'. "sets whole column to be editable
wa_fieldcat-col_pos = 7.
wa_fieldcat-outputlen = 15.
wa_fieldcat-datatype = 'CURR'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'PEINH'.
wa_fieldcat-scrtext_m = 'Price Unit'.
wa_fieldcat-col_pos = 8.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
ENDFORM. " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM build_layout.
* Set layout field for field attributes(i.e. input/output)
gd_layout-stylefname = 'FIELD_STYLE'.
gd_layout-zebra = 'X'.
ENDFORM. " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
FORM display_alv_report.
gd_repid = sy-repid.

* call function 'REUSE_ALV_GRID_DISPLAY'
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = gd_repid
i_callback_user_command = 'USER_COMMAND'
is_layout_lvc = gd_layout
it_fieldcat_lvc = it_fieldcat
i_save = 'X'
TABLES
t_outtab = it_ekko
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_ALV_REPORT


*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE it_ekko.

ENDFORM. " DATA_RETRIEVAL


*&---------------------------------------------------------------------*
*& Form set_specific_field_attributes
*&---------------------------------------------------------------------*
* populate FIELD_STYLE table with specific field attributes
*----------------------------------------------------------------------*
form set_specific_field_attributes .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .

* Populate style variable (FIELD_STYLE) with style properties
*
* The NETPR field/column has been set to editable in the fieldcatalog...
* The following code sets it to be disabled(display only) if 'NETPR'
* is gt than 10.
LOOP AT it_ekko INTO wa_ekko.
IF wa_ekko-netpr GT 10.


ls_stylerow-fieldname = 'EBELN'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ls_stylerow-fieldname = 'EBELP'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ls_stylerow-fieldname = 'STATU'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ls_stylerow-fieldname = 'AEDAT'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ls_stylerow-fieldname = 'MATNR'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ls_stylerow-fieldname = 'MENGE'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ls_stylerow-fieldname = 'MEINS'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ls_stylerow-fieldname = 'NETPR'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ls_stylerow-fieldname = 'PEINH'.
ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
INSERT ls_stylerow into table wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.


* ls_stylerow-style = cl_gui_alv_grid=>MC_STYLE_ENABLED.
"set field to disabled
* APPEND has now been replaced by the INSERT command as it would error
* if entries are not added in correct order
** APPEND ls_stylerow TO wa_ekko-field_style.
* INSERT ls_stylerow into table wa_ekko-field_style.
* MODIFY it_ekko FROM wa_ekko.
ENDIF.
ENDLOOP.

endform. " set_specific_field_attributes


*----------------------------------------------------------*
* FORM USER_COMMAND *
*----------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*----------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.

** Any Changes you have entered on screen will now be stored within
** the original internal table which the ALV was build from (it_ekko)

* Check function code
CASE r_ucomm.
WHEN '&DATA_SAVE'. "or what even event you want
loop at it_ekko into wa_ekko.
* process each line of table including new values
ENDLOOP.
ENDCASE.
ENDFORM.

Former Member
0 Kudos

Hi,

This is simple follow the below approach:

write the below code for maiing a lfields editable:

DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
       lr_column TYPE REF TO cl_salv_wd_column,
        lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.

lr_column_settings ?= lo_value.
lr_column = lr_column_settings->get_column( 'NETPR' ).
CREATE OBJECT lr_input_field EXPORTING value_fieldname = 'NETPR'.
lr_column->set_cell_editor( lr_input_field ).


lr_table_settings ?= lo_value.
lr_table_settings->set_read_only( abap_false ).

Hope this might help you.

Pooja