Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI_TRANSACTION_COMMIT doesn't save fast enough?

Former Member
0 Likes
1,571

Hello,

I'm using BAPIs to create order confirmation, and if good movements failed for this confirmation I want it to be cancelled.

My code looks like this:


** get data and fill in missing fields
CALL FUNCTION 'BAPI_PRODORDCONF_GET_TT_PROP'
[...]

** create confirmation
CALL FUNCTION 'BAPI_PRODORDCONF_CREATE_TT'
  EXPORTING
    post_wrong_entries = '0'  "do not save confirmation on error
    testrun = ' '
  IMPORTING
    RETURN = t_return_err
  TABLES
    timetickets = t_timetickets
    goodsmovements = t_goodsmovements
    link_conf_goodsmov = t_link_conf_goodsmov
    detail_return = t_return_details.

** check if there was an error 
IF t_return_err-TYPE = 'E' OR t_return_err-TYPE = 'A'. "if 'E'error or 'A'bort
** rollback changes
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  RAISE CONFIRMATION_FAILED.
ENDIF.

** check if there was an error regarding data provided
IF t_return_details-TYPE = 'E' OR t_return_details-TYPE = 'A'. "if 'E'error or 'A'bort
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  RAISE CONFIRMATION_FAILED.
ENDIF.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    WAIT = 'X'.

confirmation = t_return_details-conf_no.
confirmationcounter = t_return_details-conf_cnt.

CALL FUNCTION 'BAPI_PRODORDCONF_GETDETAIL'
  EXPORTING
    CONFIRMATION = confirmation
    CONFIRMATIONCOUNTER = confirmationcounter
  IMPORTING
    RETURN = t_return_err
    CONF_DETAIL = t_conf_detail
  TABLES
    GOODSMOVEMENTS = t_goodsmovements_correct
    FAILEDGMOVES = t_failedgmoves.


IF t_return_err-TYPE = 'E' OR t_return_err-TYPE = 'A'. "if 'E'error or 'A'bort
  RAISE CONFIRMATION_FAILED.
ENDIF.

** Check if goods movement was successful, and if not cancel the confirmation
IF t_failedgmoves IS NOT INITIAL.

** Cancel the confirmation that failed
  CALL FUNCTION 'BAPI_PRODORDCONF_CANCEL'
    EXPORTING
      CONFIRMATION              = confirmation
      CONFIRMATIONCOUNTER       = confirmationcounter
   IMPORTING
      RETURN                    = t_return_err
      LOCKED                    = locked
      CREATED_CONF_NO           = confirmation_created
      CREATED_CONF_COUNT        = confirmationcounter_created.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      WAIT = 'X'.

[...]

And my problem is as follows:

If I just run this transaction as it is, I am given following error from BAPI_PRODORDCONF_CANCEL function:

Future change records for background processing exist for order XXXXX

and confirmation_created and confirmationcounter_created variables are zeros (0).

But if I debug this code and set breakpoint at the line

CALL FUNCTION 'BAPI_PRODORDCONF_CANCEL'

(and then run it further) then the error doesn't appear and confirmation_created and confirmationcounter_created variables are given correct values and everything executes correctly.

It seems like the first BAPI_TRANSACTION_COMMIT doesn't have enough time to execute, but it is assigned WAIT flag, so this should not be the problem.

Could You suggest any solution/explanation for this weird behaviour?

Greetings,

Mateusz

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
979

Use WAIT UPTO XXXX Seconds .. after bapi commit.

Thanks

Mohan.

6 REPLIES 6
Read only

Former Member
0 Likes
980

Use WAIT UPTO XXXX Seconds .. after bapi commit.

Thanks

Mohan.

Read only

Former Member
0 Likes
979

u can also write COMMIT WORK AND WAIT only

insteadof CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

Read only

Former Member
0 Likes
979

Call the FM in UPDATE TASK

Read only

Former Member
0 Likes
979

After BAPI_TRANSACTION_COMMIT use

wait 5 seconds.

Read only

Former Member
0 Likes
979

Hi,

I Have done the same with the modulepool program for the confirmation of order and the goods movement for that order....for that i used the following Bapi's

For production order confirmation CALL FUNCTION 'BAPI_PRODORDCONF_CREATE_HDR'

after this CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

and for goods movement CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

after this CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

And for the production order cancel....

CALL FUNCTION 'BAPI_PRODORDCONF_CANCEL'

Everything went fine for me by following this sequence...

Hope this will help you also to solve the problem.

Regards,

Rohan.

Read only

Former Member
0 Likes
979

Thank You all for your responses.

Finally - suggested "wait up to..." did the trick.

Netiher Commit work nor commit work and wait worked for me (tried that earlier, also they are used in

bapi_commit_transaction).

I also took all the other suggestions into considerations and maybe I will have opportunity to use them in future.

Greetings,

Mateusz

Edited by: Mateusz K on Dec 7, 2008 10:32 PM