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

Enqueue and Dequeue before updating Database table

Former Member
0 Likes
22,627

Hi all,

We are updating database tables using INSERT, MODIFY and UPDATE statements. Since many people will be running the application at the same time we need to lock the table before updating database table. So we need to use ENQUEUE and DEQUEUE functionality for this purpose.

Can any plz explain what are the steps we should follow now?

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
7,916

HI FIRST GO TO SE11 AND CREATE THE LOCK OBJECTS FOR YOUR DATABASE TABLE.

AFTER CREATING THE LOCK OBJECTS THE ENQUE AND DEQUE FUNCTION MODULES WILL BE AUTOMATICALLY GENERATED BY SYSTEM.

CALL ENQUE BEFORE FIRING INSERT , MODIFY OR DELETE QUERIES.

CALL DEQUE AFTER THE QUERIES...THIS WILL SOLVE YOUR PROBLEM...

4 REPLIES 4
Read only

Former Member
0 Likes
7,917

HI FIRST GO TO SE11 AND CREATE THE LOCK OBJECTS FOR YOUR DATABASE TABLE.

AFTER CREATING THE LOCK OBJECTS THE ENQUE AND DEQUE FUNCTION MODULES WILL BE AUTOMATICALLY GENERATED BY SYSTEM.

CALL ENQUE BEFORE FIRING INSERT , MODIFY OR DELETE QUERIES.

CALL DEQUE AFTER THE QUERIES...THIS WILL SOLVE YOUR PROBLEM...

Read only

Former Member
0 Likes
7,916

Hi,

In SE11 create lock object for your Ztable . (starting with E followed by table name)Give table name in tab table.

Now FM Enqueue_e(table name) and DEQUEUE_e(table name) are created.

Use these to lock table data. Then save records, release lock on table.

Regards,

Mrunal

Read only

Former Member
0 Likes
7,916

Hi,

Any Database access should carefully handled as multiple applications may be accessing the database at the same time. To read a record from the database you don't need to implement a lock, but to write you need not only locks but also ideally should use the Update Function Modules to comply SAP "All or Nothing" Principle. This will prevent data inconsistency of the database and the data will be proper state. You need to use the COMMIT WORK and ROLLBACK WORK in you code to handle the consistency part of the database.

The best design approach would be seperate the Database Layer completely from the business layers. This will make your code robust and easy to maintain.

As, for the Locking Concepts, you will get multiple resources from SDN as how to create Locks and implement the Locking modules in your code. But more than that what matters is why and how to implement the SAP Locking concepts to make your application run better.

Have a look at the following link

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

Hope this helps.

Thanks,

Samantak.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
7,916

Some documents of interest :

- [SAP Lock Concept |http://help.sap.com/saphelp_nw70/helpdata/en/7b/f9813712f7434be10000009b38f8cf/frameset.htm]

- [Updates in the SAP System (BC-CST-UP)|http://help.sap.com/saphelp_nw04/helpdata/en/5f/6f8337dd34ca76e10000009b38f8cf/frameset.htm]

Steps
- lock records (FM ENQUEUExxx), manage error code
- select data
- check data
- prepare update in internal table
if ok
- CALL FUNCTION Zxxxx IN UPDATE TASK
- COMMIT WORK (will also unlock)
if ko
- ROLLBACK WORK or FM DEQUEUExxx

Regards,

Raymond