Why is there sap luw and lock object?
The SAP system is based on a three-tier architecture. When an sap gui request arrives at the application server, it is allocated to a dialog workflow. In this process, the DB interface can update opensql to the database, after a screen is processed, the used dialog workflow is released to process other user requests as soon as possible. after screen processing, implicit dB commit is triggered. In a business process, user operations span multiple screens, in this way, the database luw is insufficient to support multiple operations in the business data operation process in the same logical unit. Therefore, SAP luw provides the sap luw to bind multiple operations into a logical unit, all updates or cancellation ensure data consistency in operations. during business operations, such as order modification, this order needs to be used exclusively. Therefore, concurrent control is required for data access, and SAP provides a lock object.
Database updates in ABAPThere are two types
1> inline update,
Update the table content directly using opensql in the program, or update the table content through perform... on commit.
2> Update Module
In this case, the data in each dialog step is written to a log table vblog (transparent tables vbhdr, vbmod, vbdata, and vberror), and then updated to the DB together, after the operation is successful, the records in the log table are deleted. otherwise, the identification fails.
Technical Implementation: The UPDATE function module only has the importing tables parameter. Ignore exporting and exceptions.
During use, pay attention to the use of commit work, which will trigger database Commit Changes.
When using the UPDATE function module, you can use the following methods:
A. asynchronous update commit work. Update is performed in the update work process. It is suitable for programs that operate on the database for a long time.
B. Synchronously update commit work and wait updates in another working process.
C. The local update set update task still occupies the original dialog working process, but no data is written to the vblog. This avoids Io operations and is fast. It is suitable for batch mode.
Note:
Pay attention to the return value of the SY-SUBRC when updating the database, and pay attention to whether multiple open SQL update operations need to be in the same luw for recovery after the processing operation fails.
Lock Concept
SAP lock must be maintained during luw. SAP lock is implemented based on Lock Object and defined in ddic, it can lock one or more records in a table or lock records in multiple tables according to the foreign key relationship.
There are two functions: enqueue_xxx and dequeue_xxx used to lock and unlock.
Lock
After locking, add a record to lock talbe. Note that the lock table exists in the memory and only one record exists in the entire SAP system. You can use sm12 for maintenance.
Enqueue_xxx has the following parameters:
There are three types of locks: E exclusive locks, s shared locks, and X
Key Field
_ Scope: defines the duration of the lock relative to luw. In 1 program, 2 update Module 3 has both.
Release lock
Mainly related to _ Scope During lock
1. The dequeue_xxx function needs to be explicitly called.
2. At least one call function... for update task is registered and the lock is automatically released when commit work is used.
3. Update and the program both need to release the lock.
Note:
The dequeue_all FM can release all the locks, but note that if the call function... for update task is used, the lock may be released in advance, so it is best to use commit work.
It should also be noted that the impact of the lock on the performance will affect the concurrency of the program after the lock, so the lock time should be as short as possible.
If the BDC program is called, the program has commit work, which will interrupt the processing of BDC. In this case, you need to use the options from Wa option when calling BDC, set the racommit of wa to X to prevent interruption.
Luw Problems
Delete data from the database and insert data. If the insertion fails, how can we roll back?
A. explicitly use rollback work. Note that it cannot be used in the subroutine of perform XXXX on commit.; otherwise, there will be dump.
It cannot be used in the function module of call function XXXX in update task.
B. Messages of type A are generated.