on 04-08-2015 10:04 AM
Hello.
What I am trying to do is to grab everything that's in the ui table into an internal table, then loop at it checking for each record in the db. If the record exists, I would possibly like to modify it, if not - I want to add new record in the db.
Can anybody explain what I am doing wrong please?
* create local data variable to access context information
Data: context_node type ref to if_wd_context_node.
TYPES: BEGIN OF ty_zdest,
mandtid type zdest-mandtid,
zclid TYPE zdest-zclid,
zsid TYPE zdest-zsid,
rfcdest TYPE zdest-rfcdest,
active TYPE zdest-active,
END OF ty_zdest.
DATA: it_zdest TYPE STANDARD TABLE OF ty_zdest,
it_insert TYPE STANDARD TABLE OF ty_zdest,
wa_zdest TYPE ty_zdest,
wa_use TYPE ty_zdest,
wa_test TYPE ty_zdest.
DATA: index type i.
context_node = wd_context->get_child_node( name = 'TEST_NODE').
refresh: it_zdest.
* Get data contained within ABAP web dynpro table
context_node->get_static_attributes_table(
importing
table = it_zdest ).
LOOP AT it_zdest INTO wa_test.
SELECT SINGLE zclid zsid rfcdest active FROM zdest INTO wa_use WHERE zclid = wa_test-zclid AND
zsid = wa_test-zsid.
IF wa_use IS INITIAL.
wa_use-zclid = wa_test-ZCLID.
wa_use-zsid = wa_test-ZSID.
wa_use-rfcdest = wa_test-RFCDEST.
wa_use-active = wa_test-ACTIVE.
APPEND wa_use TO it_insert.
MODIFY zdest FROM TABLE it_insert.
CLEAR wa_use.
ELSE.
UPDATE zdest SET
zclid = wa_use-zclid
zsid = wa_use-zsid
rfcdest = wa_use-rfcdest
active = wa_use-active
WHERE
zclid = wa_test-zclid AND
zsid = wa_test-zsid.
ENDIF.
ENDLOOP.
The code above is contained within on click action of a button.
Any help would be appreciated.
Regards,
Hubert Legowski
Hi,
I suggest you to use MODIFY statement as below
data: lt_zdest type standard table ty_zdest,
lt_use type standard table zdest,
wa_use like line of lt_use,
wa_zdest like line of lt_zdest.
if lt_zdest is not the same as data base table zdest, then
loop at lt_zdest into wa_zdest.
" move data from wa_zdest to wa_use.
" append wa_use to lt_use.
endloop.
" modify / insert new records into table ZDEST
modify ZDEST from table lt_use.
Hope this helps you.
Regards,
Rama
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hubert,
- Gowtham
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please and thank you make corrections on what you think would work? This code does not work, i.e doesn't make any changes to db table neither does it add rows. In addition I'll tell you that I am having a ui table, that has editors defaulted to input fields, and I want to grab the values after I change the values in ui table, i.e. modify a cell, then grab them values and make changes to db table. Any idea how can I get this working? From my understanding get static attributes method retrieves what's in the node already, not the modified values (please correct me if I am wrong).
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
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.