Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

Setting Sy-Subrc from Update Task

$
0
0


I have a question about how to control the value of sy-subrc that is returned from a "commit work and wait" statement used to end the LUW and trigger an update function module (for synchronous update).  Here is my code for the update function module call and the commit (note: this code is contained withing a custom inbound IDOC process code) :

 

   CALL FUNCTION 'Z_UPDATE_IMS' IN UPDATE TASK
      EXPORTING
        imt_ims = gt_ims.

    COMMIT WORK AND WAIT.
    IF sy-subrc NE 0.
      ROLLBACK WORK.
      w_status = '68'.
      w_msgv1 = 'IMS Invoice Load Failed'(t04).
    ELSE.
      w_status = '53'.
      w_msgv1 = 'IMS Invoice(s) Loaded Successfully'(t05).
    ENDIF.

 

 

Here is the relevant code from withing function "Z_UPDATE_IMS" which is set as an "Update Module - Start Immediately":

 

   IF NOT lts_insert[] IS INITIAL.
    TRY.
        INSERT zims FROM TABLE lts_insert.
      CATCH cx_sy_open_sql_db.
        MESSAGE a004(zar_ap).
    ENDTRY.
  ENDIF.

 

If the d/b insert statement above results in a duplicate record insert, the exception in caught and I issue an abort message (as I was trained in my ABAP certification) to cause a d/b rollback.  However, the code after the "commit work and wait" statement is never executed. It appears the update task and the calling program are both aborted.

 

My question, in the above situation, what is needed so that the "commit work and wait" returns a non-zero sy subrc if the database insert fails in the update task. Note: the use of synchronous update is essential because I need to know the results of the d/b update in order to set the proper IDOC status.

 

Your advice is greatly appreciated.

R/

Jim Moore


Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>