Locking: Database Locking, SAP Locking
Database Locking
Lock Unit: Table line, Table, data pages, index pages
Lock mode: Read Lock(Shared Lock, Read locks allow the system to set other read locks, but prevent other transactions from setting write locks for the objects in question), Write Lock(Exclusive Lock, Write locks do not allow other transactions to set any locks for the objects in question.)
Case 1
DATA: SFLIGHT_WA TYPE SFLIGHT, SBOOK_WA TYPE SBOOK.
SELECT SINGLE * FOR UPDATE FROM SFLIGHT (Notes: For update here is the same as CALL FUNCTION func IN UPDATE TASK, and PERFORM ... ON COMMIT
SELECT SINGLE * FOR UPDATE FROM SFLIGHT (Notes: For update here is the same as CALL FUNCTION func IN UPDATE TASK, and PERFORM ... ON COMMIT
理解一:
FOR UPDATE, IN UPDATE TASK, ON COMMIT 分别是把select-clause, Function module, Form拉进这个Transaction.
理解二:让这个
Select-clause或Function module或Forms在下一个commit work时执行。
)
INTO SFLIGHT_WA
WHERE
CARRID = 'LH' AND
CONNID = '0400' AND
FLDATE = '19960516'.
IF SY-SUBRC <> 0.
MESSAGE E...
ENDIF.
IF SFLIGHT_WA-SEATSOCC < SFLIGHT_WA-SEATSMAX.
SBOOK_WA-CARRID = 'LH'.
SBOOK_WA-CONNID = '0400'.
SBOOK_WA-FLDATE = '19960516'.
...
INSERT SBOOK FROM SBOOK_WA.
IF SY-SUBRC <> 0.
MESSAGE E...
ENDIF.
UPDATE SFLIGHT
SET
SEATSOCC = SEATSOCC + 1
WHERE
CARRID = 'LH ' AND
CONNID = '0400' AND
FLDATE = '19960516'.
ELSE.
MESSAGE E...
ENDIF.
COMMIT WORK.
INTO SFLIGHT_WA
WHERE
CARRID = 'LH' AND
CONNID = '0400' AND
FLDATE = '19960516'.
IF SY-SUBRC <> 0.
MESSAGE E...
ENDIF.
IF SFLIGHT_WA-SEATSOCC < SFLIGHT_WA-SEATSMAX.
SBOOK_WA-CARRID = 'LH'.
SBOOK_WA-CONNID = '0400'.
SBOOK_WA-FLDATE = '19960516'.
...
INSERT SBOOK FROM SBOOK_WA.
IF SY-SUBRC <> 0.
MESSAGE E...
ENDIF.
UPDATE SFLIGHT
SET
SEATSOCC = SEATSOCC + 1
WHERE
CARRID = 'LH ' AND
CONNID = '0400' AND
FLDATE = '19960516'.
ELSE.
MESSAGE E...
ENDIF.
COMMIT WORK.
Uncommitted read (or dirty read)
一个事务读取了被另一个未提交的并行的事务写的数据。
A program using an "uncommitted read" to read data does not set locks on data objects and does not obey them. For this reason, programmers must bear in mind that their programs might read data that has not yet been finally written to the database with a database commit and could thus still be deleted from the database by a database rollback. "Uncommitted read" is the default setting in the R/3 system for the isolation level.
一个事务读取了被另一个未提交的并行的事务写的数据。
A program using an "uncommitted read" to read data does not set locks on data objects and does not obey them. For this reason, programmers must bear in mind that their programs might read data that has not yet been finally written to the database with a database commit and could thus still be deleted from the database by a database rollback. "Uncommitted read" is the default setting in the R/3 system for the isolation level.
Committed read
A program using a "committed read" to read data obeys the locks on data objects. This means that programmers can be sure that their programs will read only data which has been finally written to the database with a database commit. You can set the isolation level in the R/3 system to "committed read" by calling the function module DB_SET_ISOLATION_LEVEL . The next database commit or rollback will reset the isolation level to its default setting, as will calling the function module DB_RESET_ISOLATION_TO_DEFAULT .
A program using a "committed read" to read data obeys the locks on data objects. This means that programmers can be sure that their programs will read only data which has been finally written to the database with a database commit. You can set the isolation level in the R/3 system to "committed read" by calling the function module DB_SET_ISOLATION_LEVEL . The next database commit or rollback will reset the isolation level to its default setting, as will calling the function module DB_RESET_ISOLATION_TO_DEFAULT .