Chapter 14_Logical Locking
-
Upload
raul-thomas -
Category
Documents
-
view
3 -
download
1
Transcript of Chapter 14_Logical Locking
IBM Global Services
Logical Locking | 6.14 March-2005 © 2005 IBM Corporation
Logical Locking
IBM Global Services
© 2005 IBM Corporation2 March-2005Logical Locking | 6.14
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.
IBM Global Services
© 2005 IBM Corporation3 March-2005Logical Locking | 6.14
Overview
Academy Awards
Year
Category
1994
PIC
Winner Forrest Gump
Notes Great movie !!!
Critic Ellen
UpdateExit
Enter Name
Academy Awards
Year
Category
1994
PIC
Winner Forrest Gump
Notes What about Pulp Fiction?!?
Critic Mark
UpdateExit
Enter Name
Currently, multiple users can edit
the same record at the same time. We will learn how to prevent this occurrence.
IBM Global Services
© 2005 IBM Corporation4 March-2005Logical Locking | 6.14
Locking Database Records
Database Lock
DatabaseTable
ABAPProgram
Logical Lock
In an ABAP program, logical locking ensures that only one user can edit a record at any one time.
IBM Global Services
© 2005 IBM Corporation5 March-2005Logical Locking | 6.14
Lock Objects
ABAP DictionaryABAP DictionaryABAP DictionaryABAP Dictionary
PrimaryTable
LockArguments
YMOVIEAAYEAR
CATEGORY
To use SAP’s logical locking mechanism, you need to define a lock object.
A lock object is an ABAP Dictionary object.
LockObject
IBM Global Services
© 2005 IBM Corporation6 March-2005Logical Locking | 6.14
Lock Objects (Contd.)
ABAP DictionaryABAP DictionaryABAP DictionaryABAP Dictionary
Primary
Table
Lock
Arguments
YMOVIEAAYEAR
CATEGORY
To use SAP’s logical locking mechanism, you need to define a lock object.
A lock object is an ABAP Dictionary object.
LockObject
IBM Global Services
© 2005 IBM Corporation7 March-2005Logical Locking | 6.14
Function Modules
CALL FUNCTION ‘ENQUEUE_EZ_YMOVIE’
EXPORTING
AAYEAR = YMOVIE-AAYEAR
CATEGORY = YMOVIE-CATEGORY
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3.
IF SY-SUBRC = 1.
MESSAGE E004.
ENDIF.
CALL FUNCTION ‘DEQUEUE_EZ_YMOVIE’
EXPORTING
AAYEAR = YMOVIE-AAYEAR
CATEGORY = YMOVIE-CATEGORY
EXCEPTIONS
OTHERS = 1.
If a “lock” exists for the record, the
“DEQUEUE” function module will
remove the “lock” on the record.
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.
IBM Global Services
© 2005 IBM Corporation8 March-2005Logical Locking | 6.14
Locking and Unlocking
MODULE SELECT_LISTING INPUT.
IF OKCODE = ‘EDIT’.
PERFORM LOCK.
* code to select record from YMOVIE
ENDIF.
ENDMODULE.
MODULE UPDATE INPUT.
IF OKCODE = ‘UPDA’.
UPDATE YMOVIE.
* code to commit or rollback
PERFORM UNLOCK.
ENDIF.
ENDMODULE.
This subroutine will “call” the function
module “ENQUEUE_EZ_YMOVIE” to
check if the record is already “locked”
or to “lock” the record.
This subroutine will “call” the function
module “DEQUEUE_EZ_YMOVIE”
to “unlock” the record.
IBM Global Services
© 2005 IBM Corporation9 March-2005Logical Locking | 6.14
Demonstration
Using lock objects for locking and unlocking data before and after database updates.
IBM Global Services
© 2005 IBM Corporation10 March-2005Logical Locking | 6.14
Practice
Using lock objects for locking and unlocking data before and after database updates.
IBM Global Services
© 2005 IBM Corporation11 March-2005Logical Locking | 6.14
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 SAP’s 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.
IBM Global Services
© 2005 IBM Corporation12 March-2005Logical Locking | 6.14
Questions
** MZA09I01 - PAI Modules **
MODULE END INPUT.
LEAVE TO SCREEN 0.
ENDMODULE. PROCESS AFTER INPUT.
MODULE END.
Screen 9002
PROCESS AFTER INPUT.
MODULE END AT EXIT-COMMAND.
Screen 9000
PROCESS AFTER INPUT.
MODULE END AT EXIT-COMMAND.
Screen 9001
What additional code is
needed in the module “END”?