‎2014 Mar 03 3:42 AM
Dear Experts
In a RFC, our codes are as follows:
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
...
...
...
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
...
...
MODIFY Ztable FROM TABLE it_ztable.
COMMIT WORK.
We wonder to know that how do we pack above actions into a LUW for the consistency of commit or rollback.
‎2014 Mar 03 3:52 AM
Hello KuoTing Chu.
You perform commit if both BAPI and MODIFY statement are successful.
For instance,
* After BAPI_GOODSMVT_CREATE, call BAPI_TRANSACTION_COMMIT only if the return internal table of BAPI_GOODSMVT_CREATE is initial.
* After MODIFY statement, perform COMMIT WORK only if sy-subrc = 0.
Regards.
‎2014 Mar 03 4:02 AM
Dear KuoTing Chu,
I prefer BAPI_TRANSACTION_COMMIT would be enough and commit work after the Ztable update is not required..
Could you please post your coding to be more specific about the situation?
Regards,
Prakash
‎2014 Mar 03 4:05 AM
Hi all,
I think you don't even need the COMMIT WORK; IF the BAPI BAPI_GOODSMVT_CREATE is successful do the MODIFY ZTABLE and if THIS is successful call the BAPI_TRANSACTION_COMMIT. I believe this would achieve the best consistency.
Cheers,
Custodio
‎2014 Mar 03 5:21 AM
What if we want to modify ztable after BAPI is successful?
How can we do a rollback for ztable if not BAPI is unsuccessful?
Thanks,
Sharath
‎2014 Mar 03 5:27 AM
Hi Sharath
You are commiting both changes at one. so if your BAPI fails you wont update the custom table and wont call commit after it so no data gets updated
Nabheet
‎2014 Mar 03 5:40 AM
Hi Sharath,
Exactly what Nabheet says. So it would look something like this:
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'.
IF sy-subrc EQ 0. "or maybe check return table
MODIFY ztable FROM TABLE it_ztable.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. " commits change in BAPI and ZTABLE
ELSE.
bapi_transaction_rollback. "rolls back changes in BAPI and ZTABLE
ENDIF.
ELSE.
bapi_transaction_rollback. "Did not update table, rolls back change from BAPI.
ENDIF.
Cheers,
Custodio
‎2014 Mar 03 7:35 AM
I have followed your suggestion and written sample codes to create sales order.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = lt_order_header
TABLES
return = lt_return
order_items_in = lt_order_item
order_partners = lt_order_partner
order_schedules_in = lt_order_schdl.
READ TABLE lt_return WITH KEY TYPE = 'S'
ID = 'V1'
NUMBER = '311'.
IF SY-SUBRC EQ 0.
MODIFY ZT_PROG_MSG FROM TABLE lt_msg.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = lt_return2.
ELSE.
IF SY-SUBRC NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
And I manually adjust duplication number range for causing an update error.
In debug mode, I check the return type in "lt_return", and then I can get 'S'.
However, after BAPI_TRANSACTION_COMMIT, there is update error for sales order creation, but our Ztable(ZT_PROG_MSG)is still updated successfully. How can we assure consistency, if there is any system error making bapi commit failure?
‎2014 Mar 03 5:59 AM
Hello KuoTing,
Instead of COMMIT WORK, you can use COMMIT WORK AND WAIT.
COMMIT WORK- Asynchronous update.
COMMIT WORK AND WAIT - Synchronous update.
There are two sy-subrc possible for COMMIT WORK AND WAIT.
sy-subrc = 0 (Update Successful)
sy-subrc = 4 (Update Unsuccessful)
So after COMMIT WORK AND WAIT do a sy-subrc check like below.
COMMIT WORK AND WAIT.
IF sy-subrc EQ 4.
ROLLBACK WORK.
ENDIF.
Regards,
Thanga
‎2014 Mar 03 7:49 AM
After writing your code whats Error u got ?
Tell me in details the Error ,,,,
‎2014 Mar 03 8:56 AM
RFC can get successfful message.
Error message are as follows
But Our Ztable still has be updated.
‎2014 Mar 06 7:36 AM
‎2014 Mar 06 7:52 AM
Don't execute the database update in the program, create an update task FM (V1) which execute the INSERT/UPDATE statement. Call this FM IN
UPDATE TASK before the COMMIT.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'.
CALL FUNCTION 'Z_ZTABLE_UPDATE' IN UPDATE TASK
EXPORTING
it_ztable = it_ztable.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
The FM code looking like
FUNCTION z_ztable_update.
*"----------------------------------------------------------------------
*" IMPORTING
*" REFERENCE(IT_ZTABLE) TYPE ZTABLE_T
*"----------------------------------------------------------------------
MODIFY ztable FROM TABLE it_ztable.
IF sy-subrc NE 0.
MESSAGE a999(zzzz) WITH 'ZTABLE'.
ENDIF.
ENDFUNCTION.Regards,
Raymond
‎2014 Mar 06 4:15 PM
Hello Raymond,
Can you please explain me how does UPDATE TASK works.
Will it run in the same work process of the function module call.
Does it work as synchronous or asynchronous ?
Regards,
TP
‎2014 Mar 06 4:25 PM
Can you please explain me how does UPDATE TASK works.
Read the SAP documentation, it's all in there.
‎2014 Mar 06 4:30 PM
Hello Suhas,
I read it, but doesn't understand clearly. I just want to know it in simple words.
‎2014 Mar 06 4:33 PM
A couple of things -
UPDATE TASK before the COMMIT.
What did you mean by this?
*"----------------------------------------------------------------------
*" IMPORTING
*" REFERENCE(IT_ZTABLE) TYPE ZTABLE_T
*"----------------------------------------------------------------------
Update FMs can't have parameters passed by reference
Cheers,
Suhas