cancel
Showing results for 
Search instead for 
Did you mean: 

Insert / Delete / Update of the database and locking

former_member184588
Active Participant
0 Kudos

Hay everybody,

I am having my first development experiences with WD4A and to view the records is pretty simple and there are a lot of good tutorials out there.

Maybe you can help me with some questions:

I have a context (1..n). The attributes are shown in a view. The context is bound. How can I create a new record? I think for this I need to add a new record in the context. This I get. But how is the connection between the context and the database? How do you handle this connection? How do you create the new records to the database and when? So the question I have is how do you handle the inserts / deletes / updates of the records when you have just the records in the context and not yet in the database. How to sync this?

Maybe someone has a couple of time to help me out with this. I just didn't find any tutorials about this (maybe it is to simple).

Thank you,

Vanessa

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Vanessa,

Just missed out on mentioning this in my earlier posts. The locking concept in WDA is the same as the one you have in your traditional ABAP. You would have to call the ENQUEUE_<lock object name> & DEQUEUE_<lock object name> function modules just as how you would do in ABAP.

Regards,

Uday

Answers (5)

Answers (5)

former_member184588
Active Participant
0 Kudos

Hello Uday,

thanks a lot for your valueble input. I will try it out.

Thx and have a nice day, Vanessa

uday_gubbala2
Active Contributor
0 Kudos

Hi Vanessa,

Just to give you a complete working code..... I guess that you want to first display the data in your view & then allow the user to be able to modify & save it on to the database from there. Here in my example I have a node by name SFLIGHT_NODE and under this I have the desired attributes from SFLIGHT. Am displaying these in an editable table & the user would press up on a push button after making the necessary changes to the tables data. I would then need to obtain the tables information & save on to the database.

Regards,

Uday

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 = 'SFLIGHT_NODE'  ).
 
   lt_elements = node_sflight->get_elements( ).
 
"   Get all the rows from the table for saving on to the database
    loop at lt_elements into elem_sflight.
      elem_sflight->get_static_attributes( importing static_attributes = stru_sflight ).
      append stru_sflight to it_flights.
    endloop.

" Finally save the entries on to the database 
    modify ZSFLIGHT99 from table it_flights.
    if sy-subrc eq 0.
endif.

However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for the same. Try go through Thomas Jung's comments in [here|;.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Hi Vanessa,

Just for your understanding am giving a sample code snippet which you can use to read the contents of your Table UI element & save the data on to your database. Suppose you have a button up on pressing which you want to read the data from your screens table & save on to the database then you can proceed as shown below:

1) Obtain the reference of your context node.

2) Fetch all the data present in your table into an internal table using get_static_attributes_table method of if_wd_context_node

3) Use your normal ABAP logic to update the database table with the data from your internal table

Regards,

Uday

DATA:
  lr_context TYPE REF TO if_wd_context_node,
  lt_table     TYPE <THE TABLE TYPE>.
 
lr_context = wd_context->get_child_node( name = <NODE_NAME> ).
 
lr_context->get_static_attributes_table( IMPORTING table = lt_table ).
 
MODIFY <TRANSPARENT TABLE> FROM TABLE lt_table.

uday_gubbala2
Active Contributor
0 Kudos

Hi Vanessa,

You will have to create a FM or a class method which will have the code for updating the database (normal ABAP DB update code), in your WDP appliction, read the context attribute (since you are new to WDA you can use the wizard to generate the code for reading the context attribute for you). You will be reading the context attribute into a normal structure/variable/table depending on what type of attribute it is, then call your FM or class method to actually update the data into the DB.

Hope this helps,

Uday

Former Member
0 Kudos

Hello,

Search fourm for your issue you will find surely good results....

you need to write the BAPI ( for DB functions ) and then call your BAPI via controller ( Service Calls )....

Regards,