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: 

Select SINGLE vs READ statements

former_member577909
Participant
1,866

how does the Select SINGLE statement works and How does the READ Statement works .. and please give the examples of each

Thankyou

8 REPLIES 8

jayanthi_jayaraman
Active Contributor
0 Kudos
361

Hi,

Select single is used to fetch a single record from database table.Read is used to fetch a single record from internal table.

Former Member
0 Kudos
361

Hello Bhaskar,

SELECT SINGLE statement is used to read one record from a database table.

The READ statement is used to read a record from an internal table.

Regards,

Anand Mandalika.

Former Member
0 Kudos
361

For READ have a look at below link.

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm

SELECT SINGLE is a construct designed to read database records with primary key. SELECT SINGLE returns the first matching row for the given condition and it may not be unique, if there are more matching rows for the given condition.

SELECT SINGLE field

INTO w_field

FROM table.

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers

anversha_s
Active Contributor
0 Kudos
361

hi,

This situation occurs mostly inside the loops.

suppose an internal table. ITAB.

1. Never use select statements inside loops.

2. always use READ.

eg:

<i>select single.</i>

ex 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, 

* 
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.

<i>READ</i>

Reading records with keys

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm

Reading lines with Index

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3730358411d1829f0000e829fbfe/content.htm

rgds

Anver

former_member69765
Contributor
0 Kudos
361

Select single starts searching from the row 1 and picks the 1st record that matches ur selection criteria.

e.g . Select single * from bkpf where bukrs = '0001'.

If there are 100 docs in BKPF table .. it will select the 1st record.

Read (I assume u are referring to read from Internal table) statement also reads the 1st record from ur internal table that matches the key specified in ur read statement.

read table itab into wa with key bukrs = '0001'.

same as explained.

Cheers. If there is something else.. feel free to come

Former Member
0 Kudos
361

Select single - is used for extacting one record form SAP-Data base table .

Read is used only for extracting single record from internal table with in ABAP program.

Ex:-

tables : T001w.

Select single * from T001W where WERKS = 'A008'.

write 😕 t001w-werks.

Ex read :-

data : int_plants like t001w occurs 0 with header line.

Select * from T001W into table int_plants .

read table int_plants with key werks = 'A008'.

If Sy-subrc eq 0 .

write 😕 int_plants-werks.

endif.

Ramvelu

Former Member
0 Kudos
361

Hi Bhaskar

Both statements are used for reading one record.

SELECT SINGLE -> DB Table

READ -> Internal Table

Eg:

SELECT SINGLE <FLD1> <FLD2> INTO (<WA>-FLD1, <WA>-FLD2)
              FROM (DBTABLE)
              WHERE <COND>.

READ <ITAB> INTO <WA> WITH KEY <FLD1> = ....
                                                          <FLD2> = ....

One more major difference is we can not use comparision operator other than EQUAL and NOT EQUAL with READ statements, whereas we can use the same with SELECT SINGLE.

Hope this helps.

Kind Regards

Eswar

Former Member
0 Kudos
361

The SELECT SINGLE statement is used for accessing matching records (wen a conditon is specified) from the underlying database tables, one record at once...

Whereas , the read statement is used to reference a record from an internal table.. Any specific record can be fetched using the INDEX addition AND/OR a matching codition ..

The select single statement is more efficient than the select statement..and it fetches records (one by one) in sequence from the DB table...

Regards

Pankaj