‎2008 Apr 28 1:43 PM
Hi,
I am trying to insert values in table
loop at it_header.
INSERT YTAB from table it_header accepting duplicate keys.
endloop.
But, the records are not getting inserted.
Pl guide.
Regards,
Netra
‎2008 Apr 28 1:53 PM
Additionally, you're code will try to insert the table multiple times
Instead of this
loop at it_header.
INSERT YTAB from table it_header accepting duplicate keys.
endloop.
you only need this
INSERT YTAB from table it_header accepting duplicate keys.
‎2008 Apr 28 1:46 PM
hi,
If, for one or more of the rows to be inserted, a row with the same primary key or the same unique secondary key already exists and the ACCEPTING DUPLICATE KEYS addition is specified, the rows are not inserted.
regards,
madhu
‎2008 Apr 28 1:48 PM
hi check this...
When you specify an internal table itab, several rows are created from its contents for insertion into the database table. A row for insertion into the database table is take from each row of the internal table, using the same rules as for an individual work area wa. The row type of the internal table must meet the prerequisites for use in Open SQL statements.
If a row with the same primary key or the same unique secondary key does not already exist in the database table for any of the rows to be inserted, all rows are inserted and sy-subrc is set to 0. If the internal table is empty, sy-subrc is also set to 0. The system field sy-dbcnt is always set to the number of rows actually inserted.
If, for one or more of the rows to be inserted, a row with the same primary key or the same unique secondary key already exists and the ACCEPTING DUPLICATE KEYS addition is specified, the rows are not inserted and sy-subrc is set to 4. If, in this case, the addition ACCEPTING DUPLICATE KEYS is not specified, no rows are inserted. Prior to Release 6.10, this raises an exception that cannot be handled; as of Release 6.10, this raises the exception that can be handled CX_SY_OPEN_SQL_DB.
regards,
venkat
‎2008 Apr 28 1:53 PM
Additionally, you're code will try to insert the table multiple times
Instead of this
loop at it_header.
INSERT YTAB from table it_header accepting duplicate keys.
endloop.
you only need this
INSERT YTAB from table it_header accepting duplicate keys.
‎2008 Apr 28 1:56 PM
If you are inserting the it_header (internal table) records to your YTAB (DB table)....then follow the code...
INSERT YTAB from table it_header accepting duplicate keys.
No need for Loop...endloop.
-
If you are inserting the it_header (internal table) records to your YTAB (internal table)....then follow the code...
INSERT lines of it_header INTO TABLE ytab.
Please refer this link:
http://help.sap.com/saphelp_nw70/helpdata/EN/fc/eb3a6d358411d1829f0000e829fbfe/frameset.htm
‎2008 Apr 28 1:56 PM
Hi,
Insert YTAB from table it_header ACCEPTING DUPLICATE KEYS.
Reward if helpful.
‎2008 Apr 28 1:58 PM
Hi
To insert several lines into a database table, use the following:
INSERT <target> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS].
This writes all lines of the internal table <itab> to the database table in one single operation. The
same rules apply to the line type of <itab> as to the work area <wa> described above.
If the system is able to insert all of the lines from the internal table, SY-SUBRC is set to 0. If one
or more lines cannot be inserted because the database already contains a line with the same
primary key, a runtime error occurs. You can prevent the runtime error occurring by using the
addition ACCEPTING DUPLICATE KEYS. In this case, the lines that would otherwise cause
runtime errors are discarded, and SY-SUBRC is set to 4.
The system field SY-DBCNT contains the number of lines inserted into the database table,
regardless of the value in SY-SUBRC.
Whenever you want to insert more than one line into a database table, it is more efficient to work
with an internal table than to insert the lines one by one.
Examples
Adding single lines
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.
This program inserts a single line into the database table SPFLI using each of the
three possible variants of the INSERT statement.
Instead of
INSERT SPFLI
in the last line, you could also use the longer forms
INSERT SPFLI FROM SPFLI
or
INSERT INTO SPFLI VALUES SPFLI
The name SPFLI is therefore not unique.
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.
...
INSERT SPFLI FROM TABLE ITAB ACCEPTING DUPLICATE KEYS.
IF SY-SUBRC = 0.
...
ELSEIF SY-SUBRC = 4.
...
ENDIF.
This example fills a hashed table ITAB and inserts its contents into the database
table SPFLI. The program examines the contents of SY-SUBRC to see if the
operation was successful.