cancel
Showing results for 
Search instead for 
Did you mean: 

Modifying/saving the data from ui table into db table

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

ramakrishnappa
Active Contributor
0 Kudos

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

Former Member
0 Kudos

thank you this works perfectly.

Answers (1)

Answers (1)

Gowtham
Contributor
0 Kudos

Hi Hubert,

  • Kindly avoid using select query inside Loop , it will increase the processing time hence performance problems may occur

  • Instead of this you can fetch all the details before the loop itself and inside the loop you can use read table with binary search.

  • No need to have two separate queries for update and insert , only modify query is enough to Update the entries as well creating new entries in the DB table

  • Clear statement is required inside the loop else there might be an possibility of old values coming to the next line if it is empty.

- Gowtham

Former Member
0 Kudos

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).

nishantbansal91
Active Contributor
0 Kudos

Hi Hubert,

You are correct, Please fire DATACHECK  method before getting the get_Static attribute table.

It will work.

Thanks

Nishant Bansal

Former Member
0 Kudos

Hi,

Unfortunately I cannot find that method and how to use it. Can you please give me an example?

nishantbansal91
Active Contributor
0 Kudos

Hi,

You are using table or ALV Component.


Thanks and Regards,

Nishant

Former Member
0 Kudos

a regular table.