on 06-08-2009 10:01 AM
Hi there,
i reuse SALV in my ABAP-Webdynpro to edit data. In my view the user is allowed to insert, edit and delete lines of the table. So far it is working fine.
I also use the on_data_check-Event to find out which rows are edited, inserted or deleted.
Does anyone have a code example for writing those changes to a database?
I think this is not easy to manage especially when you allow all sorts of changes...
David Wallner
Edited by: David Wallner on Jun 8, 2009 11:02 AM
Hi,
Using the parameter R_PARAM you can easily find the indexes of inserted/deleted/changed rows and even the specific change sothat you don't need to verify the complete context table data to find changes. Here is the code sample below.
data:
ls_mod_cell type salv_wd_s_table_mod_cell,
ls_row type salv_wd_s_table_row.
field-symbols:
<l_value> type any.
"if no errors.
if r_param->t_error_cells is initial.
"Index & contents of changed cells as below.
loop at r_param->t_modified_cells into ls_mod_cell.
clear ls_mod.
"collect all the changes into local variable and perform DB operation later
ls_mod-index = ls_mod_cell-index.
ls_mod-attribute = ls_mod_cell-attribute.
assign ls_mod_cell-r_value->* to <l_value>.
ls_mod-value = <l_value>.
append ls_mod to lt_mod.
endloop.
" write changed data to db using table lt_mod
"similarly get the indexes of inserted rows
loop at r_param->t_inserted_rows into ls_row.
clear ls_mod.
ls_mod-index = ls_row-index.
append ls_mod to lt_mod.
"using these indexes collect the actual records from context and write to db
endloop.
"same way you can also get indexes of deleted rows from r_param->t_deleted_rows
endif.
Regards,
Manne.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check this tutorial [https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3133474a-0801-0010-d692-81827814a5a1]
Regards,
Radhika.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
When you make any kind of changes (insert/delete/change) all these changes get reflected in your context node. So when you want to save these entries into database, just read your context nodes contents by using get_static_attributes_table. Then use this internal table to modify your database table. Refer this code snippet below which is based on Suman's reply in this [thread|;:
Regards,
Uday
METHOD ondatacheck .
DATA: node_node_flighttab TYPE REF TO if_wd_context_node,
elem_node_flighttab TYPE REF TO if_wd_context_element,
lt_sflight TYPE if_resultview=>elements_node_flighttab.
* save data only if no error has occured
CHECK r_param->t_error_cells IS INITIAL.
node_node_flighttab = wd_context->get_child_node( name = `NODE_FLIGHTTAB` ).
* get data from context node <NODE_FLIGHTTAB>
node_node_flighttab->get_static_attributes_table(
IMPORTING table = lt_sflight ).
*validate value
select carrid from sflght into v_sflight where carrid = r_param-value.
if sy-subrc ne 0.
* raise error message
else.
*update to the data base.
modify table zsflight from lt_sflight transporting carrid.
endif.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.