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

re: what is difference between sap locking and database locking

Former Member
0 Likes
3,514

hi,

what is difference between sap locking and database locking. Iam locked the table mara by using lock objects.

But iam unable to unlock the mara table. I give u the coding. Please check it.

REPORT zlock .

CALL FUNCTION 'ENQUEUE_EZTEST3'

EXPORTING

MODE_MARA = 'S'

MANDT = SY-MANDT

MATNR = 'SOU-1'.

call transaction 'MM02'.

CALL FUNCTION 'DEQUEUE_EZTEST3'

EXPORTING

mode_mara = 'E'

mandt = sy-mandt

matnr = 'SOU-1'.

IF sy-subrc = 0.

WRITE: 'IT IS unlocked'.

ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,224

Hi Paluri

Here is the difference between SAP locks and Database locks, i will try to find the solution to your code.

Regards

Ashish

Database Locks: The database system automatically sets database locks when it receives change statements (INSERT, UPDATE, MODIFY, DELETE) from a program. Database locks are physical locks on the database entries affected by these statements. You can only set a lock for an existing database entry, since the lock mechanism uses a lock flag in the entry. These flags are automatically deleted in each database commit. This means that database locks can never be set for longer than a single database LUW; in other words, a single dialog step in an R/3 application program.

Physical locks in the database system are therefore insufficient for the requirements of an R/3 transaction. Locks in the R/3 System must remain set for the duration of a whole SAP LUW, that is, over several dialog steps. They must also be capable of being handled by different work processes and even different application servers. Consequently, each lock must apply on all servers in that R/3 System.

SAP Locks:

To complement the SAP LUW concept, in which bundled database changes are made in a single database LUW, the R/3 System also contains a lock mechanism, fully independent of database locks, that allows you to set a lock that spans several dialog steps. These locks are known as SAP locks.

The SAP lock concept is based on lock objects. Lock objects allow you to set an SAP lock for an entire application object. An application object consists of one or more entries in a database table, or entries from more than one database table that are linked using foreign key relationships.

Before you can set an SAP lock in an ABAP program, you must first create a lock object in the ABAP Dictionary.

15 REPLIES 15
Read only

Former Member
0 Likes
2,225

Hi Paluri

Here is the difference between SAP locks and Database locks, i will try to find the solution to your code.

Regards

Ashish

Database Locks: The database system automatically sets database locks when it receives change statements (INSERT, UPDATE, MODIFY, DELETE) from a program. Database locks are physical locks on the database entries affected by these statements. You can only set a lock for an existing database entry, since the lock mechanism uses a lock flag in the entry. These flags are automatically deleted in each database commit. This means that database locks can never be set for longer than a single database LUW; in other words, a single dialog step in an R/3 application program.

Physical locks in the database system are therefore insufficient for the requirements of an R/3 transaction. Locks in the R/3 System must remain set for the duration of a whole SAP LUW, that is, over several dialog steps. They must also be capable of being handled by different work processes and even different application servers. Consequently, each lock must apply on all servers in that R/3 System.

SAP Locks:

To complement the SAP LUW concept, in which bundled database changes are made in a single database LUW, the R/3 System also contains a lock mechanism, fully independent of database locks, that allows you to set a lock that spans several dialog steps. These locks are known as SAP locks.

The SAP lock concept is based on lock objects. Lock objects allow you to set an SAP lock for an entire application object. An application object consists of one or more entries in a database table, or entries from more than one database table that are linked using foreign key relationships.

Before you can set an SAP lock in an ABAP program, you must first create a lock object in the ABAP Dictionary.

Read only

Former Member
0 Likes
2,224

Hi,

Try with this function module

CALL FUNCTION 'ENQUEUE_EMMARAS'

EXPORTING

MATNR = 'material number'

EXCEPTIONS

FOREIGN_LOCK = 2

SYSTEM_FAILURE = 3.

call transaction 'MM02'.

CALL FUNCTION 'DEQUEUE_EMMARAS'

