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: 

how to catch error after INSERT command

former_member190312
Active Participant
0 Kudos

Hi all,

I am using INSERT command to insert record into

Database table lfa1 as per below code. I want to capture

Exact error ( like duplicate record) why insert lfa1 command is unsuccessful. Please advise.

Loop at I_lfa1 into wa_lfa1.

INSERT LFA1 from wa_lfa1.

If sy-subrc ne 0.

Capture error why insertion not success.

Endif.

Endloop.

Thanks

Pabi

6 REPLIES 6

custodio_deoliveira
Active Contributor
0 Kudos

Hi Pabitra,

It's all on the online help <F1>:

sy-subrcMeaning
0When a work area was declared in source, the specified row was changed. In the declaration of an internal table in source, all declared rows were inserted, or the internal table is empty.
2When a LOB handle structure was specified with a component for writer streams, the non-LOB handle components were not yet written to the database, but instead are passed when the stream is clased, at the latest. Whether this situation occurs or not depends on the database. Refer to LOB handles.
4When a work area was specified in source, the declared row was not inserted, or, when an internal table was specified in source, not all declared rows were inserted, since a row in the database table has the same primary key or a unique secondary index.

Cheers,

Custodio

arivazhagan_sivasamy
Active Contributor
0 Kudos

This message was moderated.

former_member209120
Active Contributor
0 Kudos

This message was moderated.

Former Member
0 Kudos

Pabitra,

Try this one.

Loop at I_lfa1 into wa_lfa1.

     select single * from lfa1 into (another workarea)

                    where field = wa_lfa1-field.

     if sy-subrc is not initial.

          INSERT LFA1 from wa_lfa1.

               if sy-subrc is initial.

                    commit work.

               else.

                    rollback work.

               endif.

     else.

*     Take the value in any other workarea that this is duplicate record or record already exists.

     endif.

Endloop.

Regards

Vivek

former_member192023
Active Participant
0 Kudos

This message was moderated.

Former Member
0 Kudos

Check sy-subrc value if '0' means record inserted else error.

Hope this helps.