0% found this document useful (0 votes)
11 views

commit and roll back report

Uploaded by

hema9.abap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

commit and roll back report

Uploaded by

hema9.abap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

ABAP Code Example

REPORT z_commit_rollback_example.

TABLES: sflight.

DATA: lt_sflight TYPE TABLE OF sflight,


ls_sflight TYPE sflight.

" Select data from the database


SELECT * FROM sflight INTO TABLE lt_sflight UP TO 10 ROWS.

" Update the internal table (this is just an example operation)


LOOP AT lt_sflight INTO ls_sflight.
ls_sflight-seatsmax = ls_sflight-seatsmax + 10.
MODIFY sflight FROM ls_sflight.
ENDLOOP.

" Check a condition to decide whether to commit or roll back


" (This is a dummy condition for demonstration purposes)
IF sy-datum MOD 2 = 0. " For example, commit on even dates
COMMIT WORK.
WRITE: / 'Transaction committed successfully.'.
ELSE.
ROLLBACK WORK.
WRITE: / 'Transaction rolled back.'.
ENDIF.

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.

You might also like