11-11-2013 12:28 AM
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
11-11-2013 2:43 AM
Hi Pabitra,
It's all on the online help <F1>:
sy-subrc | Meaning |
0 | When 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. |
2 | When 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. |
4 | When 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
11-11-2013 2:58 AM
11-11-2013 3:45 AM
11-11-2013 5:19 AM
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
11-11-2013 5:32 AM
11-11-2013 10:43 AM
Check sy-subrc value if '0' means record inserted else error.
Hope this helps.