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: 

Seect statement

Former Member
0 Kudos

Hi to all,

I am working in SAP BI , now i am learning ABAP , i have read abt Select Statemtment in SAP Help , but i didn't get any thing , it would be very knid if any body will explain how to put where condition on that select statement, if possible can u give me some material for that.

thanks in advance.

10 REPLIES 10

Former Member
0 Kudos

hi,

*SELECT Statement (selectstatement)_*

A SELECT statement (select_statement) defines and creates an unnamed result table (see named/unnamed result table).

Syntax

<select_statement> ::= <query_expression> [<order_clause>] [<update_clause>] [<lock_option>] [FOR REUSE]

query expression, order clause, update clause, lock option

Explanation

An OPEN CURSOR statement is not permitted for result tables created with this SELECT statement.

The SELECT statement (select_statement) is subject to the rules that were specified for the DECLARE CURSOR statement and those that were specified for the OPEN CURSOR statement.

Depending on the search strategy, either all the rows in the result table are searched when the SELECT statement (select_statement) is executed and the result table is physically generated, or each next result table row is searched when a FETCH statement is executed, without being physically stored. This must be taken into account for the time behavior of FETCH statements.

Updateable result table

A result table or the underlying base tables are updateable if the query statement satisfies the following conditions:

The QUERY statement comprises a DECLARE CURSOR statement.

The QUERY expression (query_expression) must only comprise one QUERY specification (query_spec).

Only one base table or one updateable view table may be specified in the FROM clause of the QUERY specification (query_spec).

The DISTINCT keyword (see DISTINCT specification), a GROUP clause, or HAVING clause must not be specified.

Expressions must not contain a set function (set_function_spec).

See also the section entitled "Updateable result table" under QUERY statement.

ORDER clause

The ORDER clause specifies a sort sequence for a result table.

UPDATE clause

An UPDATE clause can only be specified for updateable result tables. For updateable result tables, a position within a particular result table always corresponds to a position in the underlying tables and thus, ultimately, to a position in one or more base tables.

If an UPDATE clause was specified, the base tables can be updated using the position in the result table (CURRENT OF <result table name>) by means of an UPDATE statement or a DELETE statement. A lock can be requested for the affected lines of each of the affected base tables using a LOCK statement.

LOCK option

The LOCK option determines which locks are to be set on the read rows.

FOR REUSE

If the result table is to be specified in the from clause of a subsequent QUERY statement, the table should be specified with FOR REUSE keywords. If FOR REUSE is not specified, the reusability of the result table depends on internal system strategies.

Since specifying FOR REUSE increases the response times of some query statements, it should only be specified if it is required to reuse the result table.

See also:

SELECT Statement (named_select_statement)

or

you may refer to ...

http://www.sapdb.org/7.4/htmhelp/40/1312152fa511d3a98100a0c9449261/content.htm

hope this may help you....

regards,

praveena.

Former Member
0 Kudos

hi! Shalini

SELECT select clause [INTO clause] FROM from clause [WHERE cond1] [cond2] [cond3] ....

The SELECT clause select clause describes

Whether the result of the selection should be a single record or a table,

Which columns should be contained in the result,

Whether identical lines may occur in the result.

The INTO clause INTO clause determines the target area into which the selected data is read. If the target area is an internal table, the INTO clause specifies:

Whether you want to overwrite the contents of the internal table or

Append the results to the internal table, and

Whether you want to place the data in the internal table in a single step, or in a series of packages.

The INTO clause can also occur after the FROM clause. You may omit it if

The SELECT clause contains a "*",

The FROM clause does not contain a JOIN, and

You have declared a table work area dbtab in your program using TABLES.

The data, if it exists in the database, is then made available using the table work area dbtab. The statement is then processed further like the SELECT * INTO dbtab FROM dbtab statement, which has the same effect.

If the result of the selection is a table, the data is normally read line by line (for further information, see INTO clause) in a processing loop, which is introduced with SELECT and concludes with ENDSELECT. The loop is processed once for each line that is read. If you want the result of the selection to be a single record, there is no concluding ENDSELECT statement.

