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: 

Commit and Roll Back

Former Member
0 Kudos

Hi!

Can any one give an example for commit and rollback

as well as

Can u give me the statement for commit and rollback

with Eg:

Thanks

Imran.

3 REPLIES 3

Former Member
0 Kudos

Hi

COMMIT is used to commit/update the records in database after your query

Rollback will rollout the changes that were made to database using the query.

when we use BAPI's for creation/updation ofrecords we use the BAPI

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' for committing records

ROLLBACK WORK

Terminates a SAP-LUW without storing the changes.

The statement ROLLBACK WORK closes the current SAP-LUW and opens a new one. In doing so, all change requests of the current SAP-LUW are canceled. To do this, ROLLBACK WORK carries out the following actions:

COMMIT work

Terminates an SAP LUW and stores the changes

The statement COMMIT WORK completes the current SAP LUW and opens a new one, storing all change requests for the current SAP LUW in the process. In this case, COMMIT WORK performs the following actions:

for further help

write these statements in the program and press F1 you will get the necessary SAP help with examples

Reward points if useful

Regards

Anji

Message was edited by:

Anji Reddy Vangala

Former Member
0 Kudos

Normally data is sent to BAPI for processing. Now, if 1 record has been processed successfully, the COMMIT works gets triggered internally. So, Commit works as such when an entry is processed successfully.

When u pass data and inbetween BAPI fails due to some reason, ROLL BACK gets triggered and the updates that has happened for that particular record data are been roll backed

Need ur reward points

Regards

Ravi

uwe_schieferstein
Active Contributor
0 Kudos

Hello Imran

BAPIs are indeed a good example to explain the use of commit work and rollback. BAPIs are RFC-enabled function modules that allow us to access SAP business objects (e.g. materials) from outside.

In case of failure BAPIs do not raise any exceptions but usually return the collected messages in a TABLES parameter RETURN (of line type BAPIRET2).

After calling a BAPI you have to evaluate the returned messages:

DATA:
  lt_return    TYPE BAPIRETTAB (table type of BAPIRET2).


  CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' 
    EXPORTING
       ...
    IMPORTING
      ...
    TABLES
     ...
       return = lt_return.

  LOOP AT lt_return TRANSPORTING NO FIELDS
                 WHERE ( type CA 'AEX' ).  " (A)bort, (E)rror, X=dump
    EXIT.
  ENDLOOP.
  IF ( syst-subrc = 0 ).
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING  
        wait = 'X'.  " synchronous
  ENDIF.

Please note that BAPIs may or may not return a Success message (type='S') in case of success. An empty RETURN messages indicates a successful BAPI call.

Regards

Uwe