commit and roll back report
commit and roll back report
REPORT z_commit_rollback_example.
TABLES: sflight.
Explanation
1. Select Data:
o The SELECT statement fetches data from the SFLIGHT table into an internal table
lt_sflight. In this example, only 10 rows are selected.
2. Update Data:
o We loop through the internal table and update the SEATSMAX field by adding 10 to
each record.
o The MODIFY statement is used to update the SFLIGHT table with the modified
records.
3. Commit or Rollback:
o We use a dummy condition to decide whether to commit or roll back the
transaction.
o If the condition (sy-datum MOD 2 = 0) is met, the COMMIT WORK statement is
executed, which commits the transaction, making all changes permanent.
o If the condition is not met, the ROLLBACK WORK statement is executed, which
undoes all changes made in the current logical unit of work (LUW).
Notes
COMMIT WORK: This statement saves all the changes made in the current LUW to the
database and ends the LUW.
ROLLBACK WORK: This statement undoes all the changes made in the current LUW
and ends the LUW.
Important Considerations
Error Handling: In a real-world scenario, you would likely have more complex
conditions and error handling to decide when to commit or roll back. Ensure to handle
exceptions and unexpected situations gracefully.
Transactional Consistency: Ensure that your operations maintain transactional
consistency, especially when dealing with multiple related tables or complex business
logic.
This example demonstrates the basic usage of COMMIT WORK and ROLLBACK WORK in ABAP to
control database transactions.