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 db table modification failure

former_member342346
Participant
11,535

Hi,

I searched the forum for a way to catch the reason for failure of a DB table modification but didn't find any clue for a solution.

When I use the modify statement I only get sy-subrc as 0 or 4 as an indication to the modification.


How can I understand the reason for failure when sy-subrc = 4?


Thanks,

Hagit

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,939

Hi Hagit Peretz ,

As per my understanding by reading this thread come to know that you need to get the real time message during database updation. Try code as shown in below.

  DATA :lx_root           TYPE REF TO cx_root,

        err_msg           TYPE char200.

LOOP AT MY_SRC.

     TRY.

        MODIFY MY_DB_TAB FROM MY_SRC.

           CATCH cx_root INTO lx_root.

        err_msg = lx_root->get_text( ).

    ENDTRY.

ENDLOOP.

" It's in loop so that for each record you will get the status. Populate err_msg status in final table.

Regards,

PrAvIn

14 REPLIES 14
Read only

former_member196331
Active Contributor
0 Likes
5,939

Are you modifying From from work area or From the table.

Where is modify statement.

Read only

0 Likes
5,939

The modify is within an ABAP program not from work area.

Read only

0 Likes
5,939

Sorry Not understood.

You said.

When I use the modify statement I only get sy-subrc as 0 or 4 as an indication to the modification.


May i know modify Statement from the program.


Read only

0 Likes
5,939

my db table name to be updated is MY_DB_TAB.

this table is modified by source structure MY_SRC.

The update is as follows:

my_bd_tab-f1= my_src-f1.

my_db_tab-f2= my_scr-f2.

...

MODIFY my_db_tab.

Read only

0 Likes
5,939

Can you capture in debugging while sy-subrc eq 4.

if you say yes.

Take Structure value try to insert the values in the Database manually you can capture the what is the reason behind it.

you have to See Key fields also.

if key field values already exist in the table it will modify the data from structure other wise

it will insert.

Hope you understood.

Try to modify manually from the structure values, you will get the reason.

Read only

0 Likes
5,939

I want to use the reason in my code in order to send an email with the reason for the update failure.

how do I do this in code?

Read only

0 Likes
5,939

Hi,

you cannot pass values direct to table structure.


my_bd_tab-f1= my_src-f1.

my_db_tab-f2= my_scr-f2.

write your modify statement like this...

MODIFY MY_DB_TAB FROM MY_SRC.

where MY_SRC is of type MY_DB_TAB.

thank you..

Read only

0 Likes
5,939

Thank you Chintu, but the modification is not my problem, it's working good.

I want to catch the the failure before getting a dump.

Read only

0 Likes
5,939

Hi,

put a check like this..

MODIFY MY_DB_TAB FROM MY_SRC.


if sy-subrc is not initial.


write:/ 'Modification failed..error captured'.


endif.


thanks!!

Read only

Former Member
0 Likes
5,939

Hi

It should be very rare event, because the MODIFY statament can be both INSERT or UPDATE (it depends on the record to be updated),

anyway frim the help:

0All lines were inserted or changed.
4At least one line could not be processed as there is already a line with the same unique name secondary index in the database table.

so it could be a conflict due to the secondary index

Max

Read only

0 Likes
5,939

Hi Max,

In case there is a wrong value (for example: a string instead of decimal) there is a short dump with Except.  CX_SY_CONVERSION_NO_NUMBER.

I want to be able to catch this exception before the dump (using TRY...ENDTRY)

Thanks,

Hagit

Read only

0 Likes
5,939

Hi

So have you a dump? I've understood you need to know why the MODIFY returns a SY-SUBRC = 4

If you want to prevent that dump, you need to use TRY/ENDRTY


DATA: MY_ERROR  TYPE REF TO CX_SY_CONVERSION_NO_NUMBER.

DATA: MSG_ERROR TYPE STRING.

TRY.

  

   <COMMAND.....................................>.

  

   CATCH CX_SY_CONVERSION_NO_NUMBER INTO MY_ERROR.

     MSG_ERROR = MY_ERROR->GET_TEXT( ).

ENDTRY.

IF MSG_ERROR IS NOT INITIAL.

   .................do something................................

   MESSAGE I208(00) WITH MSG_ERROR.

ENDIF

Max

Read only

Former Member
0 Likes
5,940

Hi Hagit Peretz ,

As per my understanding by reading this thread come to know that you need to get the real time message during database updation. Try code as shown in below.

  DATA :lx_root           TYPE REF TO cx_root,

        err_msg           TYPE char200.

LOOP AT MY_SRC.

     TRY.

        MODIFY MY_DB_TAB FROM MY_SRC.

           CATCH cx_root INTO lx_root.

        err_msg = lx_root->get_text( ).

    ENDTRY.

ENDLOOP.

" It's in loop so that for each record you will get the status. Populate err_msg status in final table.

Regards,

PrAvIn

Read only

0 Likes
5,939

Thank you all for your kind help