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

Custom transaction lock

former_member182337
Participant
0 Likes
2,416

Hello,

We have created a custom transaction and custom tables to update the changes. Everytime a user creates a new entry in the transaction a new request number is updated in the custom table.

 

When two users at a time login to create a new request in the transaction and press the save button, then same request number is created for both of them and the system is not incrementing the request numbers.

TO explain it simple, we need it to be like a sale order. Any no. of users can login to VA01 and on pressing save simultaneously, the system

increments the sale order number by one. I would like a similar lock on this as well.

Can some one give me an idea pls?

1 ACCEPTED SOLUTION
Read only

satyabrata_sahoo3
Contributor
0 Likes
1,831

Use lock on Custom tables before updating in program. use  ENQUEUE_E_TABLE to lock before update and DEQUEUE_E_TABLE to unlock after update.

Hope this helps.

-SS-

9 REPLIES 9
Read only

satyabrata_sahoo3
Contributor
0 Likes
1,832

Use lock on Custom tables before updating in program. use  ENQUEUE_E_TABLE to lock before update and DEQUEUE_E_TABLE to unlock after update.

Hope this helps.

-SS-

Read only

former_member183073
Active Participant
0 Likes
1,831

Hi Prem,

You can just get the request number as you are getting now,

but when updating check the request number again.

if the request number that needs to be entered is same as you have on the screen lock the table and update the record.

else

update the screen with the new request number and flash a message that the number has been updated/modifies with respect to the table entry.

Read only

FredericGirod
Active Contributor
0 Likes
1,831

Hi,

you must use the range number : trans. SNRO

and after used the function : NUMBER_GET_NEXT  ...

you will find a lot of example, codes, ... with the function name

Regards

Fred

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,831

You may not require actually a lock here but yes create one with your custom table to insure an user wont be able to modify the same record than another one;

What you require is a range number :

  • Read some documentation like Number Range at help.sap.com.
  • Manage object and range via SNRO transaction.
  • In your program use NUMBER_GET_NEXT and don't forget COMMIT-WORK.

Also use search tool on range number.

Regards,

Raymond

Read only

Former Member
0 Likes
1,831

Hi Prem,

Could u pls tell me how you create the New request Number .Please provide ur code.

I think u have to do this after Creating the Number Range in TCODE - SNRO than u have to use the FM - NUMBER_GET_NEXT to get the next Number.

i think it will solve ur problem.

Thanks

tarak

Read only

former_member182337
Participant
0 Likes
1,831

Any suggestions?

Read only

former_member184675
Active Participant
0 Likes
1,831

Hi,

In case you're not already doing so, to manage the number increment for your primary key you'd best use a Number Range Object.

So go to TCODE SNRO, create a NO Range Object and an Interval.

Before a user saves the data in your Z table, call FM NUMBER_GET_NEXT. This should not fail in case two users hit SAVE button at the same time.

Then as to the locking issue, you should first create a lock object in tcode SE11 for your table. Let's call it EZTEST. After you have created the lock object, SAP generates 2 FM: ENQUEUE_EZTEST and DEQUEUE_EZTEST. By using these 2 FM you can set a lock and unset it on your Z table with specific primary key(s) value(s).

In order to check if a certain lock has been set on your Z table use FM: ENQUEUE_READ.

There's probably more to say on this subject, but perhaps the info I gave you will give you a first glance on what you should/can do.

Br,

Andrei

Read only

0 Likes
1,831

Thanks to all for your replies.

If locking and unlocking is the way to fix this then i will follow the same. I do not maintain any number range,just increment the request number by one from the database.

@ Andrei - "Before a user saves the data in your Z table, call FM NUMBER_GET_NEXT. This should not fail in case two users hit SAVE button at the same time."

Do you mean to say then by using this FM i do not need to lock and unlock the table ?

Thanks.

Read only

0 Likes
1,831

Hi,

Kinda yes. Correct me if i'm wrong, but you don't actually need to lock the table in Insert because you're only problem is the uniqueness of the primary key.

By using Number Ranges and the above mentioned FM you can guarantee that two users will never get the same primary key value and that, if I'm not mistaken, solves your problem.

-

Andrei