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

How to overcome Dump during Insert Command

Former Member
0 Likes
3,260

Hi Abappers,

When I am trying to upload the text file into the Database,

I am using Insert command using internal table.

When the record exist, it gives dump saying duplicate records.

How to convert that dump into the error message?

Please Reply.

Regards,

Rahul

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,690

Hi!

Always use system field sy-subrc while using insert

Regards

Abhijeet

6 REPLIES 6
Read only

Former Member
0 Likes
1,690

hi,

use the sy-subrc = 0. .

check initial whether the record exists int he table with key fields matchinf if ...yes check

if sy-subrc = 0.

then <do nothing>

if ne 0 then insert.....

Read only

Former Member
0 Likes
1,690

Hi,

try this

IF SY-SUBRC ne 0

  YOUR ERROR MESSAGE.

ENDIF.

Regards,

Anirban

Read only

Former Member
0 Likes
1,690

Rahul,

Insert FROM TABLE itab [ACCEPTING DUPLICATE KEYS]

...

Effect

If you specify an internal table itab, several rows are created from its content for insertion in the database table. A row for insertion into the table is taken from each row of the internal table according to the same rules as for a single work area Einfügenwa. The line type of the internal table has to meet the prerequisites for use in Open-SQL statements.

If a row witht he same primary key or a same unique secondary index 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 that were actually inserted.

If a row with the same primary key or a same unique secondary index already exists in the database table for one or more of the rows to be inserted, these rows cannot be inserted. In this situation, there are three possibilities:

Use of ACCEPTING DUPLICATE KEYS

If the addition ACCEPTING DUPLICATE KEYS is specified, all rows are inserted for which this is possible. The remaining rows are rejected and sy-subrc is set to 4. The system field sy-dbcnt is set to the number of lines that are inserted.

Handling an exception

If the addition ACCEPTING DUPLICATE KEYS is not specified, a treatable exception occurs CX_SY_OPEN_SQL_DB (it always occurs since Release 6.10). Rows are inserted until the exception occurs. The number of rows that are inserted is not defined. The system fields sy-subrc and sy-dbcnt retain their previous value.

Runtime error

If the addition ACCEPTING DUPLICATE KEYS is not specified and if the exception is not handled, then a runtime error occurs (it always occurs prior to Release 6.10). This executes a database rollback that reverses all changes to the current database LUW. This applies in particular to rows that were inserted before a double entry occurred.

i would also suggest you to see SAP help by pressing F1 because some time may we miss but SAP never.

Amit.

Read only

Former Member
0 Likes
1,691

Hi!

Always use system field sy-subrc while using insert

Regards

Abhijeet

Read only

Former Member
0 Likes
1,690

You better use the MODIFY instead of INSERT.

Modify will create the record if it not there, or else it will modify the existing one.

or you want only insert then

use the addition ACCEPTING DUPLICATE KEYS

FROM TABLE itab [ACCEPTING DUPLICATE KEYS]

Read only

Former Member
0 Likes
1,690

Thanks