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 Catch SQL Exceptions in 4.6C ?

former_member207873
Participant
0 Likes
2,072

Hi Experts,

I wanted to catch one SQL exception "SAPSQL_ARRAY_INSERT_DUPREC". I am in 4.6C system and there is no 'try' statement there. I read from documentation that in 4.6c we can catch exceptions using statement. . CATCH SYSTEM-EXCEPTIONS . But I am not finding the error id for SQL errors in 4.6.

B.R.

1 ACCEPTED SOLUTION
Read only

FredericGirod
Active Contributor
0 Likes
1,600

Hi,

isn't there an option in the INSERT statement to specify  ACCEPTING DUPLICATE KEYS

regards

Fred

Hi Experts,

I wanted to catch one SQL exception "SAPSQL_ARRAY_INSERT_DUPREC". I am in 4.6C system and there is no 'try' statement there. I read from documentation that in 4.6c we can catch exceptions using statement. . CATCH SYSTEM-EXCEPTIONS . But I am not finding the error id for SQL errors in 4.6.

B.R.

6 REPLIES 6
Read only

FredericGirod
Active Contributor
0 Likes
1,601

Hi,

isn't there an option in the INSERT statement to specify  ACCEPTING DUPLICATE KEYS

regards

Fred

Read only

0 Likes
1,600

I do not want duplicate keys. I need to raise an exception and message in case of duplicate record.

B.R.

Read only

matt
Active Contributor
0 Likes
1,600

ACCEPTING DUPLICATE KEYS does not insert duplicate records and does tell you if there were duplicates. Please read the ABAP help.

Read only

0 Likes
1,600

SELECT before inserting. If sy-subrc <> 0, INSERT; otherwise exception.

Rob

Read only

0 Likes
1,600

Yes that's the same solution I thought . I think there is no other standard exception help in 4.6.

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
1,600

What does DUMP says? I am afraid that this is not catchable exception.

I guess it says this is not it? 🙂


Error analysis

If you use an ABAP/4 Open SQL array insert to insert a record in

the database and that record already exists with the same key,

this results in a termination.

(With an ABAP/4 Open SQL single record insert in the same error

situation, processing does not terminate, but SY-SUBRC is set to 4.)

How to correct the error

Use an ABAP/4 Open SQL array insert only if you are sure that none of

the records passed already exists in the database.

(in later ABAP/SAP versions it can be catched via CX_SY_OPEN_SQL_DB exception class)

-- Tomas --