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

SINGLE FOR UPDATE

Former Member
0 Likes
1,267

Hi,

can anybody tell me the user of "SINGLE FOR UPDATE" keywords in SELECT statement?

Priya

5 REPLIES 5
Read only

Former Member
0 Likes
714

Hi,

Please check this for SAP Help ...

If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used.

An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.

Note

When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.

Regards,

Ferry Lianto

Read only

amit_khare
Active Contributor
0 Likes
714

As given by SAP -

... SINGLE [FOR UPDATE]

If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used. The addition ORDER BY can also not be used.

An exclusive <b>LOCK</b> can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.

LOCK - Lock protected data from being accessed by several users at the same time as a shared lock or as exclusive locks

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
714

SINGLE FOR UPDATE addition to SELECT, select a single record into the specified workarea. Based on sy-subrc 0 which happens only if there is 1 record matching the criteria, you can use the actual UPDATE dbtable statement following it

Read only

former_member194669
Active Contributor
0 Likes
714

Update is addition for SINGLE .

if you are using "select single for update" then the selected entry is protected against parallel updates from other transactions until the next database commit.

aRs

Read only

rajasekhar_matukumalli3
Active Participant
0 Likes
714

Hi,

SAP Explanation:

"An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering."

When u are accessing a critical data which u dont want others to change while u r acessing, you make use of FOR UPDATE.

This is recommended to be mostly used with SINGLE, because u do not want to hold a bunch of records/values with out being changed by other users.

Hope this answers ur question.

Enjoy SAP

Rajasekhar