-1

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Kevin Mueller
  • 628
  • 3
  • 10
  • 23

4 Answers4

2

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.
  2. Reread the data from the database table into your internal table after you have made the update to the database.
Gert Beukema
  • 2,510
  • 1
  • 17
  • 18
  • 1
    Other writing of option 1 : `DATA(ls_tab) = VALUE line_type_of_it_tab( laufnr = new_number ). MODIFY it_tab FROM ls_tab TRANSPORTING laufnr WHERE laufnr = ''.` – Sandra Rossi Feb 17 '18 at 12:37
0

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 .... .
Felix
  • 78
  • 4
  • 15
0

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.

VXLozano
  • 317
  • 1
  • 7
0

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.
Les ter Bon
  • 51
  • 1
  • 1
  • 8