cancel
Showing results for 
Search instead for 
Did you mean: 

Updating DB from i_tab

Former Member
0 Kudos

Hello,

this is my problem:

I have a table on a web dynpro showing content of a db table: the cell editor is inputfield; when changing some value on the table in the view, the web dynpro automatically update the wd_this->elements_table and that's great, but how can I flag an entry of this table as modified so that when I save the table content on the db, I can save only row changed?

there is no problem adding a new field in context, but how can I recognize that a particular row has been changed (and its index in wd_this->elements_table) so that I can set the flag "modified" for that particular element?

Thanks

Gabriele

Accepted Solutions (0)

Answers (1)

Answers (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Gabriele,

You can proceed like either of the methods described below: (U also have other similar thread available for your reference: [Link1 |]& [Link2|] )

1) You can have the user select a table row using lead selection & then click on a table toolbar button to indicate that he has modified this row & wants to reflect it into the database. (You can get the row number using lead selection.)

2) If you are making use of ALV, the event ON_DATA_CHECK is triggered whenever a row is inserted/deleted/modified so you can inside this event get the relevant details about the modified row. If you prefer to make use of ALV you have the added advantage that the context gets automatically updated with the new data. You wouldn't have to take care of this part. Go through this [tutorial|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/bd28494a-0801-0010-45a3-fc359d82d3e8] to understand how standard ALV events can be handled. U can check this[ link|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/bd28494a-0801-0010-45a3-fc359d82d3e8] if you want to create your own event & handler method in ALV.

Regards,

Uday

First get the newly modified row and save the changes into the context:

data: lo_element type ref to if_wd_context_element,
        lo_node type ref to if_wd_context_node.

lo_node = wd_context->get_child_node( name = 'your node name here' ).

lo_element = lo_node->create_element( ).
lo_node->bind_element( new_item = lo_element set_initial_elements = abap_false ).

Get the Data from the table & modify the database:

data:
      node_sflight           type ref to if_wd_context_node,
      elem_sflight           type ref to if_wd_context_element,
      lt_elements            type WDR_CONTEXT_ELEMENT_SET,
      stru_sflight           type if_main=>element_sflight_node,
      it_flights             type if_main=>elements_sflight_node.
 
*   navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
    node_sflight_node = wd_context->get_child_node( name =
if_main=>wdctx_sflight_node ).
 
*   get element via lead selection
*    elem_sflight_node = node_sflight_node->get_element(  ).
     lt_elements = node_sflight->get_elements( ).
 
*   get all declared attributes
    loop at lt_elements into elem_sflight.
    elem_sflight->get_static_attributes(
      importing
        static_attributes = stru_sflight ).
 
    append stru_sflight to it_flights.
    endloop.
 
    modify ZSFLIGHT99 from table it_flights.
    if sy-subrc eq 0.
 
    endif.