SELECT statement in FROM clause - syntax help
Hi,
I want to have a SELECT statement in the FROM clause. I get syntax error when doing this and since I am new to ABAP I need som help.
I want to do the following, (and if anyone has any SELECT statement from their own system which you know there is no syntax error in please post it here so I can analyze the syntax):
*I leave the INTO itab clause out, since I only want to demonstrate the functionality
I am trying to get.
<b>SELECT</b> tableOne~someField
<b>FROM</b> tab <b>AS</b> tableOne (<b>SELECT</b> someField
<b>FROM</b> tab
<b>WHERE</b> someFiled > 1) <b>AS</b> tableTwo
<b>WHERE</b> tableOnesomeField > tableTwosomeField
like I said, the problem is that the select statement in the parenthesis in the from clause seems to be incorrect because I get "wrong expression" when trying to compile. Is this because I cannot have a select statement in the from clause or is it because of a minor syntax error, such as I forgot a dot, or some other sign?
thanks and regards
Baran
sorry i am not enough familiar with sub queries but some error i can see which i will state here.
1> you have to use sub queries i.e. select in ( ) after where clause because here you are fulfilling a where clause by another select statement.
like this
SELECT * FROM SFLIGHT
INTO WA
WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).
2> you cannot specify field name without into clause either you have to use
select * or select f1 into tab-f1 like this...
but if you are using select * without into you have to define
tables : dbtab.
selec * from dbtab. like that.
regards
shiba dutta
Similar Messages
-
Selecting multiple values from a search help
Hi Experts
Anyone knows if it is possible to select multiple values from a search help?
Thanks
GauravHi,
You cannot select mutiple values from search help as it is linked to inputfield and hence it will accept single value only. But at the same time, you may able to pass row of values to different inputfields.
Refer http://help.sap.com/saphelp_dm40/helpdata/en/3d/e53642e2a3ab04e10000000a1550b0/content.htm
Thanks,
Chandra -
Please explain on what does these select statements get from these tables..
Hello Experts,
What does these select statements get?and what are these tables CDHDR and CDPOS used for?
The program that I am currently modifying lets users post documents and the ones that are not posted
are saved in a custom table. Now, we had a scenario in PROD server wherein certain items are not being
fetched as bypassed but we saved it in the bypassed table. Anyway, below is the select statements:
get all change document header within the selected dates
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_cdhdr
FROM cdhdr
WHERE udate IN s_udate
AND objectclas EQ 'CHARGE'
AND tcode IN (lc_tcode_msc1,
lc_tcode_msc2,
lc_tcode_msc1n,
lc_tcode_msc2n,
lv_tcode_vl33n,
'SE38',
'ZGENE').
IF NOT it_cdhdr[] IS INITIAL.
SELECT objectid changenr value_new
FROM cdpos
INTO TABLE it_cdpos
FOR ALL ENTRIES IN it_cdhdr
WHERE objectclas EQ it_cdhdr-objectclas
AND objectid = it_cdhdr-objectid
AND changenr = it_cdhdr-changenr
AND tabname = lc_tabname_mcha
AND fname IN (lc_fname_zustd,'LWEDT').
DELETE it_cdpos WHERE value_new+00(01) = 'X'.
LOOP AT it_cdpos ASSIGNING <fs_cdpos>.
l_matnr = <fs_cdpos>-objectid+00(18).
l_charg = <fs_cdpos>-objectid+22(10).
l_zustd = <fs_cdpos>-value_new+00(01).
READ TABLE it_batch INTO wa_batch
WITH KEY matnr = l_matnr
charg = l_charg.
IF sy-subrc EQ 0.
l_tabix = sy-tabix.
wa_batch-zustd = l_zustd.
MODIFY it_batch FROM wa_batch INDEX l_tabix
TRANSPORTING zustd.
ELSE.
wa_batch-matnr = l_matnr.
wa_batch-charg = l_charg.
wa_batch-zustd = l_zustd.
wa_batch-code = 'A'. "selected within period
APPEND wa_batch TO it_batch.
ENDIF.
ENDLOOP.
ENDIF.Hi,
The first select statement is for Change document header.CDHDR table contains this object class in your case if you change any batch number for any material number from the transaction for example (MB01) you can trace this .
From CDPOS you can trace which tables affected (EX : MCHA) and the new value(l_zustd ).
Regds,
Vinsa.R -
Select in From-Clause with JPQL
Hey,
I'm new to JPA development. How can I transform the following SQL-Statement:
select a from
Gpsj a,
(select c.tsid, c.wsid, max(c.gdat1) maxgdat from Gpsj c where c.tsid = '901' group by tsid, wsid) b
where a.tsid = b.tsid
and a.wsid = b.wsid
and a.gdat1 = b.maxgdat
I can't find any expression for using a (select-statement in a from-clause)
thanks
NikolaiJPQL does not support sub-selects in the from clause. You can use a native SQL query for this in JPA.
James : http://www.eclipselink.org -
Snapshot too old ORA-01555 from select statement (discoverer)??
Hi All
Am I loosing the plot .. but we have a select statement run from discoverer which is causing the famous snapshot too old error.
My understanding is that undo is generated from select/insert/update.
So why is the following discoverer Select statement causing the error?
from alert
ORA-01555 caused by SQL statement below (SQL ID: gk0wxgqmx66sh, Query Duration=3866 sec, SCN: 0x001e.089cf3f9):
SELECT ( ROUND(( TO_DATE(SYSDATE)-o101038.HIRE_DATE )/365,2) ) as
" bla bla
ORDER BY o101020.SUB_ORGANIZATION_NAME ASC
Thanks in Advancesimon.9999 wrote:
Hi All
Am I loosing the plot .. but we have a select statement run from discoverer which is causing the famous snapshot too old error.
My understanding is that undo is generated from select/insert/update.
So why is the following discoverer Select statement causing the error?
from alert
ORA-01555 caused by SQL statement below (SQL ID: gk0wxgqmx66sh, Query Duration=3866 sec, SCN: 0x001e.089cf3f9):
SELECT ( ROUND(( TO_DATE(SYSDATE)-o101038.HIRE_DATE )/365,2) ) as
" bla bla
ORDER BY o101020.SUB_ORGANIZATION_NAME ASC
Thanks in Advance
The SELECT statement is the victim.
Some session is doing DML against the same table against which the SELECT occurs & is likely doing COMMIT inside a LOOP. -
Dynamic 'from' Clause in Native SQL
Hi All,
While running a select query in ORACLE, we can put the table name in '<i>from</i>' clause at the runtime-Seletion Screen Parameter .
But I am not able to do so in SAP using Native Sql. Does SAP has any restrictions regarding this?
It might be possible that ,by using Embedded SQL (C/C++ precompiler ),we may be able to achive this.
Can any body please throw light on this.
Its Urgent.
Thanks in Advance.
Regards,
GauravHi
<u>Assuming you can also use Open SQL.</u>
Macroman's suggestion is OK. in Open SQL (this is SQL of ABAP platform) but a query statement can be constituted using some dynamic clauses. Although macro coding has some restrictions it will be less time consuming using it than a dynamic query.
<u>An example SELECT statement with dynamic clauses:</u>
SELECT (fields) FROM (table_name_variable)
INTO <target_fields>
WHERE (conditions_tab) .
For more information:
<a href="http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3983358411d1829f0000e829fbfe/frameset.htm">Open SQL -Reading Data</a>
*--Serdar -
Multiple select statements in PL/SQL
Hi All
I am new to PL/SQL and my experience is in writing TSQL. There we can write a SQL statement like this to return 3 result set
SELECT empname FROM Employee
SELECT authname FROM Author
SELECT athname FROM sport
how can we write the same 3 statements in PL/SQL and attain the 3 resultsets.
I tried to implement the same using PL/SQL anonymous blocks. But it didn't worked.
DECLARE
P_RECORDSET OUT SYS_REFCURSOR
BEGIN
OPEN P_RECORDSET FOR
SELECT empname FROM Employee;
SELECT authname FROM Author;
SELECT athname FROM sport;
END;
can anybody show how it can be done.
Thanks in advance
George
Edited by: user6290570 on Sep 16, 2009 11:23 PMgeorge2009 wrote:
No i just want to select 3 result sets from 3 select statements, so that it is helpful to compare the resultsets. Compare? How? This is done using the SQL language. Not PL/SQL. Not Java. Not VB. Not anything else.
You would use these other language for flow control and certain forms of conditional logic - but the actual comparison of data sets is done in SQL.
Of course, that is if you do want to do it the most optimal way, that will perform well, and scale well.
SQL is not an I/O API layer - to be used to read() a record and write() a record as if the RDBMS is an ISAM file. That form of row-by-row and slow-by-slow processing dates back to the 80's when we used Cobol.. (or at least for those old farts like me that can actually remember coding in Cobol in the 80's ;-) ).
You want to design and code database applications that are fast, robust, and can scale? Then learn how to use SQL correctly. -
Hi,
I have recently been asked to generate a program that reports of payroll postings to FI. This involves creating a giant select statement from the ppoix table to gather all the postings. My select statement is as follows:
SELECT pernr "EE Number
seqno "Sequential number
actsign "Indicator: Status of record
runid "Number of posting run
postnum "Number
tslin "Line number of data transfer
lgart "Wage Type
betrg "Amount
waers "Currency
anzhl "Number
meins "Base unit of measure
spprc "Special processing of posting items
momag "Transfer to FI/CO:EE grouping for acct determi
komok "Transfer to FI/CO: Symbolic account
mcode "Matchcode search term
koart "Account assignment type
auart "Expenditure type
nofin "Indicator: Expenditure type is not funded
INTO CORRESPONDING FIELDS OF TABLE i_ppoix
FROM ppoix
FOR ALL ENTRIES IN run_doc_xref
WHERE runid = run_doc_xref-runid
AND tslin = run_doc_xref-linum
AND spprc <> 'A'
AND lgart IN s_lgart
AND pernr in s_pernr.
where s_pernr is a select option that holds personnel nummbers and s_lgart is a select option that holds wagetypes. This statement works fine for a certain amount of personnel numbers and a certain amount of wagetypes, but once you exceed a certain limit the Database does not allow you to perform a select statement this large. Is there a better way to perform such a large select such as this one) ie: FM, or some other method I am not aware of. This select statement comes from the standard SAP delivered cost center admin report and this report dumps as well when too much data is passed to it.
any ideas would be much appreciated.
thanks.The problem here is with the select-options.
For a select statement, you cannot have more that certain amount of data.
The problem with your select becomes complex because of the FOR ALL ENTRIES in and the huge s_pernr and the 40 million records :(.
I am guessing that the s_lgart will be small.
How many entries do you have in internal table "run_doc_xref"?
If there are not that many, then I would suggest this:
TYPES:
BEGIN OF ty_temp_ppoix,
pernr TYPE ppoix-pernr,
lgart TYPE ppoix-lgart,
seqno TYPE ppoix-seqno,
actsign TYPE ppoix-actsign,
runid TYPE ppoix-runid,
postnum TYPE ppoix-postnum,
tslin TYPE ppoix-tslin,
betrg TYPE ppoix-betrg,
spprc TYPE ppoix-spprc,
END OF ty_temp_ppoix.
DATA:
i_temp_ppoix TYPE SORTED TABLE OF ty_temp_ppoix
WITH NON-UNIQUE KEY pernr lgart
INITIAL SIZE 0
WITH HEADER LINE.
DATA:
v_pernr_lines TYPE sy-tabix,
v_lgart_lines TYPE sy-tabix.
IF NOT run_doc_xref[] IS INITIAL.
DESCRIBE TABLE s_pernr LINES v_pernr_lines.
DESCRIBE TABLE s_lgart LINES v_lgart_lines.
IF v_pernr_lines GT 800 OR
v_lgart_lines GT 800.
* There is an index on runid and tslin. This should be ok
* ( still bad because of the huge table :( )
SELECT pernr lgart seqno actsign runid postnum tslin betrg spprc
* Selecting into sorted TEMP table here
INTO TABLE i_temp_ppoix
FROM ppoix
FOR ALL ENTRIES IN run_doc_xref
WHERE runid = run_doc_xref-runid
AND tslin = run_doc_xref-linum
AND spprc <> 'A'.
* The sorted table should make the delete faster
DELETE i_temp_ppoix WHERE NOT pernr IN s_pernr
AND NOT lgart IN s_lgart.
* Now populate the actual target
LOOP AT i_temp_ppoix.
MOVE: i_temp_ppoix-pernr TO i_ppoix-pernr.
* and the rest of the fields
APPEND i_ppoix.
DELETE i_temp_ppoix.
ENDLOOP.
ELSE.
SELECT pernr seqno actsign runid postnum tslin lgart betrg spprc
* Selecting into your ACTUAL target here
INTO TABLE i_ppoix
FROM ppoix
FOR ALL ENTRIES IN run_doc_xref
WHERE runid = run_doc_xref-runid
AND tslin = run_doc_xref-linum
AND spprc <> 'A'
AND pernr IN s_pernr
AND lgart IN s_lgart.
ENDIF.
ELSE.
* Error message because of no entries in run_doc_xref?
* Please answer this so a new solution can be implemented here
* if it is NOT an error
ENDIF.
Hope this helps.
Regards,
-Ramesh -
Number of records in cursor select statement
hi all,
with the cursor i am selecting set of select statement and writing into the .txt file.
its working file, but it should not open the file if the cursor returns nothing.
how to check for the number of records return by the select statement in the cursor.
pls help me.
Thanks..Hi,
You can use a Cursor for loop (you'll not enter in the loop if the SELECT is retrieving no rows):
begin
for recs in(select * from whatever) loop
null; -- Produce your file
end loop;
end;You can also use a bulk collect and check "yourcollection.count" attribute ... (but don't use it if you are processing a lot of records!) -
Count(*) function in select statement having group by condition
Hi
I would like to use count(*) in select statement having group by clause. say for example there is a state with a number of cities listed. I would like to get the count of cities for each state.
the sql stement is grouped by state and it is joined with 5 more tables.
Thanks
ps: ignore the previous postAssuming there is one record per city per state, then
SELECT state,count(*)
FROM state_tbl
GROUP BY stateWill get one record per state with the number of cities in each state. If you want to join that result set to other tables you need to either create a view with that statement or use an in-line view viz.
SELECT c.cust_name,c.state,s.num_cities
FROM customers c,
(SELECT state,count(*) num_cities
FROM state_tbl
GROUP BY state) s
WHERE c.state = s.stateTTFN
John -
How can we improve performance while selection production orders from resb
Dear all,
there is a performance issue in a report which compares sales order and production order.
Below is the code, in this while reading production order data from resb with the below select statement.
can any body tell me how can we improve the performance? should we use indexing, if yes how to use indexing.
*read sales order data
SELECT vbeln posnr arktx zz_cl zz_qty
INTO (itab-vbeln, itab-sposnr, itab-arktx, itab-zz_cl, itab-zz_qty)
FROM vbap
WHERE vbeln = p_vbeln
AND uepos = p_posnr.
itab-so_qty = itab-zz_cl * itab-zz_qty / 1000.
CONCATENATE itab-vbeln itab-sposnr
INTO itab-document SEPARATED BY '/'.
CLEAR total_pro.
**read production order data*
SELECT aufnr posnr roms1 roanz
INTO (itab-aufnr, itab-pposnr, itab-roms1, itab-roanz)
FROM resb
WHERE kdauf = p_vbeln
AND ablad = itab-sposnr+2.Himanshu,
Put a break point before these two select statements and execute in the production.This way you will come to know which select statement is taking much time to get executed.
In both the select statements the where clause is not having the primary keys.
Coming to the point of selecting the data from vbap do check the SAP note no:-185530 accordigly modify the select statement.
As far as the table RESB is concerened here also the where clause doesn't have the primary keys.Do check the SAP Note No:-187906.
I guess not using primary keys is maring the performance.
K.Kiran. -
How to coerce data types to strings in a SELECT statement?
ABAPers,
I need to coerce column outputs to strings in a SELECT statement. Here is a pseudo example:
select ConvertToString(count(*)) from MARA
On help.sap.com, I could not find enough information on the functions that are supported within SELECT statement. I would appreciate it if someone can enlighten me on how to achive this.
Note that my real problem is that I do not know the return type of the specified columns. The columns are passed as a user-specified parameter. As I do not know the column types, I am mandating that customers specify columns that return only string type data.
Thank you in advance for your help.
PradeepHi Pradeep,
Convert to string wont be possible in the SELECT statement.
What you can do is use Field Symbols. This allows to assign data types dynamically.
Field-Symbols
Best regards,
Prashant
Pls. mark points for helpful answers -
Select statement is taking lot of time for the first time Execution.?
Hi Experts,
I am facing the following issue. I am using one select statement to retrieve all the contracts from the table CACS_CTRTBU according to FOR ALL ENTRIES restriction.
if p_lt_zcacs[] is not initial.
SELECT
appl ctrtbu_id version gpart
busi_begin busi_end tech_begin tech_end
flg_cancel_obj flg_cancel_vers int_title
FROM cacs_ctrtbu INTO TABLE lt_cacs FOR ALL ENTRIES IN p_lt_zcacs
WHERE
appl EQ gv_appl
AND ctrtbu_id EQ p_lt_zcacs-ctrtbu_id
AND ( flg_cancel_vers EQ '' OR version EQ '000000' )
AND flg_cancel_obj EQ ''
AND busi_begin LE p_busbegin
AND busi_end GT p_busbegin.
endif.
The WHERE condition is in order with the available Index. The index has APPL,CTRTBU_ID,FLG_CANCEL_VERS and FLG_CANCEL_OBJ.
The technical settings of table CACS_CTRTBU says that the "Buffering is not allowed"
Now the problem is , for the first time execution of this select statement, with 1.5 lakh entries in P_LT_ZCACS table, the select statement takes 3 minutes.
If I execute this select statement again, in another run with Exactly the same parameter values and number of entries in P_LT_ZCACS ( i.e 1.5 lakh entries), it gets executed in 3-4 seconds.
What can be the issue in this case? Why first execution takes longer time?.. Or is there any way to modify the Select statemnt to get better performance.
Thanks in advance
Sreejith A PHi,
>
sree jith wrote:
> What can be the issue in this case? Why first execution takes longer time?..
> Sreejith A P
Sounds like caching or buffering in some layer down the i/o stack. Your first execution
seems to do the "physical I/O" where your following executions can use the caches / buffers
that are filled by your first exectution.
>
sree jith wrote:
> Or is there any way to modify the Select statemnt to get better performance.
> Sreejith A P
If modifying your SELECTS statement or your indexes could help depends on your access details:
does your internal table P_LT_ZCACS contain duplicates?
how do your indexes look like?
how does your execution plan look like?
what are your execution figures in ST05 - Statement Summary?
(nr. of executions, records in total, total time, time per execuiton, records per execution, time per record,...)
Kind regards,
Hermann -
Adding in Select statement for SAPscript printout
Hi everyone,
I have a new requirement where i would need to output a new field in a sapscript printout.
A summary of the requirements is as follows:
-> If EKPO-PSTYP = '3'
-> select RSNUM
from EKET
where EKET-EBELN = EKPO-EBELN and
EKET-EBELP = EKPO-EBELP
-> select MATNR
from RESB
where RESB-RSNUM = EKET-RSNUM
-> display RESB-MATNR in printout
At the moment, the sapscript is only reading from table EKPO, whereas for the new requirement to work, i'll also need to read from table EKET and RESB. Am i right to understand that sapscript cannot read SELECT statements directly from the Change Editor and i would need to do a PERFORM statement?
The question now is, where do i put this part of the logic? Any ideas?
Message was edited by: Bernard LohHi,
Write a PERFORM in your script.
PERFORM GET_MATNR IN PROGRAM Z_SUBROTINEPOOL
USING W_EBELN W_EBELP
CHANGING W_MATNR
ENDPERFORM.
And check the following to write the FORM in the Z program.
The structure ITCSY is used in relation with SAPScripts. You can call a Routine in any program in SAPScript.
For eg: if you have a subroutine named ADD_INCOME in a program ZSHAIL_BASIC, you can call the subroutine in SAPScript as follows:
/: PERFORM ADD_INCOME IN PROGRAM ZSHAIL_BASIC
/: USING &var1&
/: CHANGING &var2&
/: ENDPERFORM.
Here the input parameter to the subroutine is var1 and the value returned by the subroutine is var2.
In the program ZSHAIL_BASIC, you have to call the subroutine as
FORM ADD_INCOME TABLES IN_TAB STRUCTURE ITCSY OUT_TAB STRUCTURE ITCSY.
ENDFORM.
IN_TAB is a structure of type ITCSY,which has 2 components, NAME and value.
So in the program, var1(which is sent from SAPScript) , will be stored as IN_TAB-NAME and its value will be in IN_TAB-VALUE. You can utilise the IN_TAB-VALUE and after performing the required operations, the return value should be assigned to table OUT_TAB.
This value can thus be obtained in var2 specified in SAPScript.
Also you can search for "SUBROUTINE IN SCRIPT"... "PERFORM IN SCRIPT", "ITCSY"....
Thanks and Regards,
Bharat Kumar Reddy.V -
Limit users to execute "SELECT" statemes only from SQL Developer
Hi:
Is there a way to control what SQL command can be executed from SQL Developer?
I am trying to limit users to execute "SELECT" statements only from SQL Developer.
I believe SQL*Plus used to have the product profile where I can control what SQL command can be executed from what user.
Thanks in advance.There's nothing special in sqldev to enforce privileges, the database does all that already. See the database documentation on the GRANT and REVOKE statements. Basically, you would only want to grant SELECT privileges to your users...
Have fun,
K.
Maybe you are looking for
-
How can I prevent an e-mail address being underlined as a link?
I am using Pages to create a document to be printed by newspapers and magazines. When I put in my e-mail address Pages automatically underlines it as a hyperlink to open an e-mail message. A link will be useless in a printed document. But I don't wan
-
Problem following ID update to CS6 8.0.1
Just in case anyone else is experiencing the same problem after updating ID CS6 to 8.0.1... I found that a placed Illustrator file did not have any transparency, or at least it appeared to be displaying the Art Board (white page background) when I im
-
Weird background almost like moisture and volume issue.
Hi, I just got my iPad 2 days ago and everything seem to be working fine. Luckily I didn't have any wifi issues. I've kept it in good condition, away from kids, heat, water charged it to full every night and did frequent backups. Today while playing
-
GoodMorning, i have an array of array that is saved in a cookie. can i encrypt the cookie in some way? please help me. Thanks Markus
-
re iPhoto automatically manages both original and working copies of your pictures inside your iPhoto Library. If you interfere with its management by removing or renaming the originals manually or via a third-party utility (such as iPhoto Diet), then