The FROM clause FROM clause specifies the source of the data (database tables or views), from which you want to select the data. It also specifies the:

Client handling

Behavior for buffered tables

The maximum number of lines to be read

The database connection, on which the SELECT command is to be executed

The WHERE clause cond1 specifies the conditions that the result of the selection must satisfy. By default, only data from the current client is selected (without you having to specify the client field specifically in the WHERE clause). If you want to select data from several clients, you must use the ... CLIENT SPECIFIED addition in the FROM clause.

Reward me if Useful.

Regards,

Nagulan

aris_hidalgo
Contributor
0 Kudos

Hi Shalini,

Please check transaction ABAPDOCU and you can see ABAP examples ranging from basic statements up to object oriented programming. Also, you can type in 'SELECT' word in the 'KEYWORD' option so you can see how SELECT statement is being used.

Also, we are using the WHERE condition in a select statement to restrict the values being fetched, For example, I only need records which has a company code of '1000' so I will write:


SELECT bukrs belnr gjahr
   FROM bkpf
   INTO (lv_bukrs, lv_belnr, lv_gjahr) 
  WHERE bukrs = '1000'.

Hope it helps...

P.S. Please award points if it helps...

Former Member
0 Kudos

Hi,

SELECT statement (select_statement) defines and creates an unnamed result table (see named/unnamed result table).

Syntax

<select_statement> ::= <query_expression> <order_clause> <update_clause> <lock_option> FOR REUSE

query expression, order clause, update clause, lock option

Explanation

An OPEN CURSOR statement is not permitted for result tables created with this SELECT statement.

The SELECT statement (select_statement) is subject to the rules that were specified for the DECLARE CURSOR statement and those that were specified for the OPEN CURSOR statement.

Depending on the search strategy, either all the rows in the result table are searched when the SELECT statement (select_statement) is executed and the result table is physically generated, or each next result table row is searched when a FETCH statement is executed, without being physically stored. This must be taken into account for the time behavior of FETCH statements.

Updateable result table

A result table or the underlying base tables are updateable if the query statement satisfies the following conditions:

The QUERY statement comprises a DECLARE CURSOR statement.

The QUERY expression (query_expression) must only comprise one QUERY specification (query_spec).

Only one base table or one updateable view table may be specified in the FROM clause of the QUERY specification (query_spec).

The DISTINCT keyword (see DISTINCT specification), a GROUP clause, or HAVING clause must not be specified.

Expressions must not contain a set function (set_function_spec).

See also the section entitled "Updateable result table" under QUERY statement.

ORDER clause

The ORDER clause specifies a sort sequence for a result table.

UPDATE clause

An UPDATE clause can only be specified for updateable result tables. For updateable result tables, a position within a particular result table always corresponds to a position in the underlying tables and thus, ultimately, to a position in one or more base tables.

If an UPDATE clause was specified, the base tables can be updated using the position in the result table (CURRENT OF <result table name>) by means of an UPDATE statement or a DELETE statement. A lock can be requested for the affected lines of each of the affected base tables using a LOCK statement.

LOCK option

The LOCK option determines which locks are to be set on the read rows.

FOR REUSE

If the result table is to be specified in the from clause of a subsequent QUERY statement, the table should be specified with FOR REUSE keywords. If FOR REUSE is not specified, the reusability of the result table depends on internal system strategies.

Since specifying FOR REUSE increases the response times of some query statements, it should only be specified if it is required to reuse the result table.

Thanks,

SReddy.

Former Member
0 Kudos

Hi,

You can just put a cursor on select in abap editor n press F1, help will come.

SELECT result

FROM source

INTO|APPENDING target

[[FOR ALL ENTRIES IN itab] WHERE sql_cond]

.

...

.

Effect

SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.

The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.

The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.

Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.

System Fields

The SELECT statement sets the values of the system fields sy-subrc and sy-dbcnt.

sy-subrc Relevance

0 The SELECT statement sets sy-subrc to 0 for every pass by value to an ABAP data object. The ENDSELECT statement sets sy-subrc to 0 if at least one row was transferred in the SELECT loop.

4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database.

8 The SELECT statement sets sy-subrc to 8 if the FOR UPDATE addition is used in result, without the primary key being specified fully after WHERE.

