简体   繁体   中英

Insert data to specific field in internal table

I have a table let's call it "dbtab". The name of my internal table is "it_tab".

I have a number in "new_number".

I insert that number into the empty field "laufnr" in my dbtab by using:

update dbtab set laufnr = new_number where laufnr = ''.

This Works just fine, but the changes aren't in my it_tab.

How do I update my internal table from my dbtab?

Or how do I insert a value to a specific field in my internal table?

You have two options:

  1. Update your internal table when you update the database table with something like: LOOP AT it_tab ASSIGING <tab> WHERE laufnr = ''. <tab>-laufnr = new_number. ENDLOOP. LOOP AT it_tab ASSIGING <tab> WHERE laufnr = ''. <tab>-laufnr = new_number. ENDLOOP.
  2. Reread the data from the database table into your internal table after you have made the update to the database.

You could update your itab almost the same like a database table .. the only difference is, that you cannot use "update" ... use "modify" instead.

modify it_tab set laufnr = new_number where laufnr = '' .

An other option would be a simply reload of your dbtab

CLEAR it_tab.
SELECT * INTO it_tab FROM dbtab WHERE .... .

There are two different things, and they are not linked. An internal table is a representation of a dataset in a specific moment in time. A database table is the data itself up to date. You can manage to change any of them, but not both at the same time with a single instruction. I will reccomend to: - update your database - refresh the in-memory copy TIP: if you want to do it "the hard way", just create an object, and do both things in some sort of UPDATE method.

hi try this hope it helps

LOOP AT it_tab.
   it_tab-lufnr = new_number.
   MODIFY it_tab TRASNPOTING laufnr WHERE laufnr = ''.
ENDLOOP.

or with conditions

 LOOP AT it_tab where laufnr = ''.
   it_tab-lufnr = new_number.
   MODIFY it_tab TRASNPOTING laufnr WHERE laufnr = ''.
 ENDLOOP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM