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

Catch

Former Member
0 Likes
1,696

Hi

i would like to catch system exception cx_sy_open_sql_db INTO error_obj_ref. can i couut the error records using this?

DATA : error_obj_ref TYPE REF TO cx_root.

Thanks

Anbu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,415

Hi,

Try like this....

The exception occurs 4 times and is displayed...

DATA:  it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE,
       oref   TYPE REF TO cx_root,
       text   TYPE string,
       count.

SELECT *
FROM   mara
UP TO  5 ROWS
INTO   TABLE it_mara.

perform insert.
perform insert.
perform insert.
perform insert.
write   count.

form insert .
TRY.
insert mara from table it_mara.
  CATCH cx_sy_open_sql_db INTO oref.
    text = oref->get_text( ).
    if text is not initial.
      count = count + 1.
      endif.
ENDTRY.
endform.                    " insert

Cheers,

jose.

Edited by: jose on Feb 22, 2008 5:19 AM

9 REPLIES 9
Read only

Former Member
0 Likes
1,416

Hi,

Try like this....

The exception occurs 4 times and is displayed...

DATA:  it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE,
       oref   TYPE REF TO cx_root,
       text   TYPE string,
       count.

SELECT *
FROM   mara
UP TO  5 ROWS
INTO   TABLE it_mara.

perform insert.
perform insert.
perform insert.
perform insert.
write   count.

form insert .
TRY.
insert mara from table it_mara.
  CATCH cx_sy_open_sql_db INTO oref.
    text = oref->get_text( ).
    if text is not initial.
      count = count + 1.
      endif.
ENDTRY.
endform.                    " insert

Cheers,

jose.

Edited by: jose on Feb 22, 2008 5:19 AM

Read only

0 Likes
1,415

Hi Jose,

For example i am trying to insert 3 records to Data base table.

These records are already there. when i execute its counting only one record. becoz it's not in loop. how to fix this?

Thanks

Anbu

Read only

0 Likes
1,415

select all the data related into the internal table and check if there is an entry or not... if not then only insert the record..

loop at one table and read on another will server this purpose.


loop at itab into wa_itab.

 read table itab_next into wa_next where f1 = wa_itab-f1.
     if sy-subrc eq 0.
delete itab index sy-index.
     endif .

endloop.

Read only

0 Likes
1,415

Hi,

if ur inserting like below

insert DBTAB from WA.

it wont dump even if record exists already.....but sy-subrc ll 4..u can use dat..

if ur inserting like dis

insert DBTAB from table ITAB .

it ll dump even if one record exists already.....so follow dat example..

Cheers,

jose.

Read only

0 Likes
1,415

hi jose

I tried the above code. but its not counting properly

Read only

0 Likes
1,415

updating a Ztable will depend on the key field of the table, you cannot have redundant data in key fields.. keep that in mind...

Read only

0 Likes
1,415

Hi,

U need the no of records that already exists in table right.......

if its so

DATA:  it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE,
       count.

SELECT *
FROM   mara
UP TO  5 ROWS
INTO   TABLE it_mara.

LOOP AT it_mara.
  INSERT mara FROM it_mara.
  IF sy-subrc IS NOT INITIAL.
    count = count + 1.
  ENDIF.
ENDLOOP.

WRITE   count.

Read only

0 Likes
1,415

Hi

i dont want to insert table in loop. b'coz my internal table having 2 milloin records. if it is in loop it ll affect the performance right?

Read only

0 Likes
1,415

Hi,

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.

So i Don think its possible without loop..........

Cheers,

jose.