Application Development 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: 

ENQUEUE & DEQUEUE

former_member182371
Active Contributor
0 Kudos

Hi,

i´m developing a program that needs to update a field(status) in a ztable1 and afterwads insert a register in ztable2.

what i´ve done so far is:

1.- enqueue ztable1

2.- update field ztable1-status

3.- dequeue ztable1

4.- enqueue ztable2

5.- insert entry in ztable2

6.- dequeue ztable2

would it be best doing 1 4 2 5 3 6 instead?.

Any suggestion would be greatly appreciated.

Best regards.

1 ACCEPTED SOLUTION

Former Member

Hi Calsadillo,

The enqueue concept is used to prevent two or more processes attempting to update a database record at the same time. Without this, two processes could select a record, apply different changes and then update the database one after the other. In this case, the updates applied by the first process would be overwritten by the updates of the second process.

So, my first comment would be is that you do not need to enqueue ztable2 at all if you are performing an SQL INSERT command.

The second comment would be, when do you select the data to be updated for ztable1? Just prior to this select you should enqueue the data for ztable1. This means that if another process wants to access this data for update then then its enqueue will fail, and it should not select the data. Then you should dequeue the data for ztable1 after you have performed the update. (you can see how SAP uses this logic by going into change a sales order in VA02, and then with another session trying to do the same - you will be blocked).

So the sequence would be more like:

1. Enqueue ztable1

2. Select ztable1 data for update

3. update ztable1 status

4. insert entry into ztable2

5. perform commit work (which will automatically dequeue ztable1)

6. Dequeue ztable1 (just for thoroughness)

Hope that helps.

Brad

1 REPLY 1

Former Member

Hi Calsadillo,

The enqueue concept is used to prevent two or more processes attempting to update a database record at the same time. Without this, two processes could select a record, apply different changes and then update the database one after the other. In this case, the updates applied by the first process would be overwritten by the updates of the second process.

So, my first comment would be is that you do not need to enqueue ztable2 at all if you are performing an SQL INSERT command.

The second comment would be, when do you select the data to be updated for ztable1? Just prior to this select you should enqueue the data for ztable1. This means that if another process wants to access this data for update then then its enqueue will fail, and it should not select the data. Then you should dequeue the data for ztable1 after you have performed the update. (you can see how SAP uses this logic by going into change a sales order in VA02, and then with another session trying to do the same - you will be blocked).

So the sequence would be more like:

1. Enqueue ztable1

2. Select ztable1 data for update

3. update ztable1 status

4. insert entry into ztable2

5. perform commit work (which will automatically dequeue ztable1)

6. Dequeue ztable1 (just for thoroughness)

Hope that helps.

Brad