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: 

please clarify my doubt

Former Member
0 Kudos

what is the difference between SY-UCOMM & OK_CODE?

and what is the difference between SELECT SINGLE AND SELECT UPTO 1 ROWS? we can mention 'where' condition in both the cases. if we dont mention 'where' condition, by default the 'select single' statement will select 1 row from the database in this case what is the difference. which one of these statements will improve performance? please clarify my doubt.

5 REPLIES 5

Former Member
0 Kudos

Hi,

Got from a link

<b><u>Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS</u></b>

A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement.

So what's the difference between using 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' statement ?

If you're considering the statements

SELECT SINGLE field INTO w_field FROM table.

and

SELECT field INTO w_field FROM table UP TO 1 ROWS. ENDSELECT.

then looking at the result, not much apart from the extra ENDSELECT statement. Look at the run time and memory usage and they may be worlds apart.

Why is this ?? The answer is simple.

The <b>'SELECT SINGLE'</b> statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

The <b>'SELECT .... UP TO 1 ROWS'</b> statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

Get the difference ??

If not, here is a good example, credit for this example goes to Richard Harper, a friend of mine on sapfans.com :

Create a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also create a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010.

Then run the program shown below:

Code: 
Report Z_Difference 
       Message-id 38 
       Line-Size  80 
       Line-Count 0 
       No Standard Page Heading. 
* 
Start-Of-Selection. 
					
  Data: w_Single type Posnr, 
        t_Rows   type standard table of Posnr 
                 initial size 0 
                 with header line. 
* 
  Select single Posnr 
    from zDifference 
    into w_Single. 
* 
  Select Posnr 
    into table t_Rows 
    from zDifference 
   up to 1 rows 
   order by Posnr descending. 
* 
   Write 😕 'Select single:', w_Single. 
   Skip 1. 
   Write 😕 'Up to 1 rows :'. 
   Loop at t_Rows. 
        Write t_Rows. 
   EndLoop

.

You should see the output:

Select single: 000001

Up to 1 rows : 000010

The first 'SELECT' statement selected the first record in the database according to any selection criterion in the 'WHERE' clause. This is what a 'SELECT SINGLE' does. The second 'SELECT' has asked the database to reverse the order of the records before returning the first row of the result.

In order to be able to do this the database has read the entire table, sort it and then return the first record. If there was no ORDER BY clause then the results would have been identical (ie both '000001') but the second select if given a big enough table to look at would be far slower.

Note that this causes a problem in the Extended Program Check if the full key is not specified in a 'SELECT SINGLE'. Replacing the 'SELECT SINGLE' by an "UP TO 1 ROWS" will give the same exact results without any warning but the program will run slower and consume more memory. This is a good example of a warning that we should ignore... considering you are sure of what you are doing !!

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap faqs.faq

Former Member
0 Kudos

Hi,

When you say SELECT SINGLE, it means that you are expecting only one row to be present in the database for the condition you're going to specify in the WHERE clause. so that means, you will have to specify the primary key in your WHERE clause. Otherwise you get a warning.

SELECT UP TO 1 ROWS is used in cases where you just want to make sure that there is at least one entry in the database table which satisfies your WHERE clause. Generally, it is meant to be used for existence-check. You may not want to really use the values returned by the SELECT statement in this case (thought this may not necessarily be so). In thise part of primary key fields will participate in the where clause.

And in each case the database optimizer may choose a different strategy to retrieve the data.

Rgds,

Vijay

Former Member
0 Kudos

Hi,

SY-UCOMM is a system field ( see structure SYST ), usually used in list and selection-screen processing. OK_CODE is a field in dynpro screen processing. In the both cases, the meaning is the function code triggered by event/PAI.

Svetlin

Former Member
0 Kudos

Hi Swathi,

SY_UCOMM is a ABAP System Filed that contains the Function code when the user performs some action.

For Example:

DATA: OK_CODE LIKE SY-UCOMM.

When the user chooses a pushbutton or performs some action, the PAI event is triggered. The function code of the pushbutton is assigned to the screen field OK_CODE, which is then passed onto the ABAP field with the same name.

so if u execute the statement

write:/ ok_code. (or)

write:/ sy-ucomm.

The result will be the same.

Thanks&Regards

Former Member
0 Kudos

If your doubt has been clarified, please give award points accordingly.

Svetlin