Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

some eg code needed

Former Member
0 Likes
600

Hi,

someone can send me some sample code showing the use of lock functions before updating any tables..i need the full code ..

pls help me

points will be rewarded

ravi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
563

Hi,

***********lock table

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = 'ZTABLE'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

        • do ur coding (update query)

**************Unlocktable:

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

tabname = 'ZTABLE'.

Go to Se11 you will find the option Lock object (Naming convetion should be followed Example : EZ_ )

Select object type Lock object in the initial screen of the ABAP Dictionary, enter an object name and choose Create. The name of a lock object should begin with an E (Enqueue).

The maintenance screen for lock objects is displayed.

Enter an explanatory short text in the field Short text.

You can then use the short text to find the lock object at a later time, for example with the R/3 Repository Information System.

Enter the name of the primary table of the lock object.

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.

Select the lock mode of the primary table in the field below it.

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

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 is displayed. Select the appropriate table. The lock mode of the primary table is copied as 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 just added with foreign keys. To do this, place the cursor on the name of the secondary table and choose Add.

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

Save your entries.

A dialog box appears in which you have to assign the lock object a development class.

You can (optionally) exclude lock parameters (see lock objects) from the function module generation on the Lock parameter tab page. This makes sense for example if you always want to lock a parameter generically.

To do this, simply deselect the Weight flag for the parameter. The parameter is not taken into consideration in the generated function modules. This parameter is then always locked generically.

The name of a lock parameter is usually the name of the corresponding table field. 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 field Lock parameter.

You can define whether the function modules generated from the lock object should be RFC-enabled on the Attributes tab page.

If you set the Allow RFC flag, the generated function modules can be called from within another system with Remote Function Call.

If you permit Remote Function Calls 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 should therefore check all programs that use the associated function modules before activating the lock object with the new option.

Choose .

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 use the same in the Program

Lock in sap will lock the object only

http://help.sap.com/saphelp_40b/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm

reward marks helpful

3 REPLIES 3
Read only

Former Member
0 Likes
564

Hi,

***********lock table

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = 'ZTABLE'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

        • do ur coding (update query)

**************Unlocktable:

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

tabname = 'ZTABLE'.

Go to Se11 you will find the option Lock object (Naming convetion should be followed Example : EZ_ )

Select object type Lock object in the initial screen of the ABAP Dictionary, enter an object name and choose Create. The name of a lock object should begin with an E (Enqueue).

The maintenance screen for lock objects is displayed.

Enter an explanatory short text in the field Short text.

You can then use the short text to find the lock object at a later time, for example with the R/3 Repository Information System.

Enter the name of the primary table of the lock object.

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.

Select the lock mode of the primary table in the field below it.

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

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 is displayed. Select the appropriate table. The lock mode of the primary table is copied as 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 just added with foreign keys. To do this, place the cursor on the name of the secondary table and choose Add.

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

Save your entries.

A dialog box appears in which you have to assign the lock object a development class.

You can (optionally) exclude lock parameters (see lock objects) from the function module generation on the Lock parameter tab page. This makes sense for example if you always want to lock a parameter generically.

To do this, simply deselect the Weight flag for the parameter. The parameter is not taken into consideration in the generated function modules. This parameter is then always locked generically.

The name of a lock parameter is usually the name of the corresponding table field. 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 field Lock parameter.

You can define whether the function modules generated from the lock object should be RFC-enabled on the Attributes tab page.

If you set the Allow RFC flag, the generated function modules can be called from within another system with Remote Function Call.

If you permit Remote Function Calls 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 should therefore check all programs that use the associated function modules before activating the lock object with the new option.

Choose .

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 use the same in the Program

Lock in sap will lock the object only

http://help.sap.com/saphelp_40b/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm

reward marks helpful

Read only

Former Member
0 Likes
563

Ravi,

I have one simple example and it will show what is lock objects exactly.

See the program :

&----


*& Report ZTEST_LOCK1

*&

&----


*&

*&

&----


REPORT ZTEST_LOCK1.

data i_plaf like plaf occurs 0 with header line.

start-of-selection.

select * from plaf into table i_plaf

where plnum = '0000005432'.

loop at i_plaf.

CALL FUNCTION 'ENQUEUE_EMPLAFE'

EXPORTING

  • MODE_PLAF = 'E'

  • MANDT = SY-MANDT

PLNUM = i_plaf-plnum

  • X_PLNUM = ' '

_SCOPE = '3'

  • _WAIT = ' '

  • _COLLECT = ' '

  • EXCEPTIONS

  • FOREIGN_LOCK = 1

  • SYSTEM_FAILURE = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

break sy-uname.

CALL FUNCTION 'LOESCHEN_PLANAUFTRAG'

EXPORTING

  • ECM61M =

  • ECM61W =

EPLAF = I_plaf

  • MONTX =

  • MDVL_FLAG = XFLAG

  • RM_CONF = ' '

  • APO_PROC = ' '

  • EMT61D =

  • ECM61B =

  • USE_COLLECTIVE_UPDATE = ' '

  • LAST_ORDER = ' '

  • TABLES

  • MDSBX =

  • MDPMZ =

  • EXCEPTIONS

  • UNDEFINED_INTERFACE = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'DEQUEUE_EMPLAFE'

  • EXPORTING

  • MODE_PLAF = 'E'

  • MANDT = SY-MANDT

  • PLNUM =

  • X_PLNUM = ' '

  • _SCOPE = '3'

  • _SYNCHRON = ' '

  • _COLLECT = ' '

.

endloop.

Ravi, Goto se11 ,use PLAF Table -> get one number from PLNUM field.

keep the Plnum field in where clause in select query.

now run the program ,already i setup break point after lock of planned order.

once you are in debugging,then use MD12 Transaction ( Change Planned order),enter planned order number(what ever you use number in the program,use same number in MD12 Transaction)-> and see the results.

you get message planned order number locked.

basically the program does it deletes the planned order ,before deleteing i am just locking planned order number.

do not use this program anywhere except dev system.

Thanks

Seshu