0% found this document useful (0 votes)
5 views12 pages

Chapter 14 - Logical Locking

The document outlines the concept of logical locking in SAP, which ensures that only one user can edit a database record at a time. It explains the creation of lock objects and the use of function modules 'ENQUEUE' and 'DEQUEUE' for locking and unlocking records. Additionally, it highlights that logical locks are maintained in a lock table rather than at the database level, and provides guidance on using these mechanisms effectively.

Uploaded by

Aniruddha_Ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views12 pages

Chapter 14 - Logical Locking

The document outlines the concept of logical locking in SAP, which ensures that only one user can edit a database record at a time. It explains the creation of lock objects and the use of function modules 'ENQUEUE' and 'DEQUEUE' for locking and unlocking records. Additionally, it highlights that logical locks are maintained in a lock table rather than at the database level, and provides guidance on using these mechanisms effectively.

Uploaded by

Aniruddha_Ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

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.

2 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 Enter Name Currently, multiple users can edit
the same record at the same time.
Exit Update We will learn how to prevent this
occurrence.
Academy Awards
Year 1994
Category PIC
Winner Forrest Gump
Notes What about Pulp Fiction?!?
Critic Mark Enter Name
3 Logical Locking | Dec-2008 © 2005 IBM Corporation
IBM Global Services

Locking Database Records

Database ABAP
Table 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 SAP’s logical locking mechanism, you need to define a lock object.
 A lock object is an ABAP Dictionary object.

ABAP
ABAP Dictionary
Dictionary Lock
Object

Primary Lock
Table Arguments

AAYEAR
YMOVIE
CATEGORY

5 Logical Locking | Dec-2008 © 2005 IBM Corporation


IBM Global Services

Lock Objects (Contd.)

 To use SAP’s logical locking mechanism, you need to define a lock object.
 A lock object is an ABAP Dictionary object.

Lock
ABAP
ABAP Dictionary
Dictionary
Object

Primary Lock
Table Arguments

AAYEAR
YMOVIE
CATEGORY

6 Logical Locking | Dec-2008 © 2005 IBM Corporation


IBM Global Services

Function Modules

CALL FUNCTION CALL FUNCTION


‘ENQUEUE_EZ_YMOVIE’ ‘DEQUEUE_EZ_YMOVIE’
EXPORTING EXPORTING
AAYEAR = YMOVIE-AAYEAR AAYEAR = YMOVIE-AAYEAR
CATEGORY = YMOVIE- CATEGORY = YMOVIE-
CATEGORY CATEGORY
EXCEPTIONS EXCEPTIONS
FOREIGN_LOCK =1 OTHERS = 1.
SYSTEM_FAILURE = 2
OTHERS = 3. If a “lock” exists for the record, the
IF SY-SUBRC = 1. “DEQUEUE” function module will
MESSAGE E004. remove the “lock” on the record.
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.
7 Logical Locking | Dec-2008 © 2005 IBM Corporation
IBM Global Services

Locking and Unlocking

MODULE SELECT_LISTING INPUT. This subroutine will “call” the function


IF OKCODE = ‘EDIT’. module “ENQUEUE_EZ_YMOVIE” to
PERFORM LOCK. check if the record is already “locked”
* code to select record from YMOVIE or to “lock” the record.
ENDIF.
ENDMODULE.

MODULE UPDATE INPUT.


IF OKCODE = ‘UPDA’.
UPDATE YMOVIE.
* code to commit or rollback This subroutine will “call” the function
PERFORM UNLOCK. module “DEQUEUE_EZ_YMOVIE”
ENDIF. to “unlock” the record.
ENDMODULE.

8 Logical Locking | Dec-2008 © 2005 IBM Corporation


IBM Global Services

Demonstration

 Using lock objects for locking and unlocking data before and after database
updates.

9 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 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.

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

You might also like