10-15-2008 5:04 AM
hi experts,
Can anyone please assist me in inserting records to a database table from an Internal Table
whose structures are identical.
Thanks in Advance,
Sudhaa............
10-15-2008 5:05 AM
Hi,
You can use MODIFY,INSERT statements. Goto tcode ABAPDOCU and enter the above keywords to get the exact syntax.
For example:
Modify <database table> from table <itab>.
Thanks & Regards,
Navneeth K.
10-15-2008 5:07 AM
Hi,
You can find the syntax to do so in F1 help provided by SAP, just type update in ABAP editer and press F1 you will get the required info in detail.
10-15-2008 5:08 AM
INSERT dbtab FROM TABLE itab.
UPDATE dbtab FROM TABLE itab.
MODIFY dbtab FROM TABLE itab.
10-15-2008 5:10 AM
modify <DBtable> from <int.tab>
if you use update
you need to provide the primary key also
10-15-2008 5:10 AM
Hi Sudha,
Below is the sample code.
DATA scarr_wa TYPE scarr.
scarr_wa-carrid = 'FF'.
scarr_wa-carrname = 'ABC Ltd'.
scarr_wa-currcode = 'EUR'.
scarr_wa-url = 'http://www.abcltd.com'..
INSERT INTO scarr VALUES scarr_wa.
Thanks,
Chidanand
10-15-2008 5:14 AM
10-15-2008 5:15 AM
Hello,
Better you use MODIFY statement instead of going INSERT or UPDATE.
If u use Modify if the records exists it will modify the row.
MODIFY i_tab INDEX idx FROM i_wa
TRANSPORTING currcode.
MODIFY sflight_tab FROM sflight_wa
TRANSPORTING planetype WHERE planetype = p_plane1.
If u want to modify complete row dont use Transporting key word.
10-15-2008 5:16 AM
Hi sudha,
It is not recommended to update a sap database table
Even if u want u can use something like this----
select *
from dbtab
into table itab.
loop at itab.
itab-field = <new_value>.
modify itab index sy-tabix.
endloop.
UPDATE dbtab FROM TABLE itab.
use update command.
regards
Prashant.
10-15-2008 5:20 AM
Hi,
use this syntax
MODIFY <ztable> FROM TABLE <it_itab>.
Regards
Bala Krishna
10-15-2008 5:31 AM
HI ,
You can use insert and modify statements to update the database table .
Ex:
Modify <dbtbname> from <itab>.
insert into <dbtabname > values <wa_itab> (where wa_itab have the values which is to be inserted)
Ex:
data: wa_vbak type vbak.
wa_vbak-vkorg = '11'
Now you can do like this:
insert into vbak values wa_vbak '' here you have to take care about primay key ''
or you can use :
insert <dbtabname> from <tbname>
Hope this will help you .
Bye
10-15-2008 5:44 AM
Hi Sudha,
Here are some example of update and insert:
UPDATE SFLIGHT SET PLANETYPE = 'A310'
PRICE = PRICE - '100.00'
WHERE CARRID = 'LH' AND CONNID = '0402'.
This example overwrites the contents of the PLANETYPE column with A310 and decreases the value of the PRICE column by 100 for each entry in SFLIGHT where CARRID contains u2018LHu2019 and CONNID contains u2018402u2019.
TABLES SPFLI.
DATA WA TYPE SPFLI.
MOVE 'AA' TO WA-CARRID.
MOVE '0064' TO WA-CONNID.
MOVE 'WASHINGTON' TO WA-CITYFROM.
...
UPDATE SPFLI FROM WA.
MOVE 'LH' TO SPFLI-CARRID.
MOVE '0017' TO SPFLI-CONNID.
MOVE 'BERLIN' TO SPFLI-CITYFROM.
...
UPDATE SPFLI.
CARRID and CONNID are the primary key fields of table SPFLI. All fields of those lines where the primary key fields are "AA" and "0064", or "LH" and "0017", are replaced by the values in the corresponding fields of the work area WA or the table work area SPFLI.
DATA: ITAB TYPE HASHED TABLE OF SPFLI
WITH UNIQUE KEY CARRID CONNID,
WA LIKE LINE OF ITAB.
WA-CARRID = 'UA'. WA-CONNID = '0011'. WA-CITYFROM = ...
INSERT WA INTO TABLE ITAB.
WA-CARRID = 'LH'. WA-CONNID = '1245'. WA-CITYFROM = ...
INSERT WA INTO TABLE ITAB.
WA-CARRID = 'AA'. WA-CONNID = '4574'. WA-CITYFROM = ...
INSERT WA INTO TABLE ITAB.
...
UPDATE SPFLI FROM TABLE ITAB.
This example fills a hashed table ITAB and then overwrites the lines in SPFLI that have the same primary key (CARRID and CONNID) as a line in the internal table.
Insert statement :
TABLES SPFLI.
DATA WA TYPE SPFLI.
WA-CARRID = 'LH'.
WA-CITYFROM = 'WASHINGTON'.
...
INSERT INTO SPFLI VALUES WA.
WA-CARRID = 'UA'.
WA-CITYFROM = 'LONDON'.
...
INSERT SPFLI FROM WA.
SPFLI-CARRID = 'LH'.
SPFLI-CITYFROM = 'BERLIN'.
...
INSERT SPFLI.
If the database table does not already contain a line with the same primary key as specified in the work area, the operation is completed successfully and SY-SUBRC is set to 0. Otherwise, the line is not inserted, and SY-SUBRC is set to 4.
Regards,
Premraj kaushik
10-15-2008 6:09 AM
11-29-2008 7:31 AM
Hi Prem,
For such type of scenario,I have a doubt regarding modifying a database table.
I would like to add the line items from an internal table to a data base table with the content of the primary key as same.
For example:
If I specify a correspondence number in table ZU1CD_CORRPOS,I would like to have 3 or multi line items for that correspondence number.
In such a case,I should insert 3or many rows from internal table with the value of the primary key as the same but I should insert multi line items.
I have tried issuing Modiy Insert zu1cd_corrpos from table it_corr accepting duplicate keys..
But now I could see the first entry of the internal table and the rest of the entries are not inserted into DB.
Please help me.
Thanks,
Johny
05-08-2014 9:56 AM
07-09-2019 7:37 AM
Always Use Lock Objects While Updating the records of a table.
That will Consider as best Practice.
Regards,
Satish.
07-09-2019 3:47 PM
This question is from 2008. Please take note of the date before chiming in with an answer and consider if an answer adds any value at this point.
07-15-2019 8:11 AM
Hi Jelena,
Yes i saw the date, as I am a fresher and searching for the same doubt before 2 weeks ,and got the solution as mentioned above.
Thinking it may useful for freshers like me searching for the same question I answered 😊.
Regards,
Satish.
10-10-2019 12:03 PM
10-10-2019 8:35 PM
This question is from 2008! And it's not even the right answer, the question is about INSERT.
Such questions can be easily answered by reading ABAP Help, which has been improved tremendously since 2008.
10-10-2019 9:09 PM
Not sure why people keep posting answers to this RTFM question every 5 years. Please stop doing that. If anyone still has a similar question - go to ABAPDOCU transaction and read article about INSERT command. No access to the system? Google "ABAP keyword documentation". The answer is literally in the command syntax.
Still have a question? Post your own.
Yearning to share knowledge? Post a blog.
Please no more necromancing.
10-10-2019 9:20 PM
Jelena Perfiljeva I don't understand why the SCN team has "opened the archive". That was nice a few months ago when "archive.sap.com" was closed to answers and comments, and "answers.sap.com" used to contain only new questions.