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

how to use commit and roll back in bapi in same program?

babu_gavi
Explorer
0 Likes
3,658

Hi Experts,

i have requirements like update sales order data using bapi

if any errors occurs in those i want to roll back them and rest of them i need to update...

how can i achieve these....

in which order i need use both commit and roll back in bapi

@moderators

before closing any content please tell me right path for getting the solution....................................

you people are simply closing the content with out explaining solution.

we are here for try to get solution for our problem.................

dont kill our oppurtunities..........

1 ACCEPTED SOLUTION
Read only

rajkumarnarasimman
Active Contributor
0 Likes
1,343

Hi Babu,

Please find the below program for Commit and Rollback.


"Data Declaration - Error Type

DATA: L_ERR TYPE I VALUE 0.

"FM to update the Sales Order

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = salesdocument

ORDER_HEADER_IN = order_header_in

ORDER_HEADER_INX = order_header_inx

LOGIC_SWITCH = logic_switch

TABLES

RETURN = return

CONDITIONS_IN = conditions_in

CONDITIONS_INX = conditions_inx.

"Clear Error Flag

L_ERR = 0.

" Check whether any error occured in BAPI

LOOP AT RETURN.

IF return-type = 'A' OR return-type = 'E'.

  L_ERR = 1.     "Activate the Error Flag

ENDIF.

ENDLOOP.

"Check any error occured, If error occured, rollback, else commit the work

IF L_ERR = 1.

  "Rollback

  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ELSE.

  "Commit the Work

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

      EXPORTING

        wait   = 'X'.

ENDIF.

Note:

Always use BAPI_TRANSACTION_COMMIT instead of COMMIT WORK and use BAPI_TRANSACTION_ROLLBACK instead of ROLLBACK WORK, It will refresh the Buffer. Also find the link below.


BAPI_TRANSACTION_COMMIT versus COMMIT WORK - ABAP Development - SCN Wiki

Regards

Rajkumar Narasimman

2 REPLIES 2
Read only

Former Member
0 Likes
1,343

Hi,

Using this  BAPI_SALESORDER_CHANGE , you can update your SO.

But the way you described situation It may not be possible as we update SO using standard BAPI,

but If your functional require validations than you can simply skip those field which don't satisfy condition and pass only those structure to BAPI which contains only accurate data.

Hope you got my point.

Thank You.

Dular Sharma.

Read only

rajkumarnarasimman
Active Contributor
0 Likes
1,344

Hi Babu,

Please find the below program for Commit and Rollback.


"Data Declaration - Error Type

DATA: L_ERR TYPE I VALUE 0.

"FM to update the Sales Order

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = salesdocument

ORDER_HEADER_IN = order_header_in

ORDER_HEADER_INX = order_header_inx

LOGIC_SWITCH = logic_switch

TABLES

RETURN = return

CONDITIONS_IN = conditions_in

CONDITIONS_INX = conditions_inx.

"Clear Error Flag

L_ERR = 0.

" Check whether any error occured in BAPI

LOOP AT RETURN.

IF return-type = 'A' OR return-type = 'E'.

  L_ERR = 1.     "Activate the Error Flag

ENDIF.

ENDLOOP.

"Check any error occured, If error occured, rollback, else commit the work

IF L_ERR = 1.

  "Rollback

  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ELSE.

  "Commit the Work

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

      EXPORTING

        wait   = 'X'.

ENDIF.

Note:

Always use BAPI_TRANSACTION_COMMIT instead of COMMIT WORK and use BAPI_TRANSACTION_ROLLBACK instead of ROLLBACK WORK, It will refresh the Buffer. Also find the link below.


BAPI_TRANSACTION_COMMIT versus COMMIT WORK - ABAP Development - SCN Wiki

Regards

Rajkumar Narasimman