EXPORTING

MODE_MARA = 'S'

MANDT = SY-MANDT

MATNR = 'material number'

X_MATNR = ' '

_SCOPE = '3'

_SYNCHRON = ' '

_COLLECT = ' '.

IF sy-subrc = 0.

WRITE: 'IT IS unlocked'.

ENDIF.

Cheers,

Sasi

Read only

0 Likes
2,224

Hi,

Continues to my previous posting,

Database lock is a physical and SAP lock is a logical one.

Cheers,

Sasi

Read only

Former Member
0 Likes
2,224

Hi Paluri

To unlock table MARA (or any table): use txn SM12, supply your table name, client and user name and you will get the list of lock entries. Here, you can manage to delete them.

Regards

Ashish

Read only

Former Member
0 Likes
2,224

hi friends,

still iam unable to unlock the lock object

Read only

Former Member
0 Likes
2,224

ashish,

i want to unlock the object by using function module.

Read only

Former Member
0 Likes
2,224

Hi Paluri

Atleast release the lock using SM12 first so that you can try locking and unlocking again with whatever modified code you have. I will also try to see for the function module options

Cheers

Ashish

Read only

0 Likes
2,224

To unlock objects use fm DEQUEUE_ALL

for material master DEQUEUE_MATERIAL_MASTER.

regds

gv

Read only

andreas_mann3
Active Contributor
0 Likes
2,224

Hi Paluri,

try that:

data sptab type rstable.
  sptab-TABNAME = 'MARA'.
  concatenate sy-mandt 'SOU-1' into sptab-VARKEY.
*lock
  CALL FUNCTION 'ENQUEUE_E_TABLE'
       EXPORTING
            TABNAME        = sptab-TABNAME
            VARKEY         = sptab-VARKEY
       EXCEPTIONS
            FOREIGN_LOCK   = 1
            SYSTEM_FAILURE = 2
            OTHERS         = 3.
...
*unlock
CALL FUNCTION 'DEQUEUE_E_TABLE'           
     EXPORTING                            
          TABNAME = RSTABLE-TABNAME       
          VARKEY  = RSTABLE-VARKEY.       

Andreas

Read only

Former Member
0 Likes
2,224

Hi Paluri

As already pointed out by someone, use can use DEQUEUE_ALL or DEQUEUE_MATERIAL_MASTER

But beware of using dequeue_all, you can very well imagine what may happen........

You can search for more function modules using keyword dequeue in SE37.

Regards

Ashish

Read only

Former Member
0 Likes
2,224

ashish,

what is the ARGUMENT IN SM12. IT IS NOT ACCEPTING MATERIAL NUMBER

Read only

Former Member
0 Likes
2,224

Hi Paluri

Don't supply lock argument, just supply table name, client and username (id) and press list, you will get the whole list.

Regards

Ashish

Read only

Former Member
0 Likes
2,224

Hi,

chek out this link for Database locking:

http://www.sapdevelopment.co.uk/dictionary/lock_enqueue.htm

Regards,

Anjali

Read only

Former Member
0 Likes
2,224

Hi Paluri

Please look at the link below for Lock Objects help:

http://help.sap.com/saphelp_nw04/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/frameset.htm

In this link, the topic 'Function modules for lock objects' may be of your interest, especially the parameter '_synchron'.

The DEQUEUE function module also has the parameter _SYNCHRON. If X is passed, the DEQUEUE function waits until the entry has been removed from the lock table. Otherwise it is deleted asynchronously, that is, if the lock table of the system is read directly after the lock is removed, the entry in the lock table may still exist.

Cheers

Ashish

Read only

Former Member
0 Likes
2,224

You really shouldn't be doing it this way. Transaction MM02 will lock anything it needs to just before it saves it and release it immediately after. If you lock it using your code, the material will be locked for as long as you are in the transaction. If you are called away, this could be a long time. In the meantime, no one else will be able to change it.

It's always best to leat SAP handle locking its own objects.

Rob