After every value that is transferred to an ABAP data object, the SELECT statement sets sy-dbcnt to the number of rows that were transferred. If the result set is empty, sy-dbcnt is set to 0.

WHERE sql_cond ... .

Effect:

The addition WHERE restricts the number of lines included in the result set by the statement SELECT, by using a logical expression sql_cond. The logical expression compares the content of columns in the database with the content of ABAP data objects, or with the content of other columns. You can use the optional addition FOR ALL ENTRIES to compare the content of a column in the database with a component with all lines of a structured internal table itab.

The logical expression sql_cond is either true, false, or unknown. The expression is unknown if one of the columns involved in the database contains a null value and is evaluated with another comparison as IS NULL. A line is only included in the resulting set if the logical expression is true.

Except for columns of type STRING or RAWSTRING, all columns of the database tables or views listed after FROM can be evaluated after the WHERE condition. The columns do not necessarily have to be a part of the resulting set.

Reward pts if helpful

Former Member
0 Kudos

Hi,

Follow the following link....you could get some information about the select statement and its significance.

http://help.sap.com/saphelp_nw04/helpdata/en/62/10a423384746e8bf5f15ccdd36e8b1/content.htm

Thanks,

Anon

Former Member
0 Kudos

hi,

A SELECT statement allows retrieving data from the database. Technically, it is a query with an optional clause for ordering the results. The query is either a query specification or a union of query specifications. The result of a SELECT statement is a result set.

example :

SELECT * FROM employees

A Simple SELECT Statement. This SELECT statement selects all columns from the table employees.

SELECT empid AS employee_id, last_name,salary

FROM employees

WHERE salary>5000

ORDER BY empid

A SELECT Statement. This SELECT statement selects data from the columns empid, last_name and salary from the table employees. The statement selects only the employees whose salary is greater than 5,000. In the result table the data from the empid column is presented in a column named EMPLOYEE_ID. The results are sorted by employee ID in ascending order.

WHERE Clause

A where clause is used to filter columns by a search condition.

Syntax

<where clause> ::= WHERE <search condition>.

The result of the <where clause> is a result table consisting of the set of rows for which the evaluation of the <search condition> yields true.

pls reward if helpful,

rgds,

Rajyalakshmi.

Former Member
0 Kudos

SELECT select clause

[INTO clause]

FROM from clause

[WHERE cond1]

[GROUP BY fields1]

[HAVING cond2]

[ORDER BY fields2].

Reads a selection and/or a summary of data from one or more database tables and/or views

SELECT is an Open SQL statement

The SELECT clause select clause describes :

1.Whether the result of the selection should be a single record or a table,

2.Which columns should be contained in the result,

3.Whether identical lines may occur in the result.

The INTO clause INTO clause determines the target area into which the selected data is read. If the target area is an internal table, the INTO clause specifies:

1.Whether you want to overwrite the contents of the internal table or

2.Append the results to the internal table, and

3.Whether you want to place the data in the internal table in a single step, or in a series of packages.

The FROM clause FROM clause specifies the source of the data (database tables or views), from which you want to select the data.

The WHERE clause cond1 specifies the conditions that the result of the selection must satisfy.

The GROUP BY clause fields1 combines groups of lines into single lines of the result table. A group is a set of records with the same value of each database field listed in the GROUP BY clause.

The HAVING clause cond2 specifies conditions for the combined lines of the result table.

The ORDER BY clause fields2 specifies how the records in the result table should be arranged.

The system field SY-DBCNT contains the number of lines read so far ecah time the SELECT statement is executed. After ENDSELECT, SY-DBCNT contains the total number of records read.

The Return Code is set as follows:

SY-SUBRC = 0:

The result table contains at least one record.

SY-SUBRC = 4:

The result table is empty.

SY-SUBRC = 8:

Applies only to SELECT SINGLE FOR UPDATE: You did not specify all of the primary key fields in the WHERE condition. The result table is empty.

Reward if useful.

Dhanashri.

Edited by: Dhanashri Pawar on Jun 10, 2008 10:35 AM

Former Member
0 Kudos

ANS