Select Statement Doubt
Moderator message: Please use meaningful subject in future
Hi,
I've a requirement that I need to get a record from EREV table for a Purchase Requisition no. based on Latest Version No. (REVNO. ) at a single shot.
I hav used the following code but i dint get desired values.
Select EDOKN
FGNAM
FGDAT
REVNO
from EREV into ls_erev
where edokn eq p_edokn and
revno eq (select Max(revno) from erev)).
Any body pl help me.
-Rajiv
Edited by: Vaddepati on Dec 3, 2008 11:01 AM
Edited by: Matt on Dec 3, 2008 10:03 AM
Hi veddapati,
Your sequence of using the fields in Select statement is wrong...thats why, you are not getting the required output..
You should select revno in the select statement before FGNAM as it is present in the table..
Please modify your select statement like this..... ::
Select EDOKN
REVNO
FGNAM
FGDAT
from EREV into ls_erev
where edokn eq p_edokn and
revno eq (select Max(revno) from erev)).
Hope it will solve your problem
Regards,,
Nikita
Edited by: Nikita Jain on Dec 3, 2008 2:29 PM
Similar Messages
-
Order by in select statement doubt
Hi ,
i created one table tab name is one column
tab
name
5
4
11
1
2
a
b
aa
select * from tab order by name;
and i got the result like this
name
1
11
2
4
5
a
aa
b
but i want to sort numbers as numeric order and name as alphabatic order
means like order below
name
1
2
4
5
11
a
aa
b
how can do in a single oracle query can anyone help me .
with regardsOne method..
SQL> select c1
2 from test
3 order by decode(translate(c1,'a0123456789','a'),
4 null,to_number(c1),null) nulls last,
5 c1
6 /
C1
1
2
11
1b
a
a1
b
7 rows selected.
Message was edited by:
jeneesh
No need of TRIM.Thanks Rob... -
Doubt about Select statement.
Hi folks!!
I have a few doubts about the select statements, it may be a silly things but its useful for me.
what is difference between below statment.
1)SELECT * FROM TABLE.
2)SELECT SINGLE * FROM TABLE
3)SELECT SINGLE FROM TABLE.
Hope i will get answer,thanks in advance.
Regards
Richie..Hi,
try this and if possible use sap help.i mean place the cursor on select and press F1.
Types of select statements:
1. select * from ztxlfa1 into table it.
This is simple select statement to fetch all the data of db table into internal table it.
2. select * from ztxlfa1 into table it where lifnr between 'V2' and 'V5'.
Thisis using where condition between v2 and v5.
4. select * from ztxlfa1 where land1 = 'DE'. "row goes into default table work Area
5. select lifnr land1 from ztxlfa1
into corresponding fields of it "notice 'table' is omitted
where land1 = 'DE'.
append it.
endselect.
Now data will go into work area. and then u will add it to internal table by
append statement.
6. Table 13.2 contains a list of the various forms of select as it is used with internal tables and their relative efficiency. They are in descending order of most-to-least efficient.
Table 13.2 Various Forms of SELECT when Filling an Internal Table
Statement(s) Writes To
select into table it Body
select into corresponding fields of table it Body
select into it Header line
select into corresponding fields of it Header line
7. SELECT VBRK~VBELN
VBRK~VKORG
VBRK~FKDAT
VBRK~NETWR
VBRK~WAERK
TVKOT~VTEXT
T001~BUKRS
T001~BUTXT
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
FROM VBRK
INNER JOIN TVKOT ON VBRKVKORG = TVKOTVKORG
INNER JOIN T001 ON VBRKBUKRS = T001BUKRS
WHERE VBELN IN DOCNUM AND VBRK~FKSTO = ''
AND VBRK~FKDAT in date.
Select statement using inner joins for vbrk and t001 and tvkot table for this case based on the conditions
8. SELECT T001W~NAME1 INTO TABLE IT1_T001W
FROM T001W INNER JOIN EKPO ON T001WWERKS = EKPOWERKS
WHERE EKPO~EBELN = PURORD.
here selecting a single field into table it1_t001winner join on ekpo.
9. SELECT BUKRS LIFNR EBELN FROM EKKO INTO CORRESPONDING FIELDS OF IT_EKKO WHERE EBELN IN P_O_NO.
ENDSELECT.
SELECT BUTXT FROM T001 INTO IT_T001 FOR ALL ENTRIES IN IT_EKKO WHERE BUKRS = IT_EKKO-BUKRS.
ENDSELECT.
APPEND IT_T001.
here I am using for all entries statement with select statement. Both joins and for all entries used to fetch the data on condition but for all entries is the best one.
10. SELECT AVBELN BVTEXT AFKDAT CBUTXT ANETWR AWAERK INTO TABLE ITAB
FROM VBRK AS A
INNER JOIN TVKOT AS B ON
AVKORG EQ BVKORG
INNER JOIN T001 AS C ON
ABUKRS EQ CBUKRS
WHERE AVBELN IN BDOCU AND AFKSTO EQ ' ' AND B~SPRAS EQ
SY-LANGU
AND AFKDAT IN BDATE AND AVBELN EQ ANY ( SELECT VBELN FROM
VBRP WHERE VBRP~MATNR EQ ITEMS ).
Here we are using sub query in inner join specified in brackets.
Thanks,
chandu. -
HI Friends,
i have a requirement to select matnr,werks and mmsta from marc table.where i have input of matnr and mmsta.
The matnr in the marc table having 2 werks with different mmsta.
i was asked to select matnr not having mmsta 40.
but in marc table there is same matnr with two mmsta 37 and 40.
i want a select statement which should not pick matnr having 40.
my select statement was
select matnr werks mmsta into itab from marc
where matnr in fpso_matnr and mmsta in fpso_mmsta.
this does not work for the above condition.
please suggest me a correct statement..
Thanks,
Gokulselect matnr werks mmsta into itab from marc
where matnr in fpso_matnr and mmsta in fpso_mmsta
and mmsta NE 40.
ill this not work ?
MARC is plant data.. so I guess u need to give werks also...
Edited by: jackandjay on Dec 19, 2007 12:02 PM -
Select statement operators in ecc 6.
Hi Experts,
I have a small doubt about the '>=' ( greater than or equal to ) operator usage in select statement. Is this operator by any chance perform not as desired in ECC 6.0. Is it a good option to use 'GE' instead of '>='. ?
It may sound a bit awkward, but still I would like to know. I am facing a situation, which could be related to this. An early response would be highly appreciated.
I would request,you NOT TO REPLY with links/explanations which says how to use select statement. Only answer if you have the answers related to this query.
Regards,
Sandipan>
Jaideep Sharma wrote:
> Hi,
> The only difference is GE will take a little more time than >= as system need to convert the keyword into actual operator when fetching data from Database.
>
> KR Jaideep,
????? Every Open SQL statements is translated to the SQL slang the underlying database is talking regardless if you type GE or >=
If the result differs using >= or GE i would open a call at SAP instead of asking in SDN. -
Parsing an OPEN SQL select statement
Hi all,
I want to parse an open SQL select statement to get the list of tables and the corresponding fields in the select statement.
Is there some ABAP-internal syntax from the SAP Database Interface that does this? or is the only option to do this is to manually break the statement?
Thanks.
GirishHi,
I doubt if there is something like that available to use. It think you will have to write a parser for yourself.
Regards -
Time issue of select statement
Hi friends,
I have a doubt about select single statement in this particular statement below.
i have the code which goes this way.
loop at itab.
concatenate *year *materail no * item type into dummy variable.
select single dmbtr from bsis into itab-dmbtr where xref3 = dummy variable and belnr = itab-migodoc and gjahr = itab-mjahr and hkont = '0000123'.
clear dummy variable.
modify itab.
endloop.
the bsis table has around 4,000,000 records.
The report when executed goes smoothly till the point where the above select statement is encountered.
my question is does it take time to execute because of so many records ?
If not then why dies it take a lot of time to execute a single select statement ?
and how can i optimise the time consumed by this select query or report. ?
Thank you.
Moderator message: please understand the basic concept of using primary or secondary indexes in your queries, you will sure find the missing field in your where-clause, read the sticky threads of this forum.
Edited by: Thomas Zloch on Nov 20, 2010 5:31 PMHi Vivek,
Data volume definitely gives impact on SQL.
Don't use sql inside the loop, it will decrease the performance.
Year material no. and item type may have duplicate entries. filter that. It may also gives impact on performance.
Write a single Select query.
Instead of fetching the data at once use packet size.
http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP4TuningChecklist
Regards,
Sudha
Edited by: Sudha Rani Pathuri on Nov 20, 2010 6:42 PM
Edited by: Sudha Rani Pathuri on Nov 20, 2010 6:48 PM
Edited by: Sudha Rani Pathuri on Nov 20, 2010 6:51 PM -
Simple Select statement in MS Access
I am not able to get this simple select statement working in MS Access.
"SELECT PhotoLocation from RfidData WHERE TeamID = '"+teamID ;
It is using a variable called teamID which is a string.
The error is java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression
Please Suggest
Thank You...Let's look at your code, shall we?
public String readPhotoLoc(String teamID)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL,"","");
PreparedStatement ps = con.prepareStatement("Select PhotoLocation from RfidData "); // There's no bind parameter here, so setString will do nothing
ps.setString(1,teamID);
ResultSet rs = ps.executeQuery(); // what do you do with the ResultSet? Nothing. //You don't return anything, either. I doubt that this mess even compiles.
}Here's one suggestion for how to write it properly:
public String readPhotoLoc(Connection connection, String teamID)
String photoLoc = null;
PreparedStatement ps = null;
ResultSet rs = null;
try
String query = "SELECT PhotoLocation FROM RfidData WHERE TeamID = ?";
ps = connection.prepareStatement(query);
ps.setString(1,teamID);
rs = ps.executeQuery();
while (rs.next())
photoLoc = rs.getString("PhotoLocation");
return photoLoc;
catch (SQLException e)
e.printStackTrace();
return null;
finally
try { if (rs != null) rs.close(); } catch (SQLException ignoreOrLogThis) {}
try { if (ps != null) ps.close(); } catch (SQLException ignoreOrLogThis) {}
}Make sure that the types of the columns match the Java types.
% -
Hi Expert,
Is this select statement is ok ?
actually i have doubt in where clause when it mix both AND and OR without braces
SELECT SINGLE * FROM vbfa WHERE
vbeln = s_bkpf-awkey AND
vbtyp_v = 'C' OR
vbtyp_v = 'E' OR
vbtyp_v = 'M' OR
vbtyp_v = 'J' OR
vbtyp_v = 'R' .
thanks and regards
abaper.SELECT SINGLE * FROM vbfa WHERE
vbeln = s_bkpf-awkey AND ( vbtyp_v = 'C' OR
vbtyp_v = 'E' OR
vbtyp_v = 'M' OR
vbtyp_v = 'J' OR
vbtyp_v = 'R' ).
OR YOU CAN USE
SELECT SINGLE * FROM vbfa WHERE
vbeln = s_bkpf-awkey AND
vbtyp_v IN ('C', 'E', 'M', 'J', 'R') .
CHECK THE SPACE NO SPACE BETWEEN ('C' AFTER , ONE SPACE AND NO SPACE BETWEEN 'R'). GIVE THE SPACE CORRECTLY ...
REGARDS
SHIBA DUTTA -
Select statements in smartform
Hi All,
what happens if u use lot of select statements in smartform rather than in driver program...
regards,
P.Ramesh.Ramesh,
You wrote :hi amit,
then wat the purpose we have driver program....everything can be done in smartforms..
yes i was expecting this questiong from you next.
let me explain why we need driver program!
major reason we cant create Transaction for smartform.so how can you give your smartform to your enduser?they are not suppose to run every time smartform by smartforms trasaction itself.
so we must need to attach smartform to our driver program and we create a transaction for that driver program.than user supposr to run only that transaction every time.
I hope your doubt clear.
Amit. -
'FOR ALL ENTRIES' in SELECT statements
Hi,
I got a doubt in working of the 'FOR ALL ENTRIES' option in the SELECT statement. Here is my scenarion.
Table A - Document Header Level (Key: Doc Number)
Internal Table B - Document Item level (Keys: Doc num and Doc Item).
So, for each record in Table A, table B will have multiple records.
In this situation, how the below SELECT will work.
SELECT <field names> INTO <some internal table>
FROM A
FOR ALL ENTRIES in B
WHERE doc_num = B-doc_num.
Will the above SELECT result in duplicate records or not?
(I tested it and found that it doesn't! I was lil surprised and wanted to confirm that)
Thanks & Regards,
SreeHi,
For all entries option basically sorts out the entries in the internal tbale based on the where condition and thus it only picks the unique entries based on the list.
so indeed your table A is a header one so it will give you only single value. if you go by the reverse way where in look for B for all entries in A it will give you multiple values as table B has multiple values for each value in A.
Regards,
Jagath -
Order of records in o/p of select statement
Hi all
I have doubt regarding the select statement. I need to execute a select statement (with out any order ie with out "order by") which searchs a table. I want to know whether in any
circumstances the order of the records of the select statement is different.
sample select statement which I need to execute
select emp_no from emplyees where designation = 'programer'
in one word order of records of in the o/p of a select statement will be unique ?
(provided same query same, table,)
can u plz quote the link to get more information
regards
RenjithHi,
YES, you can
Do Order By Without Using Order By Clause
in your select statement.
I assume that you have unique data ( e.g. emp_no in Emp Table ) and you you do not want to use Order by clause.
Solution 1:
Select Emp_no
from Emp
group by Emp_no;
the o/p will be in the sorted in the Ascending order.
Solution 2: ( Only for columns holding Numeric Values )
Select Emp_No
From Emp
Where 99999 - Emp_no in ( Select 99999 - Emp_no from Emp );
Again this will sort the result will be in the Descending Order. you can use any big number instead of 99999 but it should be greater than Emp_no value.
Note: You Should only use this method on not very large tables coz of performance issue.
Hope this will solve your problem.
Any Comment on this, any body.
Thanks and Regards
There is always a solution to the problem, And if there is no solution of a problem then problem is not a problem. -
If statement in select statement alias
I have the following select statement. It has the alias Survivors, Deaths and "All Cases". Is it posible to use :P_LANGUAGE variable to say that -- IF :P_LANGUAGE = FRENCH THEN alias are Survivants for survivors, Décès for Deaths, Tous_les_cas for All Cases. Please advise
SELECT ALL T_NTR_MULTIBAR.CAT, T_NTR_MULTIBAR.NUM_CASES_LEFTBAR AS Survivors,
T_NTR_MULTIBAR.NUM_CASES_MIDDLEBAR AS Deaths, T_NTR_MULTIBAR.NUM_CASES_RIGHTBAR AS "All Cases"
FROM T_NTR_MULTIBAR
WHERE INSTANCE_NUM = :P_INSTANCENUM
order by ORDERSYou may not be able to add this condition inside the SQL Statement. But you can add this condition outside the statement, if you're using PL/SQL...
IF :p_language = french THEN
SELECT ALL t_ntr_multibar.cat,
t_ntr_multibar.num_cases_leftbar AS survivors,
t_ntr_multibar.num_cases_middlebar AS deaths,
t_ntr_multibar.num_cases_rightbar AS "All Cases"
ELSE
END IF; -
How to get all values from an interval using select statement
Hi,
Is it possible to write a select statement that returns all values from an interval? Interval boundaries are variable.
something like this:
select (for x in 1,1024 loop x end loop) from dual
(this, of course, doesn't work)
The result in this example should be 1024 rows of numbers from 1 to 1024. These numbers are parameters, so it is not possible to create a table with predefined values.
Thanks in advance for your help,
Mia.For your simple case, with a lower boundary of 1, you can use:
SELECT rownum
FROM all_objects
WHERE rownum <= 1024For a set of number between say 50 - 100, you can use something like:
SELECT rownum + (50 - 1)
FROM all_objects
WHERE rownum <= (100 - 50 + 1)Note, that all_objects was used only because it generally has a lot of rows. Any table with at least the number of rows in your range will work.
TTFN
John -
How to find the number of fetched lines from select statement
Hi Experts,
Can you tell me how to find the number of fetched lines from select statements..
and one more thing is can you tell me how to check the written select statement or written statement is correct or not????
Thanks in advance
santoshHi,
Look for the system field SY_TABIX. That will contain the number of records which have been put into an internal table through a select statement.
For ex:
data: itab type mara occurs 0 with header line.
Select * from mara into table itab.
Write: Sy-tabix.
This will give you the number of entries that has been selected.
I am not sure what you mean by the second question. If you can let me know what you need then we might have a solution.
Hope this helps,
Sudhi
Message was edited by:
Sudhindra Chandrashekar
Maybe you are looking for
-
HT1386 how do i sync photos from iphone to pc in order to delete them?
how do i sync photos from iphone to pc in order to delete them?
-
Revision: 931 Author: [email protected] Date: 2008-03-26 11:31:01 -0700 (Wed, 26 Mar 2008) Log Message: Bug: BLZ-96 - When sending a HttpService request from ActionScript with multiple headers with the same name, it causes a ClassCastException in the
-
Photosmart B110a & Mavericks - won't print after about two minutes...
Evening - I've been using the Photosmart B110a for a few years no problems at all with Windows XP, Windows 7 and more recently Windows 8 - I've recently bought an iMac that is running Mavericks, and it's not right. It took me a while to install it,
-
Hi all, Does any1 have a Query that retrieves stock postings for a Variable Item Code. I want to Enter an Item Code and the query should bring foward all the stock postings for that Item Grouped by Months/Periods. I need to create a Monthly Usage Re
-
Backup ALL hard drives, inc. EXTERNAL and FLASHDRIVES?
Hi, I've read on the forums and got no answer that could help me on this problem. And there have been posts about this earlier but here I go... *I'm carrying a 250 gb WD Passport disk everyday with all my school work. And I use a Mac Pro to boost my