Você está na página 1de 9

Example of Lock Objects

When booking flights, (for more information, see Flight Model ) you have to
prevent flights from being overbooked. For this reason, you have to lock the
particular flight as well as all the bookings existing for this flight during
processing. You can do this with lock object E_BOOKING.

The system records the flights in table SFLIGHT and the bookings for the
flights in table SBOOK. The two tables are linked with a foreign key. Lock
object E_BOOKING must contain table SFLIGHT as the primary table and
table SBOOK as the secondary table. In the following figure you can see the
relations between the primary and the secondary table in our example.
The lock argument of table SFLIGHT thus contains the fields MANDT,
CARRID, CONNID, and FLDATE. The lock argument of table SBOOK thus
contains the fields MANDT, CARRID, CONNID, FLDATE, BOOKID and
CUSTOMID.
Select exclusive lock mode, that is, the locked data can only be displayed and
edited by one user.

When the lock object is activated, the following function modules are
generated from its definition:

 ENQUEUE_ E_BOOKING (set locks)


 DEQUEUE_ E_BOOKING (release locks)

These function modules can now be linked to ABAP programs.

The following figure shows how function module ENQUEUE_ E_BOOKING is


called.
With this call, flight LH 400 on November 29,1998 is exclusively locked (lock
mode E) in table SFLIGHT. It is locked together with all the bookings entered
in table SBOOK for this flight (since the initial value 0 is transferred for
BOOKID and CUSTOMID). The lock is sent to the update program (_SCOPE
= '2'). If there is a lock conflict, the system makes another attempt to set the
lock after a certain time (_WAIT = 'X').

The set locks can be removed by calling the function module


DEQUEUE_E_BOOKING as follows:

The existing exclusive lock entries for flight LH 400 are deleted in table
SFLIGHT and the bookings for this flight are deleted in table SBOOK. The
request to delete the lock entries is passed on to the update program
(_SCOPE = '3').

Creating Lock Objects


Procedure

1. Open the Repository Browser and navigate to the package in which you
want to create the lock object.
2. In the context menu of the package, choose Create → Dictionary Object
→ Lock object.

A dialog box appears.

3. In the new dialog box, enter the name of the lock object and
choose with the quick info text Continue.

The maintenance screen for lock objects is displayed.

Caution
The name of a lock object must begin with E (Enqueue).

4. In the field Short Description, enter an explanatory short text.

You can use this short text to find the lock object at a later time, for
example with the SAP Repository Information System.

5. Choose the Tables tab page and enter the name of the primary table of
the lock object in the Name field.

Caution
All other tables in the lock object must be linked with the primary table
using foreign keys . There are also some restrictions on the valid foreign
key relationships .
6. Select the lock mode of the primary table in the Lock Mode field.

The lock mode is used as the default value for the corresponding
parameters of the function modules generated from the lock object.

7. On the Tables tab page, choose Add if you want to lock records in more
than one table with the lock object.

A list of all the tables linked with the primary table using valid foreign
keys appears. Select the appropriate table. The lock mode of the
primary table is copied as the lock mode. You can change this setting
as required, for example you can assign the lock mode separately for
each table.
Similarly, you can add a table linked with the secondary table that was
just added with foreign keys. To do this, select the name of the
secondary table and choose Add.

Note
If no lock mode is assigned to a table, the system does not set a lock for
the entries in this table when the generated function modules are called.
You must not assign a lock mode if a secondary table is only used to
define a path between the primary table and another secondary table
with foreign keys.

8. Choose with the quick info text Save.

A dialog box appears in which you must assign the lock object to a
package. To change this package at a later time, choose Goto → Object
Dirrectory Entry.

9. On the Lock parameter tab page, you can (optionally) exclude lock
parameters (see lock objects ) from the function module generation.
This makes sense if you always want to lock a parameter generically,
for example.
To do this, deselect the indicator for the parameter in column W. The
system does not take the parameter into consideration in the generated
function modules. Then the system always locks this parameter
generically.
The name of a lock parameter is in most cases the name of the
corresponding table field.

Note
If two fields with the same name are used as lock parameters in the lock
object from different tables, you must choose a new name for one of the
fields in the Lock parameter field.

10. On the Attributes tab page, you can define whether the function
modules generated from the lock object must be RFC-enabled.

If you set the Allow RFC indicator, the generated function modules can
be called from within another system with Remote Function Call.
If you allow Remote Function Calls(RFC) for an existing lock object, you
must ensure that the generated function modules are called from within
an ABAP program with parameters appropriate for the type. You must
check all programs that use the associated function modules before
activating the lock object with the new option.

11. Choose with the quick info text Activate.

Result

When you activate the lock object, the two function modules
ENQUEUE_<lockobjectname> and DEQUEUE_<lockobjectname> are
generated from its definition to set and release locks.

You can find information about the activation flow in the activation log, which
you can display with Utilities → Activation Log. If errors occur during
activation, the system displays the activation log automatically.

Você também pode gostar