Hi,
How were you able to solve it? I am having problems also. I am not sure if it is because of the delay in changing form status SENT to APPROVED that is why it is not able to change status from APPROVED to SENT. Please help. Happened twice already, didn't happen for other users. Thanks
Here is my code:
METHOD change_leavereq_status.
DATA: lr_request TYPE REF TO if_pt_req_request,
lv_event_sent TYPE tim_req_xfer_event VALUE cl_pt_req_const=>c_reqtrans_send,
lv_status TYPE tim_req_status,
lv_enqueue TYPE boole_d.
*>>> Enqueue the request
* Perform locking of request 10 times just in case first enqueue doesnt work
DO 10 TIMES.
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.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
lv_enqueue = abap_true.
EXIT.
ELSE.
WAIT UP TO 60 SECONDS.
ENDIF.
ENDDO.
*>>> Enqueue the request
IF lv_enqueue EQ abap_true.
* 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 AND WAIT.
ELSE.
ev_error_msg = 'Failed to change leave request status'.
CONCATENATE ev_error_msg : lv_status INTO ev_error_msg.
ENDIF.
ELSE.
ev_error_msg = 'Failed to change leave request status'.
IF sy-msgid IS NOT INITIAL.
CONCATENATE sy-msgid sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
INTO ev_error_msg SEPARATED BY space.
ENDIF.
ENDIF.
* Dequeue
CALL FUNCTION 'DEQUEUE_EPTREQ'
EXPORTING
mode_ptreq_header = 'S'
request_id = iv_request_id.
ELSE.
ev_error_msg = 'Failed to lock leave request'.
IF sy-msgid IS NOT INITIAL.
CONCATENATE sy-msgid sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
INTO ev_error_msg SEPARATED BY space.
ENDIF.
ENDIF.
ENDMETHOD.