IBM Global Services
Logical Locking
Logical Locking |
Dec-2008
2005 IBM Corporation
IBM Global Services
Objectives
The participants will be able to:
Lock database records.
Create a lock object.
Recognize the automatic creation of the ENQUEUE and DEQUEUE function modules.
Logical Locking |
Dec-2008
2005 IBM Corporation
IBM Global Services
Overview
Exit
Update
Academy Awards
Year
1994
Category
PIC
Winner
Forrest Gump
Notes
Great movie !!!
Critic
Ellen
Currently, multiple users can edit
Enter Name
Exit
Update
Academy Awards
Logical Locking |
the same record at the same time.
We will learn how to prevent this
occurrence.
Year
1994
Category
PIC
Winner
Forrest Gump
Notes
What about Pulp Fiction?!?
Critic
Mark
Enter Name
Dec-2008
2005 IBM Corporation
IBM Global Services
Locking Database Records
Database
Table
ABAP
Program
Database Lock
Logical Lock
In an ABAP program, logical locking ensures that only one user
can edit a record at any one time.
4
Logical Locking |
Dec-2008
2005 IBM Corporation
IBM Global Services
Lock Objects
To use SAPs logical locking mechanism, you need to define a lock object.
A lock object is an ABAP Dictionary object.
ABAP
ABAP Dictionary
Dictionary
Primary
Table
YMOVIE
Logical Locking |
Lock
Object
Lock
Arguments
AAYEAR
CATEGORY
Dec-2008
2005 IBM Corporation
IBM Global Services
Lock Objects (Contd.)
To use SAPs logical locking mechanism, you need to define a lock object.
A lock object is an ABAP Dictionary object.
ABAP
ABAP Dictionary
Dictionary
Primary
Lock
Table
Arguments
YMOVIE
Lock
Object
Logical Locking |
AAYEAR
CATEGORY
Dec-2008
2005 IBM Corporation
IBM Global Services
Function Modules
CALL FUNCTION
ENQUEUE_EZ_YMOVIE
CALL FUNCTION
DEQUEUE_EZ_YMOVIE
EXPORTING
AAYEAR
EXPORTING
= YMOVIE-AAYEAR
CATEGORY = YMOVIECATEGORY
EXCEPTIONS
AAYEAR
= YMOVIE-AAYEAR
CATEGORY = YMOVIECATEGORY
EXCEPTIONS
FOREIGN_LOCK
=1
OTHERS
= 1.
SYSTEM_FAILURE = 2
OTHERS
= 3.
If a lock exists for the record, the
DEQUEUE function module will
IF SY-SUBRC = 1.
remove the lock on the record.
MESSAGE E004.
ENDIF.
If a lock already exists for the record, the ENQUEUE function
Module will raise the foreign lock exception. If a lock does
not exist, this function module will lock the record.
Logical Locking |
Dec-2008
2005 IBM Corporation
IBM Global Services
Locking and Unlocking
MODULE SELECT_LISTING INPUT.
IF OKCODE = EDIT.
PERFORM LOCK.
* code to select record from YMOVIE
This subroutine will call the function
module ENQUEUE_EZ_YMOVIE to
check if the record is already locked
or to lock the record.
ENDIF.
ENDMODULE.
MODULE UPDATE INPUT.
IF OKCODE = UPDA.
UPDATE YMOVIE.
* code to commit or rollback
PERFORM UNLOCK.
ENDIF.
ENDMODULE.
Logical Locking |
This subroutine will call the function
module DEQUEUE_EZ_YMOVIE
to unlock the record.
Dec-2008
2005 IBM Corporation
IBM Global Services
Demonstration
Using lock objects for locking and unlocking data before and after database
updates.
Logical Locking |
Dec-2008
2005 IBM Corporation
IBM Global Services
Practice
Using lock objects for locking and unlocking data before and after database
updates.
10
Logical Locking |
Dec-2008
2005 IBM Corporation
IBM Global Services
Summary
Database locks on records are automatically created by the system. The system
releases a database lock at every database commit (i.e., at every screen
change).
Records are automatically unlocked at every screen change, we cannot rely on
database locks to prevent multiple users from editing the same record at the
same time in a multi-screen transaction.We can handle this problem with logical
locks.
To use SAPs logical locking mechanism, you need to define a lock object. When
you activate a lock object, the system automatically generates two function
modules: ENQUEUE_<lock object name> and DEQUEUE_<lock object
name> .
It is important to understand that logical locks do not create locks at the database
level. Logical locks are maintained through entries in a lock table.
Transaction SM12 will display the current entries in the lock table.
11
Logical Locking |
Dec-2008
2005 IBM Corporation
IBM Global Services
Questions
Screen 9000
PROCESS AFTER INPUT.
MODULE END AT EXIT-COMMAND.
What additional code is
needed in the module END?
Screen 9001
PROCESS AFTER INPUT.
MODULE END AT EXIT-COMMAND.
** MZA09I01 - PAI Modules **
MODULE END INPUT.
Screen 9002
LEAVE TO SCREEN 0.
PROCESS AFTER INPUT.
ENDMODULE.
MODULE END.
12
Logical Locking |
Dec-2008
2005 IBM Corporation