Application Development 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: 

What is the Use of BAPI_TRANSCATION_COMMIT?

Former Member
0 Kudos

What is the Use of BAPI_TRANSCATION_COMMIT?

Would you please give the example how the above FM used in realtime?

Early reply is highely appriciable.

Regards,

Chow.

5 REPLIES 5

Former Member
0 Kudos

Hello,

Check this:

FU BAPI_TRANSACTION_COMMIT

____________________________________________________

Short text

Execute external Commit when using BAPIs

Functionality

This method executes a COMMIT WORK command. It is required for

transactions developed externally to the R/3 System that change data in

the R/3 System via BAPI calls.

When you call BAPIs in your program that change data in the R/3 System,

afterwards you must call this method to write the changes to the

database.

Notes

Messages are returned in the parameter 'return'. This parameter

documentation contains the return codes and their descriptions.

Further Information

Use the method BapiService.TransactionRollback to prevent changes to the

database being committed.

Parameter

WAIT

RETURN

Exceptions

Cheers,

Vasanth

Former Member
0 Kudos

Hi,

As of Release 4.0 BAPIs must not execute 'COMMIT WORK' commands. Because The caller should have control of the transaction. Several BAPIs should be able to be combined within one LUW.

The BAPI's created with new guidelines will not have COMMIT WORK or

ROLLBACK Statement in it. Based on the Failure/Success of the BAPI we have to explicitly call BAPI_TRANSACTION_ROLLBACK and BAPI_TRANSACTION_COMMIT which will have

ROLLBACK WORK or COMMIT WORK Respectively in it.

Reward with points if helpful.

-Pranjali Mode.

Former Member
0 Kudos

Hi,

Commit work is used when you code directly in ABAP and make changes in the database and

want to commit the database.

BAPI_TRANSACTION_COMMIT is used when you make changes to the SAP database by calling

a BAPI from outside SAP and want to commit the database. When you use a BAPI, you can not

directly use commit work, instead you are allowed to use only

BAPI_TRANSACTION_COMMIT.

Regards

Sudheer

Former Member
0 Kudos

See below code which might be useful...

  • Post GR using the IR reference.

CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'

EXPORTING

documentheader = lf_header

IMPORTING

obj_key = l_obj_key

TABLES

accountgl = lit_item

currencyamount = lit_amount

return = it_return.

SORT it_return BY type.

READ TABLE it_return INTO gf_return WITH KEY type = c_e

BINARY SEARCH.

IF sy-subrc EQ 0.

  • Rollback the Bapi Updations

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .

DESCRIBE TABLE it_return LINES sy-tfill.

READ TABLE it_return INTO gf_return INDEX sy-tfill.

CLEAR gf_errlog.

CONCATENATE

'BAPI Error occurred while posting FI document'(025)

'from Contract'(020) lf_new_posting-vbeln c_slash

lf_new_posting-posnr gf_return-message

INTO gf_errlog-line SEPARATED BY c_space.

CONDENSE gf_errlog-line.

APPEND gf_errlog TO it_errlog.

ELSE.

  • Call database commit.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = c_x.

Former Member
0 Kudos

To commit the databse (to save changes to the database), we have to use the FM bapi-tra.commit.

Normal commit wil not work in BAPIS

bcoz, BAPI is RFC,

Once u do changes to database, u have to this bapi-tran.commit

Reward if useful