Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Is it possible to update internal table from database table

Former Member
0 Likes
2,434

Hello All:

I know how to update database table from internal table in one shot (batch) but is the reverse possible? Can I update some fields in an internal table from a database table in one shot (without looping) because my internal table is huge? Could you please provide me any ideas how to acheive something like this? Thanks in advance and answers will be rewarded.

thanks.

Mithun

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,035

Sure, the syntax is like so.

modify ztab from table itab.

Regards,

Rich Heilman

Hello All:

I know how to update database table from internal table in one shot (batch) but is the reverse possible? Can I update some fields in an internal table from a database table in one shot (without looping) because my internal table is huge? Could you please provide me any ideas how to acheive something like this? Thanks in advance and answers will be rewarded.

thanks.

Mithun

14 REPLIES 14
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,036

Sure, the syntax is like so.

modify ztab from table itab.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
2,035

Hello my friend,

You can do it MAYBE , i think you can reverse the update doing a ROLLBACK, but only after you update....not after the program finishes..

To update some fields at once use:

UPDATE DBTABLE FROM TABLE IT_TABLE

Hope this helps!!

Gabriel

Read only

Former Member
0 Likes
2,035

Hi,

Please try this.

MODIFY <dbtab> FROM TABLE <itab>.

OR

UPDATE <dbtab> FROM TABLE <itab>.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
2,035

Sorry, if I confused you all with my question, but is it possible to do the reverse like

Update <internaltable> from <dbtable>!!

or even if I can update one internal table from another internal table without looping in one shot, that should be fine too!!

Thanks.

Mithun

Read only

0 Likes
2,035

If the two internal tables are of same type then you can just do like this.

itab1[] = itab2[].

Rgds,

Naren

Read only

0 Likes
2,035

If you want to extract records from the database into an internal table without a loop, all you need is a SELECT INTO TABLE statement. For example.

Data: it001 type table of t001.

Select * into table it001 from t001.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
2,035

Thanks everyone for the replies. I know about itab1[] = itab2[] but I want to update only some fields in itab1 with the values from itab2. WOuld itab1[] = itab2[] work in this case?

Thanks

Mithun

Read only

Former Member
0 Likes
2,035

Hi,

I don't think you can update an internal table from table without using looping/modify and select/read statement.

Regards,

Ferry Lianto

Read only

0 Likes
2,035

Mithun,

You cannot achieve that with out looping the internal table. And you can not update an internal table from a database table at one shot. All you have to do is a select * from dbtable into table itab.

Rgds,

Naren

Read only

Former Member
0 Likes
2,035

Thanks Rich. I tried select into statement but it is overriding the values previously present in my internal table. Here is my logic:

For example my internal table has 3 fields f1,f2 and f3.

I first populate my internal table itab1 from some database table db1 and populate my feilds f1 and f2. Now I need to just update feild f3 in my itab from some different database table db2 without loosing the values in f1 and f2. Is this possible?

thanks.

Mithun

Read only

0 Likes
2,035

Mithun,

The onl;y solution is read the contents from db2 into itab2.

select * from db2 into itab2.

loop at itab1.

read table itab2 with key field1 = itab1-field1.

move itab2-fld3 to itab1-fld3.

modify itab1.

endloop.

Thanks,

Naren

Read only

0 Likes
2,035

Hi Mithun da,

Select * from table dbtab appending table itab.

This code will serve the purpose

Read only

Former Member
0 Likes
2,035

Thanks everyone for the feedback. I rewarded points to everyone.

Mithun.

Read only

0 Likes
2,035

Hi Mithun,

I have an exactly same requirement as your. Were you able to find the solution for this?

Regards,

Charu