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 statement

VenuAnumayam
Participant
0 Kudos

Hi All,

I'm new to ABAP. Could you please explain whatz the differences b/n

<b>"select *"

"select single *"

"select distinct"</b>.

I appreciate your help.

Thanks

Ravi

1 ACCEPTED SOLUTION

Former Member
0 Kudos

A select statement is used collect records from SAP DB table.

A select single is used to get a unqiue record from the database. You will have to provide all the key fields to fetch the unique records.

a Select distinct is used to get a unique record for the specified condition. All the duplicate values are not considered.

check the below link to know more about select statemetns.

http://help.sap.com/saphelp_470/helpdata/en/fc/eb3983358411d1829f0000e829fbfe/content.htm

Regards,

vara

9 REPLIES 9

Former Member
0 Kudos

A select statement is used collect records from SAP DB table.

A select single is used to get a unqiue record from the database. You will have to provide all the key fields to fetch the unique records.

a Select distinct is used to get a unique record for the specified condition. All the duplicate values are not considered.

check the below link to know more about select statemetns.

http://help.sap.com/saphelp_470/helpdata/en/fc/eb3983358411d1829f0000e829fbfe/content.htm

Regards,

vara

0 Kudos

thnx for the help.

can I say like this:

data: begin of i_records occurs 0,

matnr like mara-matnr,

end of i_records.

select MATNR into i_records-matnr from MCH1

where charg = i_dfbatch-charg.

0 Kudos

Hi,

Instead of

select MATNR into i_records-matnr from MCH1

where charg = i_dfbatch-charg.

use

select MATNR into i_records-matnr from MCH1

where charg = i_dfbatch-charg.

append i_records.

endselect.

or

select MATNR into table i_records from MCH1

where charg = i_dfbatch-charg.

regards,

vara

0 Kudos

hi ravi,

select MATNR into <b>table</b> i_records from MCH1

where charg = i_dfbatch-charg.

or

select MATNR into i_records from MCH1

where charg = i_dfbatch-charg.

endselect.

hope this helps,

do reward if it helps,

priya.

0 Kudos

thnx all guyz for the help. I appreciate that.

laxmanakumar_appana
Active Contributor
0 Kudos

Hi,

Welcome to SDN.

Check this SAP help:

1. SELECT [SINGLE [FOR UPDATE] | DISTINCT] *

2. SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn

3. SELECT [SINGLE [FOR UPDATE] | DISTINCT] (source_text)

Effect

The result of a SELECT statement is itself a table. The SELECT clause, along with the database tables and/or viewsin the FROM clause, specifies the sequence, name, database type, and length of the columns of the result table.

You can also use the optional additions SINGLE or DISTINCT to indicate that only certain lines in the result set should be visible to the program:

SINGLE

The result of the selection should be a single entry. If it is not possible to identify a unique entry, the system uses the first line of the selection. If you use the FOR UPDATE addition, the selected entry is protected against parallel updates from other transactions until the next database commit (see LUW and database lock mechanism). If the database system identifies a deadlock, a runtime error occurs.

DISTINCT

Duplicate entries in the result set are automatically deleted.

Regards

Appana

*Reward Points for helpful answers

0 Kudos

Select * - you are selecting group of records into a corresponding internal table or looping thru the records and doing some processing in which case you need an ENDSELECT.

SELECT SINGLE - selects 1 record only

DISTINCT option - DISTINCT forces a sort on the database server

Former Member
0 Kudos

Hi Ravi,

check this:

SELECT

Reads data from the database.

Syntax

SELECT <result>

INTO <target>

FROM <source>

[WHERE <condition>]

[GROUP BY <fields>]

[HAVING <cond>]

[ORDER BY <fields>].

The SELECT statement consists of a series of clauses, each of which fulfils a certain task:

SELECT clause

Defines the structure of the selection.

Syntax

SELECT [SINGLE]|[DISTINCT]

  • | <si> [AS <a i>]... <agg>( [DISTINCT] <s j>) [AS <a j>]...

The selection can be one line, SINGLE, or several lines. You can eliminate duplicate lines using the DISTINCT addition. To select the entire line, use *, otherwise, you can specify individual columns <si>. For individual columns, you can use aggregate functions <agg>, and assign alternative column names <a i>.

INTO clause

Defines the target area into which the selection from the SELECT clause is written.

Syntax

... INTO [CORRESPONDING FIELDS OF] <wa>

| INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE <itab>

[PACKAGE SIZE <n>]

| INTO (<f1>, <f 2>,...)

The target area can be a flat work area <wa>, an internal table <itab>, or a list of fields <fi>. If you use the CORRESPONDING FIELDS addition, data is only selected if there is an identically-named field in the target area. If you use APPENDING instead of INTO, the data is appended to an internal table instead of overwriting the existing contents. PACKAGE SIZE allows you to overwrite or extend the internal table in a series of packages.The data type of the target area must be appropriate for the selection in the SELECT clause.

FROM clause

The FROM clause determines the database tables from which the data specified in the SELECT clause is read.

Syntax

... FROM [<tab> [INNER]|LEFT [OUTER] JOIN] <dbtab> [AS <alias>]

[ON <cond>]

[CLIENT SPECIFIED]

[BYPASSING BUFFER]

[UP TO <n> ROWS]

You can read both single fields and groups of fields. You link several tables using inner and outer joins to link tables with conditions <cond>, where <tab> is a single table or itself a join condition. The names of database tables may be specified statically or dynamically, and you can use alias names. You can bypass automatic client handling with the CLIENT SPECIFIED addition, and SAP buffering with BYPASSING BUFFER. You can also restrict the number of lines read from the table using the UP TO <n> ROWS addition.

WHERE clause

Restricts the number of lines selected.

Syntax

... [FOR ALL ENTRIES IN <itab>] WHERE <cond>

The condition <cond> may contain one or more comparisons, tests for belonging to intervals, value list checks, subqueries, selection table queries or null value checks, all linked with AND, OR, and NOT. If you use the FOR ALL ENTRIES addition, the condition <cond> is checked for each line of the internal table <itab> as long as <cond> contains a field of the internal table as an operand. For each line of the internal table, the system selects the lines from the database table that satisfy the condition. The result set is the union of the individual selections resulting from each line.

GROUP BY clause

Groups lines in the selection.

Syntax

... GROUP BY <s1> <s 2>

Groups lines with the same contents in the specified columns. Uses aggregate functions for all other columns in each group. All columns of the SELECT clause that are not listed in the GROUP BY clause must be included in aggregate functions.

reward if helpful.

regards,

keerthi.