Hi Guys,
Need your help. I currently have a requirement for 2-level leave approval. I got the dump below when changing leave request status from APPROVED to SENT.
Category ABAP Programming Error
Runtime Errors UNCAUGHT_EXCEPTION
Except. CX_OS_DB_INSERT
ABAP Program CA_PT_REQ_HEADER==============CP
Application Component PT
Date and Time 06.11.2015 23:45:42
Code in Error:
Class:CA_PT_REQ_HEADER
Method: MAP_SAVE_TO_DATABASE
* * DB Inserts
INSERT ptreq_header FROM TABLE db_itb_ptreq_header
ACCEPTING DUPLICATE KEYS.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE cx_os_db_insert
EXPORTING
table = 'PTREQ_HEADER'.
ENDIF.
Below is the code I used to change the leave request status. The code is being called in a background task in leave request workflow.
CALL FUNCTION 'ENQUEUE_EPTREQ'
EXPORTING
mode_ptreq_header = 'S'
mandt = sy-mandt
request_id = iv_request_id
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc EQ 0.
ENDIF.
* Request object
CALL METHOD cl_pt_req_badi=>get_request
EXPORTING
im_req_id = iv_request_id
IMPORTING
ex_request = lr_request.
IF lr_request IS NOT INITIAL.
* Change status of request
CALL METHOD cl_pt_req_badi=>initiate_state_transition
EXPORTING
im_request = lr_request
im_event = lv_event_sent
IMPORTING
ex_new_status = lv_status.
IF lv_status EQ 'SENT'.
ev_ok = abap_true.
COMMIT WORK.
ELSE.
ev_error_msg = 'Failed to change leave request status'.
CONCATENATE ev_error_msg : lv_status INTO ev_error_msg.
ENDIF.
ENDIF.
From the code, as you can see, if the program was not able to set the status, it should return an error message. But it didn't and the dump occur. At the same time, when I checked in PT_REQ_HEADER, the request is still in status APPROVED. Funny thing is, when I tried to execute the same method, via manual test in SE24, I was able to change the leave request status without issues. This issue actually is not consistent. Happened already twice but clueless as to how/when it happens. Hope anyone can help. Thanks!