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

locking problem - unique documents with external numbers

Former Member
0 Likes
990

Hello,

I have following problem:

In external system documents are generated with unique numbers. When they come to SAP (via RFC calls) corresponding documents in SAP are created with internal SAP numbering (the external document number is saved in "Ref. Doc No." field).

Recently we had a situation when the external documents were posted twice (with two different internal SAP numbers). There is a check if the document with "Ref. Doc No." already exists in database table but it doesn't work when double posting is performed in very short period of time (the document from first posting is not yet written in DB while the second posting checks if it is already there - in result the second posting is also performed).

I thought about using ENQUEUE/DEQUEUE mechanism but it seems to work only on records which are already in DB table.

Do you have any idea what "lock mechanism" could be used in this case?

1 ACCEPTED SOLUTION
Read only

chaouki_akir
Contributor
0 Likes
747

Boinjour,

You said :

"I thought about using ENQUEUE/DEQUEUE mechanism but it seems to work only on records which are already in DB table."

My point of view is that you can lock an entry that is not already existing in the DB.

Example : in the transaction code se11 try to create a LOCK OBJECT named eztest. During this creation and before saving, open an other sap session and try to create the same object. You will have an error message because a lock already exist.

The entry is locked but does not exist in DB.

"Do you have any idea what "lock mechanism" could be used in this case?"

Create a specific lock object with Lock parameter = a sap field to will correspond to the external number.

==> It will generate 2 function modules (ENQUEUE and DEQUEUE).

In the abap that is integrating incoming data :

add a CALL to the "ENQUEUE" function module ===> try to lock an entry

If the lock was OK (return code of enqueue function module is 0)

Then you continue

Else.

The entry that you are trying to lock is already locked.

ENDIF.

Cordialement,

Chaouki.

It is easy to test :

Cordialement,

Chaouki.

3 REPLIES 3
Read only

naimesh_patel
Active Contributor
0 Likes
747

The locking mechanism will not work if the same number comes twice.

I would suggest:

Save the Reference number in one temporary database table and use it for the validation alongwith the reference number in the actual table.

Process would be:

Start of RFC, Save the Reference in the Temp DB table

Check the reference in the original table (the table in which you are checking right now)

Check the reference in the Temp DB tab

If it fails, give the error otherwise go on and finish the posting in SAP.

Now, after finishing delete the entry from the Temp DB table.

You need to make sure you delete the Temp DB table entry, at all exit points from the RFC FM

Regards,

Naimesh Patel

Read only

chaouki_akir
Contributor
0 Likes
748

Boinjour,

You said :

"I thought about using ENQUEUE/DEQUEUE mechanism but it seems to work only on records which are already in DB table."

My point of view is that you can lock an entry that is not already existing in the DB.

Example : in the transaction code se11 try to create a LOCK OBJECT named eztest. During this creation and before saving, open an other sap session and try to create the same object. You will have an error message because a lock already exist.

The entry is locked but does not exist in DB.

"Do you have any idea what "lock mechanism" could be used in this case?"

Create a specific lock object with Lock parameter = a sap field to will correspond to the external number.

==> It will generate 2 function modules (ENQUEUE and DEQUEUE).

In the abap that is integrating incoming data :

add a CALL to the "ENQUEUE" function module ===> try to lock an entry

If the lock was OK (return code of enqueue function module is 0)

Then you continue

Else.

The entry that you are trying to lock is already locked.

ENDIF.

Cordialement,

Chaouki.

It is easy to test :

Cordialement,

Chaouki.

Read only

0 Likes
747

You are right the ENQUEUE/DEQUEUE works on nonexisting records - the lock object can be even created on structures.

I just tested the solution in wrong way - I thought, when I lock the object the lock is persistent and lasts until it is dequeued. In practice it is automatically removed when the program - which created it - ends (at least it behaves like that with parameters I've used).

thanks