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

commit work and roll back with simple language and simple example

Former Member
0 Likes
14,784

hi guru

commit work and roll back with simple language and simple example

2 REPLIES 2
Read only

Former Member
0 Likes
3,973

Hi,

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:

It executes all subroutines registered using PERFORM ON COMMIT.

The sequence is based on the order of registration or according to the priority specified using the LEVEL addition. Execution of the following statements is not permitted in a subroutine of this type:

PERFORM ... ON COMMIT|ROLLBACK

COMMIT WORK

ROLLBACK WORK

The statement CALL FUNCTION ... IN UPDATE TASK can be executed.

ROLL BACK:

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:

1) Executes all subprograms registered with PERFORM ON ROLLBACK.

2) Deletes all subprograms registered with PERFORM ON COMMIT.

3) Raises an internal exception in the Object Services that makes sure that the attributes of persistent objects are initialised.

4) Deletes all update function modules registered with CALL FUNCTION ...IN UPDATE TASK from the VBLOG database table and deletes all transactional remote Function Calls registered with CALL FUNCTION ... IN BACKGROUND TASK from database tables ARFCSSTATE and ARFCSDATA.

5) Removal of all SAP locks set in the current program in which the formal parameter _SCOPE of the lock function module was set to the value 2.

6) Triggers a database rollback, which also ends the current database-LUW.

Read only

Former Member
0 Likes
3,973

hi,

here is one example i found somewhere, it will help you understand commit and rollback.

REPORT ZTEST.

TABLES : ZYDTABLE01.

DATA: IT_TAB01 LIKE ZYDTABLE01

OCCURS 0 WITH HEADER LINE.

IT_TAB01-ZTEXT01 = 'DAVID'.

IT_TAB01-ZTEXT02 = 'VVVVV'.

APPEND IT_TAB01.

*MODIFY ZYDTABLE01 FROM IT_TAB01.

UPDATE ZYDTABLE01

SET: ZTEXT02 = 'UPDATEDONE'

WHERE ZTEXT01 LIKE 'BG1'.

INSERT INTO ZYDTABLE01 VALUES IT_TAB01.

IF SY-SUBRC = 0.

COMMIT WORK.

ELSE.

ROLLBACK WORK.

ENDIF.

reward if useful..