I have to write a select query
hi
i have a select-options DATE , i want to make a select QUERY which select all data Staring Date(Initial Date) to 1 less to DATE-LOW.
For that i define a variable i.g. ODDATE = DATE-LOW - 1. this contain date 1 less then LOW.
But now how i can make select statement.
PLZ Guide me
see the logic given below.........
tables vbak.
select-options: s_date for vbak-erdat no-extension.
data:
w_date1 like sy-datum,
w_date2 like sy-datum.
w_date1 = s_date-low - 1.
w_date2 = s_date-low.
select ......
where
date between w_date1 and w_date2.
Reward points if useful, get back in case of query...
Cheers!!!
Similar Messages
-
How to write XSJS Select Query with input parameters
Hello Experts,
I am creating a xsjs file and in that file I am trying to write a Select Query based on a Calculation View
I have tried it the following way:
var query = 'SELECT TOP 100 \"Name\", \"Address\", \"City\", \"Country\" FROM \"_SYS_BIC\".\"Test.HL/AddressView\"'
+ 'WITH PARAMETERS(\'PLACEHOLDER\' = (\'$$P_Name$$\', \' Akhil \'),'
+ '\'PLACEHOLDER\' = (\'$$P_City$$\', \' Lucknow \'))';
But it gives me the "Mixed spaces and tabs error".
How should I write XSJS Select Query with input parameters?
Regards,
Rohit>But it gives me the "Mixed spaces and tabs error".
Mixed spaces and tabs has nothing to do with the syntax of the statement. You used both spaces and the tab in the content - which JSLint doesn't like. Remove the beginning spaces of each line and use only one or the other.
The actual syntax of your statement doesn't look right. The problem is that you are escaping the \ when you don't need to if you are using ' instead of " for your string. You escape with \" in the first line but then escape with \' in the 2nd and 3rd line. That is going to cause serious parsing problems with the command. -
Can I write a SELECT query on maintenance view?
Hi,
Can we write a select query on maint. view? If not what are the views on which we can write the select queries?hi,
you can write select query for maintenance view, database view and projection view but not helpview as it is only intended for f4 help.
reward if helpful
prasanth -
How to write the select query with complex where condition
Hi all,
Can u help me in writing following select query.
select * from zu1cd_corr where time_stamp between firstday and lastday .
In the above query time_stamp contains the date and time.
where as firstday and lastday contains the dates.
I need to compare the date in the time_stamp with the firstday and lastday.
But time_stamp contains the time also and it is char of 14 characters length.Hi,
If that is the case u can do as advait specified....
if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.
CLEAR : lv_firstday,
lv_lastday.
concatenate firstday '000000' to lv_firstday.
concatenate lastday '240000' to lv_lastday.
ranges : r_Date for zu1cd_corr-time_stamp.
r_date-sign = 'I'.
r_date-option = 'BT'.
r_Date-low = lv_firstday.
r_Date-high = lv_lastday.
append r_date.
select * from zu1cd_corr into table it_zu1cd_corr where time_stamp in r_Date.
I hope it helps.
Regards,
Nagaraj -
Sample XML format that can be used to write a SELECT query
Hello,
I want to use and XML file in the scenario FILE to JDBC where i use the operation as SELECT in which i want to embbed an sql statemnet which is equivalent to
SELECT EMPNO, NAME FROM EMPLOYEE WHERE EMPNO>1
as in the form of XML format like,
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
<STATEMENT>
<TABLENAME ACTION="SELECT">
<TABLE>EMPTEST</TABLE>
<ACCESS>
<EMPNO></EMPNO>
<NAME></NAME>
</ACCESS>
<KEY>
<EMPNO compareOperation="GT">1</EMPNO>
</KEY>
</TABLENAME>
</STATEMENT>
</ns0:MT_JDBC_SELECT_JDBC_REQ>
Can i do like this?
PLease help me out in using various conditions in the XML file formats like the above.
Thanks,
Soorya.Hello raj,
I would like to write the query in that format where i mentioned as,
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
<STATEMENT>
<TABLENAME ACTION="SELECT">
<TABLE>EMPTEST</TABLE>
<ACCESS>
<EMPNO></EMPNO>
<NAME></NAME>
</ACCESS>
<KEY>
<EMPNO compareOperation="GT">1</EMPNO>
</KEY>
</TABLENAME>
</STATEMENT>
</ns0:MT_JDBC_SELECT_JDBC_REQ>
without giving clear SQL statement as you mentioned here like,
<ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
<STATEMENT>
<TABLENAME ACTION="SQL_QUERY">
<ACCESS>SELECT EMPNO, NAME FROM EMPLOYEE WHERE EMPNO > '$EMPNO$</ACCESS>
<KEY>
<EMPNO>1</EMPNO>
</KEY>
</TABLENAME>
</STATEMENT>
</ns0:MT_JDBC_SELECT_JDBC_REQ>
Thanks,
Soorya -
Select query help for Sales order
Hi Experts,
I have to write a select query to fetch sales orders which are open along with the quantities which are open ( not delivered). What would the best approach for this?
Any help is appreciated. Expecting code samples....Thanks
Thanks
Rickyhi,
do like this,
write a select query for vbak and vbuk as follows.
delivery status field is <b>lfstk</b> from <b>vbuk</b>,
and relation field is <b>vbeln</b> from the both the tables.
reward points if useful,
regards,
seshu. -
Select query in driver program for sapscript
Hi All,
I want to select buzei, zuonr,sgtxt,meins from bseg ,temp (a temporary variable of type p deciamls 2), tmp (another temporary variable) and dmbtr from HBSEG (a structure of type bseg) . under the cond
koart ne 's' or
xauto ne 'x' or
buzid ne 't'.
I have to write this select query usinf a WORKAREA . After this select query i give WRITE_FORM as i call there vairables in script.Its very urgent.
thanks muchHi,
You can use inner join. Consider this simple example.
data : a type zvijirank occurs 10 with header line,
b type zvijirank1 occurs 10 with header line.
data : name like zvijirank-name,
total like zvijirank1-total,
reg_no like zvijirank.
* regno type i.
data : begin of wa,
name type zvijirank-name,
total type zvijirank1-total,
branch type zvijirank1-branch,
reg_no type zvijirank-reg_no,
* FNAME TYPE ZVIJIRANK2-F_NAME,
* MNAME TYPE ZVIJIRANK2-M_NAME,
* CITY TYPE ZVIJIRANK2-CITY,
* TEL_NO TYPE ZVIJIRANK2-TEL_NO,
end of wa.
data : it like standard table of wa with header line,
it1 like standard table of wa with header line.
call selection-screen 9010.
select a~name b~total b~branch a~reg_no into table it from zvijirank as a inner join zvijirank1 as b on a~reg_no = b~reg_no .
loop at it.
if it-reg_no eq regno.
write : 'NAME :', it-name,
'REG_NO :', it-reg_no,
'TOTAL :', it-total.
ENDIF.
endloop.
Thanks,
Reward If Helpful. -
I am working on a function module.
The input to the function is more one entry.... (zz1, zz2, zz3)...
Based on the input i have to write a select query
select f1
f2
from DBtable into table itab2
for all entries in itab2 where
f1 eq itab1-f1 and
f3 ge sy-datum.
here f 1 is zz1,zz2,zz3.
However if the user enters z* in the input then also this select query in the FM should work.How to achieve this..Thank you.Hi Karthik,
I hope following code will solve your problem. Here, it_itab should be your table declared in the interface of your your function module. Use should pass zz1,zz2 to it_itab. Here, I have taken only three fields and written the code. You will have to tweak it a bit to suit your scenario. So, based on the entries in the it_itab, your fields that need to be selected from the database and condition to be evaluated will be generated dynamically.
TYPES : BEGIN OF x_itab,
field TYPE string,
END OF x_itab.
DATA : it_itab TYPE TABLE OF x_itab,
it_vbak TYPE TABLE OF vbak,
x_itab TYPE x_itab,
v_select TYPE string,
v_condition TYPE string.
LOOP AT it_itab INTO x_itab.
IF sy-tabix = 1.
v_select = x_itab-field.
ELSE.
CONCATENATE v_select x_itab-field INTO v_select SEPARATED BY space.
ENDIF.
CASE x_itab-field.
WHEN 'VBELN'.
IF sy-tabix = 1.
v_condition = 'VBELN = X_ITAB-FIELD'.
ELSE.
CONCATENATE v_condition 'AND VBELN = X_ITAB-FIELD' INTO v_condition
SEPARATED BY space.
ENDIF.
WHEN 'ERNAM'.
IF sy-tabix = 1.
v_condition = 'ERNAM = X_ITAB-FIELD'.
ELSE.
CONCATENATE v_condition 'AND ERNAM = X_ITAB-FIELD' INTO v_condition
SEPARATED BY space.
ENDIF.
WHEN 'ERDAT'.
IF sy-tabix = 1.
v_condition = 'ERDAT > 20070405'.
ELSE.
CONCATENATE v_condition 'AND ERDAT > 20070405' INTO v_condition
SEPARATED BY space.
ENDIF.
ENDCASE.
ENDLOOP.
CONCATENATE v_condition '.' INTO v_condition.
SELECT (v_select)
FROM vbak
INTO CORRESPONDING FIELDS OF TABLE it_vbak
WHERE (v_condition).
Reward points if the answer is helpful.
Regards,
Mukul -
How to re-write this big SELECT Query with INNER JOINs?
Hi Experts
I have a performance killer SELECT query with an inner join of 3 tables u2013 VBAP, VBAK and VBEP together, which populates records to an internal table INT_COLL_ORD. Based on these records selected, in another SELECT query, records are fetched from VBUK table to the internal table INT_VBUK.
SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV D~AUART E~ETTYP E~EDATU
INTO TABLE INT_TAB_RES
FROM VBAP AS A INNER JOIN VBAK AS D
ON D~VBELN EQ A~VBELN AND D~MANDT EQ A~MANDT
INNER JOIN VBEP AS E
ON E~VBELN EQ A~VBELN AND E~POSNR EQ A~POSNR AND E~MANDT EQ A~MANDT
WHERE A~VBELN IN s_VBELN AND
D~auart in s_auart AND
D~vkorg in s_vkorg AND
D~vbtyp eq 'C' AND
( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
A~ABGRU EQ SPACE AND
A~MTVFP IN R_MTVFP AND
A~PRCTR IN R_PRCT AND
E~ETENR EQ '1'.
SORT INT_COLL_ORD BY VBELN POSNR ETTYP.
DELETE ADJACENT DUPLICATES FROM INT_TAB_RES COMPARING VBELN POSNR.
CHECK NOT INT_TAB_RES [] IS INITIAL.
SELECT VBELN UVALL CMGST INTO TABLE INT_VBUK
FROM VBUK FOR ALL ENTRIES IN INT_TAB_RES
WHERE VBELN = INT_TAB_RES-VBELN AND UVALL NE 'A'.
Now, the requirement is:
I want to split this query. Like, first join VBAK and VBUK first. With this selection, go to the inner join of VBAP and VBEP (on key VBELN) to get the results. How can I re-write this Query?
Please help.
Thx n RgdsHi Nagraj
As of your suggestion, I have re-written the query as below:
* Declarations
TYPES: BEGIN OF TYP_COLL_ORD,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBUP-POSNR,
MATNR LIKE VBAP-MATNR,
KWMENG LIKE VBAP-KWMENG,
KBMENG LIKE VBAP-KBMENG,
ERDAT LIKE VBAK-ERDAT,
ERZET LIKE VBAK-ERZET,
PSTYV LIKE VBAP-PSTYV,
AUART LIKE VBAK-AUART, u201Calready exists in type
ETTYP LIKE VBEP-ETTYP,
EDATU LIKE VBEP-EDATU.
TYPES: END OF TYP_COLL_ORD.
DATA: INT_COLL_ORD TYPE TABLE OF TYP_COLL_ORD WITH HEADER LINE.
TYPES: BEGIN OF TYP_VBUK,
AUART LIKE VBAK-AUART, u201Chave added this field
VBELN LIKE VBUK-VBELN,
UVALL LIKE VBUK-UVALL,
CMGST LIKE VBUK-CMGST.
TYPES: END OF TYP_VBUK.
DATA: INT_VBUK TYPE TABLE OF TYP_VBUK WITH HEADER LINE.
*QUERY#1 u2013 for VBAK & VBUK Join
SELECT A~AUART B~VBELN B~UVALL B~CMGST
INTO TABLE INT_VBUK
FROM VBAK AS A INNER JOIN VBUK AS B
ON A~VBELN EQ B~VBELN
WHERE A~VBELN IN s_VBELN AND
A~auart in s_auart AND
A~vkorg in s_vkorg AND
A~vbtyp eq 'C' AND
B~UVALL NE 'A'.
IF NOT INT_VBUK[] IS INITIAL.
SORT INT_VBUK BY VBELN.
DELETE ADJACENT DUPLICATES FROM INT_VBUK COMPARING VBELN.
*QUERY#2 u2013 for VBAP & VBEP Join
SELECT A~VBELN A~POSNR A~MATNR A~KWMENG A~KBMENG A~ERDAT A~ERZET A~PSTYV B~ETTYP B~EDATU
INTO TABLE INT_COLL_ORD
FROM VBAP AS A INNER JOIN VBEP AS B
ON B~VBELN EQ A~VBELN AND B~POSNR EQ A~POSNR AND B~MANDT EQ A~MANDT
FOR ALL ENTRIES IN INT_VBUK
WHERE A~VBELN = INT_VBUK-VBELN AND
( ( matnr LIKE c_prefix_sp AND zz_msposnr NE 0 AND kbmeng EQ 0 )
OR ( matnr LIKE c_prefix_fp AND kwmeng NE A~kbmeng ) ) AND
A~ABGRU EQ SPACE AND
A~MTVFP IN R_MTVFP AND
A~PRCTR IN R_PRCT AND
B~ETENR EQ '1'.
ENDIF.
SORT INT_COLL_ORD BY VBELN POSNR ETTYP.
DELETE ADJACENT DUPLICATES FROM INT_COLL_ORD
COMPARING VBELN POSNR.
CHECK NOT INT_COLL_ORD[] IS INITIAL.
LOOP AT INT_COLL_ORD.
CLEAR: L_MTART,L_ATPPR,L_ETTYP.
IF L_PREVIOUS_ETTYP NE INT_COLL_ORD-ETTYP OR
L_PREVIOUS_AUART NE INT_COLL_ORD-AUART.
READ TABLE INT_OVRCTL WITH KEY AUART = INT_COLL_ORD-AUART ETTYP = INT_COLL_ORD-ETTYP.
CHECK SY-SUBRC NE 0.
Now, the issue is:
Please note that declaration for INT_COLL_ORD has a field AUART, which is used in further parts of program (see the statement just above)
But, since neither VBAP nor VBEP contains AUART field, it cannot be fetched through the QUERY#2. So this value is not populated into INT_COLL_ORD through SELECT Query.
Since this field is used in later part of program & that the internal table has no value for this field, it dumps!!
How to include this value into the INT_COLL_ORD?
Plz suggest.... -
Need help in writing a select query to pull required data from 3 tables.
Hi,
I have three tables EmpIDs,EmpRoles and LatestRoles. I need to write a select Query to get roles of all employees present in EmpIDs table by referring EmpRoles and LatestRoles.
The condition is first look into table EmpRoles and if it has more than one entry for a particular Employee ID than only need to get the Role from LatestRoles other wise consider
the role from EmpRoles .
Sample Script:
Create Table #EmpIDs
(EmplID int )
Create Table #EmpRoles
(EMPID int,Designation varchar(50))
Create Table #LatestRoles
EmpID int,
Designation varchar(50)
Insert into #EmpIDs values (1),(2),(3)
Insert into #EmpRoles values (1,'Role1'),(2,'Role1'),(2,'Role2'),(3,'Role1')
Insert into #LatestRoles values (2,'Role2')
Employee ID 2 is having two roles defined in EmpRoles so for EmpID 2 need to fetch Role from LatestRoles table and for
remaining ID's need to fetch from EmpRoles .
My Final Output of select query should be like below.
EmpID Role
1 Role1
2 Role2
3 Role1
Please help.
MohanMohan,
Can you check if this answers your requirement:
Create Table #EmpIDs
(EmplID int )
Create Table #EmpRoles
(EMPID int,Designation varchar(50))
Create Table #LatestRoles
EmpID int,
Designation varchar(50)
Insert into #EmpIDs values (1)
Insert into #EmpIDs values (2)
Insert into #EmpIDs values (3)
Insert into #EmpRoles values (1,'Role1')
Insert into #EmpRoles values (2,'Role2')
Insert into #EmpRoles values (2,'Role1')
Insert into #EmpRoles values (3,'Role1')
Insert into #LatestRoles values (2,'Role2')
--Method 1
select e.EmplID,MIN(ISNULL(l.Designation,r.Designation)) as Designation
from #empids e
left join #emproles r on e.emplID=r.EmpID
left join #latestRoles l on e.emplID=l.EmpID
group by e.EmplID
--Method 2
;with cte
as
select distinct e.EmplID,r.Designation,count(*) over(partition by e.emplID) cnt
from #empids e
left join #emproles r on e.emplID=r.EmpID
select emplID,Designation
from cte
where cnt=1
UNION ALL
select a.EmplID,l.Designation
from
(select distinct EmplID from cte where cnt>1) a
join #Latestroles l on a.EmplID=l.EmpID
order by emplID
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
How to get result of select query from oracle in VC
Dear All ,
I have a application in oracle which insert the data in the oracle database table.
Now i want to show all the data that has been inserted into the database table in my VC application but i don't know how to handle select query in VC.
Regards
KrishanHi Goivndu
Thanks for your reply .
I know all those things.
I have created the system & alias for my backend oracle system.
I can also see all the stored procedure that are there in my oracle system.
I just want to know how to write a select query in a stored procedure .
you can insert data , Update data through oracle procedure but i don't think there is any way to get the result of select query in stored procedure .
If you know any way to do that please do let me know .
Regards
Krishan -
Can we use concatenate in where clause of a select query
I have a select query as follows....
SELECT ebeln ebelp belnr vgabe bwart DMBTR
FROM ekbe
INTO TABLE i_ekbe
FOR ALL ENTRIES IN i_blck
WHERE ebeln = i_blck-ebeln AND ebelp =
i_blck-ebelp.
Now i want to retrieve data from BKPF ..can i write a select query something like....
select * from BKPF into itab
FOR ALL ENTRIES IN i_ekbe
where awkey = ( conatenate i_ekbe-belnr i_ekbe-gjahr )
OR ELSE...is there any other way to link table ekbe and bseg ???Hi Poonam,
SELECT ebeln ebelp belnr vgabe bwart DMBTR
FROM ekbe
INTO TABLE i_ekbe
FOR ALL ENTRIES IN i_blck
WHERE ebeln = i_blck-ebeln
AND ebelp = i_blck-ebelp.
select *
from BKPF
into table itab
FOR ALL ENTRIES IN i_ekbe
where belnr = i_ekbe-belnr.
If u want to check with AWKEY concatenate into seperate field and then use to check in where condition.
data: lw_awkey(20) type c.
CONCATENATE i_ekbe-belnr i_ekbe-gjahr INTO lw_awkey.
select *
from BKPF
into table itab
FOR ALL ENTRIES IN i_ekbe
where awkey = lw_awkey
Best regards,
raam -
How to include conditions in select query
i want to write a select query wherein plants have to to be fetched from table vekp
and if it is a plant then the set movement type to 999 else leave for exiting.please help me on this>
deep shikha wrote:
> (This is module pool programming)
what is modulepool programming doing in form printing forum.
Please use appropriate forum next time.
кu03B1ятu03B9к -
URGENT: To change the where condition in select query at runtime ?
Hi,
I have to develop a report, 4 which I have created a selection screen with 7 Input Parameters whose value is to be filled by the user while executing the report.
On the basis of this I do the desired selection of output.
But the problem is that how do I write my select Query(where condition) if the user enetrs only 2 Input parameters or 3 or whatever he feels like.
Pls help me out...hi,
check this sample code.
Here i am populating where condition at runtime.
DATA: V_WHERE TYPE STRING.
SELECTION-SCREEN BEGIN OF BLOCK INPUT WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN,
S_ERDAT FOR VBAK-ERDAT.
SELECTION-SCREEN END OF BLOCK INPUT.
START-OF-SELECTION.
PERFORM POPULATE_WHERE.
PERFORM GET_VBAK_DATA.
*& Form POPULATE_WHERE
* Populate Where
FORM POPULATE_WHERE .
IF NOT S_ERDAT[] IS INITIAL.
CONCATENATE 'VBELN IN S_VBELN'
'AND'
'ERDAT IN S_ERDAT'
INTO V_WHERE
SEPARATED BY SPACE.
ELSE.
V_WHERE = 'VBELN IN S_VBELN'.
ENDIF.
ENDFORM. " POPULATE_WHERE
*& Form GET_VBAK_DATA
* GET VBAK DATA
FORM GET_VBAK_DATA .
SELECT VBELN
ERDAT
VBTYP
NETWR
WAERK
VKORG
VTWEG
SPART
INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
FROM VBAK
WHERE VBELN IN S_VBELN
AND ERDAT IN S_ERDAT.
WHERE (V_WHERE).
endform.
Regards
Sailaja. -
I have a dataset like below in two columns ( col1,col2 in table Mytable)
A | ab
A | cd
A | ef
B | xl
B | ik
E | 23
E | op
C | tk
I need a select query which will return first set of every group which I ask for .
For example, if I ask for data for A , B , the select query will return records
A | ab
B | xl
For example, if I ask for data for B ,E the select query will return records..
B | xl
E | 23
For example, if I ask for data for C the select query will return records..
C | tk
How do I write my select query ?Something like this ?
SCOTT@orcl> create table test(col1 varchar2(1),col2 varchar2(2));
Table created.
SCOTT@orcl> insert into test values('A','ab');
1 row created.
SCOTT@orcl> insert into test values('A','cd');
1 row created.
SCOTT@orcl> insert into test values('A','ef');
1 row created.
SCOTT@orcl> insert into test values('B','xl');
1 row created.
SCOTT@orcl> insert into test values('B','ik');
1 row created.
SCOTT@orcl> insert into test values('E','23');
1 row created.
SCOTT@orcl> insert into test values('E','op');
1 row created.
SCOTT@orcl> insert into test values('C','tk');
1 row created.
SCOTT@orcl> commit;
Commit complete.
SCOTT@orcl>
SCOTT@orcl> ed
Wrote file afiedt.buf
1 select * from (
2 select decode(lag(col1) over (order by col1,rownum),null,col1
3 ,col1,null
4 ,col1) col1
5 ,col2
6 from test) aaa
7* where aaa.col1='A'
SCOTT@orcl> /
C CO
A abHTH
Girish Sharma
Maybe you are looking for
-
My skype is quitting when i open it in mac os x 10.6.8
My Skpe is quitting when I open it in mac os x 10.6.8 It had been working fine. Today I did a restart of the system, and now skype quits whenever I open it. I deleted the version that I had, and installed the latest version of skype and it is still
-
i would like to retore this to factory settings? - thanks. new 27 inch imac 10.7 4 op system
-
when I visit music sites can't play music in the Firefox browser although it was working in a good way couple weeks ago. I'm using the latest version of Android 5.0.1 Regards
-
I can't attach a document if it is open "in use by another application"
If I try to attach a word document in Windows Live Hotmail, it says the document is in use by another application. I have to close the application to attach it. This just started recently.
-
Mail merge fails if too many characters?
It seems that if included (imported from Numbers file by merge) field is too large, the result is a blank. Is this true .. or is it failing for another reason?