Application Development 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: 

Catch db table modification failure

former_member342346
Participant

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

Former Member
0 Kudos

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

former_member196331
Active Contributor
0 Kudos

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

Where is modify statement.

0 Kudos

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

0 Kudos

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.


0 Kudos

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.

0 Kudos

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.

0 Kudos

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?

0 Kudos

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..

0 Kudos

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.

0 Kudos

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!!

Former Member
0 Kudos

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

0 Kudos

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

0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

Thank you all for your kind help