Skip to Content
author's profile photo Former Member
Former Member

Handle INSERT exception

i need to handle exception for below code. PLS HELP ME.

when i trying for error records it ll got to dump

IF itab_zdfkkwoh IS NOT INITIAL.

INSERT zdfkkwoh FROM TABLE itab_zdfkkwoh.

IF SY-SUBRC = 0.

DESCRIBE TABLE itab_zdfkkwoh LINES countb.

ELSE.

ENDIF.

*???????

ENDIF.

Edited by: Alvaro Tejada Galindo on Feb 21, 2008 4:33 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 21, 2008 at 10:07 AM

    Hi,

    you can make to popup a message relavently.

    IF <variable> is NOT INITIAL.
        INSERT <table> FROM TABLE <itab>.
        IF sy-subrc = 0.    "data inserted successfully
           DESCRIBE TABLE...
        ELSE.               "data not inserted
           MESSAGE 'table insertion error' TYPE 'I'.
        ENDIF.
    ENDIF.
    

    <REMOVED BY MODERATOR>

    teja

    Edited by: Alvaro Tejada Galindo on Feb 21, 2008 4:33 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 21, 2008 at 11:04 AM

    Hi,

    1. If you wish to handle the exception as an information message,then it will show as a popup window.On closing this window,you can proceed with the program as in a normal flow.To achieve this,you can write the following piece of code :

    IF itab_zdfkkwoh IS NOT INITIAL.

    INSERT zdfkkwoh FROM TABLE itab_zdfkkwoh.

    IF sy-subrc = 0. " Data inserted successfully

    DESCRIBE TABLE itab_zdfkkwoh LINES countb.

    ELSE. " Data insertion failed

    message i001(00) with 'Row(s) with same primary key already exists'.

    ENDIF.

    ELSE. " Table is initial

    message i001(00) with 'Table contains no data'.

    ENDIF.

    2. However,if you want to raise the exception as an error message,then it will show at the bottom of the screen as a highlighted red field.If you don't rectify the error,the program won't proceed.To achieve this,just make the modification in the message text as :

    -


    message e001(00) with 'Row(s) with same primary key already exists'.

    -


    3. If you are writing this piece of code inside a function module,then you can raise exception as :

    IF itab_zdfkkwoh IS NOT INITIAL.

    INSERT zdfkkwoh FROM TABLE itab_zdfkkwoh.

    IF sy-subrc = 0. " Data inserted successfully

    DESCRIBE TABLE itab_zdfkkwoh LINES countb.

    ELSE. " Data insertion failed

    RAISE insertion_error.

    ENDIF.

    ELSE. " Table is initial

    RAISE no_data.

    ENDIF.

    Here,'insertion_error' & 'no_data' are 2 exceptions that you need to define in the exceptions tab of funtion module definition.They will have sy-subrc values as 1 & 2(if no other exception is defined).

    You can handle this exceptions when you call the function module.At the end of function module code,write as :

    case sy-subrc.

    when 0.

    • Proceed further

    when 1.

    • insertion_error is raised.Handle the error.*

    message i001(00) with 'Row(s) with same primary key already exists'.

    when 2.

    • no_data raised.*

    message i001(00) with 'Table contains no data'.

    endcase.

    Hope this helps.

    Regards,

    Kaveri.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.