‎2008 Mar 06 8:26 AM
Hi Experts,
should we put any condition inside select endselect statement like below ?
select var1 var2 from table1 into var3 var4
where var1=.. and var2= .... .
counter=counter + 1.
if counetr > 1.
exit.
endif.
endselect.
thanks and regards,
rohit
‎2008 Mar 06 8:43 AM
Hi,
you can use this logic mention here.or just u just create an internal table an pass the rows to internal table and then check the rows in that internal table.
select var1 var2 from table into corresponding fields of table itab.
data:n_lines(2) type n.
descibe table itab lines n_lines.
if n_lines > 1.
......
endif.
rgds,
bharat.
‎2008 Mar 06 8:28 AM
Hi,
u can keep the condition inside the select...endselect.
rgds,
bharat.
‎2008 Mar 06 8:31 AM
yes u can..but what i get from ur code is dat u only need to fetch a single record, so better option is:
select single....
dis gives better performance...
plz reward points if dis helps..
‎2008 Mar 06 8:35 AM
no
i am checking on the number of rows returned..
if more than one row is returned i have to come out of the select endselect...
for that i am using a counter inside that.
‎2008 Mar 06 8:41 AM
use select single..
it'll retreive only single record so no need to check and exit..
‎2008 Mar 06 9:43 AM
Hi rohit,
I think you should use
select v1 v2 from <tab> into itab
where <condition>.
then count the no of lines.
describe table itab line l_line.
now in l_line u will get the no of line ,from where u can proceed accordingly,
regards,
sudha
‎2008 Mar 06 8:39 AM
Hi,
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.
HAVING clause
Restricts the number of line groups selected.
Syntax
... HAVING <cond>
Like the WHERE clause, but can only be used in conjunction with a GROUP BY clause. The HAVING clause uses conditions to restrict the number of groups selected.
ORDER BY clause
Sorts the lines of the selection.
Syntax
... ORDER BY PRIMARY KEY |... <si> [ASCENDING|DESCENDING]...
Sorts the selection in ascending or descending order according to the primary key or the contents of the fields listed.
Regards,
Priya.
‎2008 Mar 06 8:39 AM
in this case (only 1 entry)
better use :
1) select single
2) up to 1 rows
A.
‎2008 Mar 06 8:41 AM
Hi Rohit,
You not initialized counter.
However I agree with that you are trying to fetch only single record and there is better options for this (like select single) than this coding.
+ An
‎2008 Mar 06 8:43 AM
Hi,
you can use this logic mention here.or just u just create an internal table an pass the rows to internal table and then check the rows in that internal table.
select var1 var2 from table into corresponding fields of table itab.
data:n_lines(2) type n.
descibe table itab lines n_lines.
if n_lines > 1.
......
endif.
rgds,
bharat.
‎2008 Mar 06 9:08 AM
Hi,
If ur requirement is to get singl erecord then go for the following.
1. Select single...
2. Upto 1 row..
Regards,
kavitha.