‎2007 Nov 05 11:23 AM
Hi Friends,
I have a doubt regarding select statement. i want to know when do we use select*, select upto 1 rows, select single, select distinct, where should we put the data fetched from these statements i.e table or work area in each.
Pl give sample of each case.
Regards,
Quavi.
‎2007 Nov 05 11:35 AM
Hi,
when u want to only one record then u will use workarea inorder to put ur data,otherwise if u want more than one record go for internal table
check with examples.
select single * from mara into table wa_mara
where matnr = p_matnr.
select * from mara into wa_mara upto 1 rows
where matnr = p_matnr.
endselect.
select * from mara into table it_mara
where matnr in s_matnr.
Reward if helpful.
Regards,
Nagaraj
‎2007 Nov 05 11:35 AM
Hi,
when u want to only one record then u will use workarea inorder to put ur data,otherwise if u want more than one record go for internal table
check with examples.
select single * from mara into table wa_mara
where matnr = p_matnr.
select * from mara into wa_mara upto 1 rows
where matnr = p_matnr.
endselect.
select * from mara into table it_mara
where matnr in s_matnr.
Reward if helpful.
Regards,
Nagaraj
‎2007 Nov 05 11:37 AM
Hi abdul quavi,
select * will be translated by database interface into a fieldlist of all fields of the databse table fetched from. It is the easiest for coding and does not need any change when database structure changes. But it is quite time and space-consuming because always many non-necessary fields are retrieved and transported.
The destination area may be a work area or an internal table; for table you need addition INTO TABLE.
Use select up to 1 rows if you can not specify the full primary key in WHERE condition but want only one record.
SELECT SINGLE should be used if you can specify the full prinary key in WHERE condition.
You may also look at WIKI, FAQ or GOOGLE. Lots of information avalable.
Regards,
Clemens
‎2007 Nov 05 11:52 AM
Hi Abdul,
We use <b>select *</b> when you require all the fields from the table ..
eg: select * from Mara where matnr = ...
<b>select upto 1 rows</b> when dnt have any all primary key values and still u need a record.
eg:select field1 field2 frome mara where matnr = .. upto 1 rows.
<b>select single</b> is used when u require a single field from all the records in that table..
select single mtext from mara where matnr in s_matnr.
we use<b> select distinct</b> when u require the output to be in sorted order ...
eg SELECT DISTINCT (ftab)
FROM spfli
INTO CORRESPONDING FIELDS OF wa
WHERE
carrid = 'LH'.
WRITE: / wa-cityfrom, wa-cityto.
ENDSELECT.