Range valuses in Select statment.
Hi experts,
i am retriving the data from the data base table and in where cluse im using the RANGE tables i difiened and appending the values of sign option low ,high to it.
i have defined as:
ranges:post for bsak-budat.
post-sign = post_dat-sign .
post-option = post_dat-option.
post-low = post_dat-low.
post-high = post_dat-high.
append post.
comp-sign = comp_code-sign .
comp-option = comp_code-option.
comp-low = comp_code-low.
comp-high = comp_code-high.
append comp.
vend-sign = vendor-sign .
vend-option = vendor-option .
vend-low = vendor-low.
vend-high = vendor-high .
append vend.
select bukrs gjahr belnr
xblnr lifnr wskto
skfbt waers wrbtr
wmwst augdt budat
bldat cpudt zfbdt
zterm zbd1t zbd2t
zbd3t zbd1p zbd2p
zlsch from bsak into corresponding fields of table g_bsak
where
budat in post and
bukrs in comp and
lifnr in vend .
but in select i am not getting any rows retrieval but entries are there in Table for same condition.
Plz help me how to code ranges values in select statement where condition and in anything wrong in my code mentioned above.
Mahesh
Edited by: mahesh s on Sep 4, 2009 10:59 AM
Hi,
Thats true if you are using select-options to get the values then its not required for you to move into ranges...
but stil if you want to move them into ranges....
use the following code...
ranges:post for bsak-budat.
loop at post_dat.
move post_dat to post.
append post.
endloop.
loop at comp_code.
move comp_code to comp.
append comp.
endloop.
loop at vendor.
move vendor to vend.
append vend.
endloop.
select bukrs gjahr belnr
xblnr lifnr wskto
skfbt waers wrbtr
wmwst augdt budat
bldat cpudt zfbdt
zterm zbd1t zbd2t
zbd3t zbd1p zbd2p
zlsch from bsak into corresponding fields of table g_bsak
where
budat in post and
bukrs in comp and
lifnr in vend .
Regards,
Siddarth
Similar Messages
-
Performace problem in a select statment how to imporve the performance
fist select statment
SELECT a~extno
a~guid_lclic " for next select
e~ctsim
e~ctsex
*revised spec 3rd
f~guid_pobj
f~amnt_flt
f~amcur
f~guid_mobj
e~srvll "pk
e~ctsty "PK
e~lgreg "PK
INTO TABLE gt_sagmeld
FROM /SAPSLL/LCLIC as a
INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
* revised spec 3rd
inner join /sapsll/legcon as f on fguid_lclic = aguid_lclic " for ccngn1 selection
inner join /sapsll/corcts as g on gguid_pobj = fguid_pobj
where a~extno in s_extno.
sort gt_sagmeld by guid_lclic guid_pobj.
lgreg ctsty srvll
delete adjacent duplicates from gt_sagmeld comparing guid_lclic guid_pobj.
it selects about 20 lakh records
belos select statment whichs is taking time as it is based on the entreis of gt_sagmeld
select /sapsll/corpar~guid_mobj
/sapsll/corpar~PAFCT
but000~bpext
but000~partner
/sapsll/corpar~parno
into table gt_but001
from /sapsll/corpar
INNER join but000 on but000partner = /sapsll/corparparno
for all entries in gt_sagmeld
where /sapsll/corpar~guid_mobj = gt_sagmeld-guid_mobj
and /sapsll/corpar~PAFCT = 'SH'.
SELECT /sapsll/cuit~guid_cuit " PK
/sapsll/cuit~QUANT_FLT " to be displayed
/sapsll/cuit~QUAUM " to be displayed
/sapsll/cuit~RPTDT " to be displayed
/sapsll/cuhd~guid_cuhd " next select
/sapsll/cuit~guid_pr " next select
INTO table gt_sapsllcuit
FROM /sapsll/cuit
inner join /sapsll/cuhd on /sapsll/cuitguid_cuhd = /sapsll/cuhdguid_cuhd
FOR all entries in gt_sagmeld
WHERE /sapsll/cuit~guid_cuit = gt_sagmeld-guid_pobj.
Delete adjacent duplicates from gt_sapsllcuit[].
if not gt_sapsllcuit[] is initial.hi navenet
that didnt worked
we need to try ur range options
but not sure what you told in the last mail as not clear with range can u pls eloboragte more i am pasting the full code here
SELECT a~extno
a~guid_lclic " for next select but000
e~ctsim
e~ctsex
e~srvll
e~ctsty
e~lgreg
INTO TABLE gt_sagmeld
FROM /SAPSLL/LCLIC as a
INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
where a~extno in s_extno.
sort gt_sagmeld by guid_lclic.
delete adjacent duplicates from gt_sagmeld comparing all fields.
IF not gt_sagmeld[] is initial.
SELECT /sapsll/legcon~guid_lclic
/sapsll/legcon~guid_pobj
/sapsll/legcon~amnt_flt
/sapsll/legcon~amcur
but000~bpext
*revised spec
/sapsll/corpar~PAFCT
/sapsll/legcon~guid_mobj
/sapsll/cuit~guid_cuit
INTO TABLE gt_but000
FROM /SAPSLL/LEGCON
for all entries in gt_sagmeld
where /SAPSLL/legcon~guid_lclic = gt_sagmeld-guid_lclic.
IF NOT GT_BUT000[] IS INITIAL.
sort gt_but000 by guid_mobj.
delete adjacent duplicates from gt_but000 comparing guid_mobj.
select /sapsll/corpar~guid_mobj
/sapsll/corpar~PAFCT
/sapsll/corpar~parno
into table gt_but001
from /sapsll/corpar
for all entries in gt_but000
where /sapsll/corpar~guid_mobj = gt_but000-guid_mobj.
and /sapsll/corpar~PAFCT = 'SH'.
DELETE gt_but001 where PAFCT <> 'SH'.
*sort gt_corpar by parno.
*delete adjacent duplicates from gt_corpar comparing parno.
*select gd000~partner
gd000~bpext
from gd000 into table gt_but001
for all entries in gt_corpar
where gd000~partner = gt_corpar-parno.
my ultimat aim is to select bpext from gd000
can u please explain how to use ranges here and what is the singnificance and how ill i read the data from the final table if we use ranges
regards
Nishant -
Select statment - where clause
Hello experts,
I want to write a select statment,
e.g.
select * from pa0001 where ename like '%Rahul%'.
so this stamemt will give me all DB rows in which ename contains Rahul but i also want rows those are having rahul or rAhul or raHul or RAhul or RAHul or RaHul like wise....
can u plz help me on this ???Hi
Find the below code which may be useful for your requirement
ranges:r_sel for lfa1-name1.
data:v_name(5) type c value 'laxmi'.
data:len type i,
v_num type i,
v_num1 type i,
v_num2 type i,
v_name1(5) type c,
v_name2(5) type c,
v_name_final(7) type c,
v_char type c.
len = strlen( v_name ).
clear:v_name1,v_name2,v_name_final,v_num,v_num1,v_num2.
v_num1 = len.
do len times.
v_num1 = v_num1 - 1.
v_char = v_name+v_num(1).
v_num2 = v_num.
v_num = v_num + 1.
if v_num1 is initial.
clear:v_name1.
else.
v_name1 = v_name+v_num(v_num1).
endif.
if v_num2 is not initial.
v_name2 = v_name+0(v_num2).
endif.
translate v_char to upper case.
concatenate '' v_name2 v_char v_name1 '' into v_name_final.
r_sel-option = 'CP'.
r_sel-sign = 'I'.
r_sel-low = v_name_final.
clear:r_sel-high.
append r_sel.
translate v_char to lower case.
concatenate '' v_name2 v_char v_name1 '' into v_name_final.
r_sel-option = 'CP'.
r_sel-sign = 'I'.
r_sel-low = v_name_final.
clear:r_sel-high.
append r_sel.
enddo.
Use range parameter in your select statement.
Regards
Sripal -
Hi ,
what is the difference between,select single and
select upto one row .
In a select statment .
Thanks ,
shankar.According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not
using all the primary key fields.
select single is a construct designed to read database records with primary key. In the absence of the primary key,
it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key
supplied and will try to find most suitable index.
The best way to find out is through sql trace or runtime analysis.
Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s)
you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the
second or the third record has the value you are looking for.
The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional
level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause
If this results in multiple records then only the first one will be returned and therefore may not be unique.
Mainly: to read data from
The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that
are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns
the first record of the result set.
Mainly: to check if entries exist.
You can refer to the below link..
http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm -
Af:table range navigation and select with rownum
I'm trying to use af:table to display some data (long list), but the value attribute always returns the entire list. (Basic example)
I'd like to use the range navigation so the application only select a sublist from the database (using rownum between x and y) and also display the navigation pane with all the pages, but I was only able to get the specific page with no navigation pane.
Does anyone have a good example on how to use the range navigation with selects/rownum?Assuming I have an untitled1.jspx page with an Untitled1.java backing bean and an <af:table> on my page whose whose binding attribute is set to the EL expression #{Untitled1.table} to expose the table UI component in the backing bean, and a rangeChangeListener set to the EL expression #{Untitled1.onRangeChanged}, then with the following backing bean class, I seem to have been able to disable the user's picking the "Show all" option. It still appears in the list, but visually picking it stays on the current range of rows.
package test.backing;
import oracle.adf.view.faces.component.core.data.CoreTable;
import oracle.adf.view.faces.event.RangeChangeEvent;
public class Untitled1 {
private CoreTable table;
public Untitled1() {
public void onRangeChanged(RangeChangeEvent rangeChangeEvent) {
int newStart = rangeChangeEvent.getNewStart();
int newEnd = rangeChangeEvent.getNewEnd();
if (newEnd - newStart > getTable().getRows()) {
int oldEnd = rangeChangeEvent.getOldEnd();
int oldStart = rangeChangeEvent.getOldStart();
queueRangeChangeEventForTable(newStart, newEnd, oldStart, oldEnd);
private void queueRangeChangeEventForTable(int oldStart, int oldEnd,
int newStart, int newEnd) {
RangeChangeEvent rce =
new RangeChangeEvent(getTable(), oldStart, oldEnd, newStart, newEnd);
getTable().queueEvent(rce);
public void setTable(CoreTable table) {
this.table = table;
public CoreTable getTable() {
return table;
} -
How to select range of values (select-options) in BDC?
Dear experts,
I need to write a BDC program for the T-code CN72 where i need to handle a range of intervals (select-options) for the WBS element field in the initial screen.I have done the recording. what is the logic in BDC to handle the range of intervals ?
How do we handle the range of intervals?Hi,
Suppose your select-option field name is N_PSPNR .then send the values as N_PSPNR-LOW = 'ABC'
N_PSPNR-HIGH = '678' . In recording u will find the screen field name and what value is passed.
regards
Manish -
Select statment - fill internal table
Hi,
I have following situation:
TYPES: BEGIN OF q_data,
i_lqua LIKE lqua,
v_xxx(20) type c,
END OF q_data.
DATA: a_data TYPE STANDARD TABLE OF q_data.
Now I would write a select statment and fill the table a_data.
select lqua~matnr lqua~werks... from lqua inner join mch1 into (i_lqua-matnr, i_lqua-werks.....)...
Is it possible to write a statement without writing the whole structure (all the names of columns) of lqua in the SQL-statement (lquamatnr lquawerks lqua~........)?
Thanks
Michael1. you can write that but i think you have to write that in SELECT ...ENDSELECT.
select lquamatnr lquawerks... from lqua inner join mch1 into (i_lqua-matnr, i_lqua-werks.....
append i_lqua.
endselect.
2. OR you can use INTO CORRESPONDING FIELDS OF TABLE
select lquamatnr lquawerks... from lqua inner join mch1 into corresponding fields of table i_lqua. -
Using distinct and orderby in the select statment
Hi All,
Can anyone tell me what is the purpose of using distinct and orderby in the select statment.Hi,
Using the distinct function with more than one column yields some substantial results. SQL will return the rows with distinct or unique combinations of those columns. Assume this same employee table has another column including the salary of each employee. With the use of the distinct function we can pull a list of unique job titles - salaries.
SQL Code:
SELECT DISTINCT job_titles, salary FROM employees;
SQL has returned all the rows with unique combinations of job titles and salaries. Any duplicate combinations of job titles and salaries will be ignored. For example if we had two CEOs in the table making the same salary each year, only one row would be returned but if we had two CEOs with different salaries, both rows would be returned.
Order by
The SQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s). For example if you want to select all the persons from the already familiar Customers table and order the result by date of birth, you will use the following statement:
SELECT * FROM Customers
ORDER BY DOB
As you can see the rows are sorted in ascending order by the DOB column, but what if you want to sort them in descending order? To do that you will have to add the DESC SQL keyword after your SQL ORDER BY clause:
SELECT * FROM Customers
ORDER BY DOB DESC
If you don't specify how to order your rows, alphabetically or reverse, than the result set is ordered alphabetically, hence the following to SQL expressions produce the same result:
SELECT * FROM Customers
ORDER BY DOB
SELECT * FROM Customers
ORDER BY DOB ASC
You can sort your result set by more than one column by specifying those columns in the SQL ORDER BY list. The following SQL expression will order by DOB and LastName:
SELECT * FROM Customers
ORDER BY DOB, LastName
if its useful reward points -
Hi,
I am devloping Query with the table DBERCHZ1
it having two fields
V_ ABRMENGE value 456
N_ ABRMENGE value 0.67899
Here i want to print as 456.67899 with one select statment.
is any way to sum in select statment.
ThanksHi,
I have just given a code snippet similar to your requirement.
DATA: average TYPE p DECIMALS 2,
sum TYPE p DECIMALS 2.
SELECT AVG( luggweight ) SUM( luggweight )
INTO (average, sum)
FROM sbook.
WRITE: / 'Average:', average,
/ 'Sum :', sum.
Just replace with your variables and let me know if it works.
Thanks,
Harini -
Dynamic field in select statment.
Hello,
I created a report in which i have two checkboxes in the selection screen. The first checkbox is for the option to bring or not, initial purchase requisitions (BANFN) from EKPO and the second is to bring initial or not, RFQs
(ANFNR). I want the select statment to have this form:
select ...
from ekpo
into g_table
where ..
and dynamic field = " ".
Can this be done ?
i tried to put it as a string but it didnt work. (data: dynamic field type string value "EKPO-BANFN")
P.S i know that it can be by writing the same select code twice.
I just wonder if this can be done by this way
\Regards.Hey Nick,
I have more conditions than the one i said before , should all be in the lv_where_clause ?
check my code.
DATA: G_CHBFLD type STRING.
G_CHBFLD = 'P~BANFN = '' " '.
FORM SELECT_DATA_EKPO_EKKO.
SELECT .....
FROM EKPO AS P INNER JOIN EKKO AS K
ON PEBELN = KEBELN
INTO CORRESPONDING FIELDS OF TABLE GT_EKPOEKKO
WHERE K~EBELN IN S_EBELN
AND K~AEDAT IN S_AEDAT
AND K~BSTYP IN S_BSTYP
and ( G_CHBFLD ) . -
> //DEBUGER ")" is not a valid comparison operator. comparison operator. -
Fix Variable in select statment
Hi,
Can we define a variable in select statment .
Example :
Select firstname , lastname
from employees;
in this simple select statment can we define x as number ?Maybe
SQL> variable x number
SQL> exec :x := 3
PL/SQL procedure successfully completed.
SQL> select :x x, last_name from employees where rownum <= 3
X LAST_NAME
3 King
3 Kochhar
3 De Haan
3 rows selected. -
Problem in select statment & loop of itab.
Hi all,
I am having on ITAB1 for, ex which is having five line items or more .
iam also using select statment SINGLE statment for 7 times ,to select values for
different data base table.
for ex,
loop at itab.
1---> SELECT SINGLE Z_CTRY_ORIG INTO LS_PSHDESN-Z_CTRY_ORIG FROM ZLE_PART_MST
WHERE WERKS = ITAB1-LGNUM
AND MATNR = ITAB1-MATNR .
2---
3---
4---
endloop
i want to remove from the loop statment and i have to select the datas ..
can any one sugesset some possible ways....
regards
veerahi,
Solution:
Never use select single in loop at itab!! for that :
Solution 1:
say ur main table is ITAB and rferring this u want to select data from other tables.
SELECT SINGLE Z_CTRY_ORIG INTO LS_PSHDESN-Z_CTRY_ORIG FROM ZLE_PART_MST
into table itab2
FOR ALL ENTRIES IN ITAB
WHERE WERKS = ITAB-LGNUM
AND MATNR = ITAB-MATNR.
With this what will hapeen , u will get all records in itab2 which u can update itab1(master) using loop.
solution 2:
Instead of all this use JOINs in select statement properly and u can fetch data in one shot this will reduce database load as well as abap load ( More than 3 joins in SELECT stmt are not recommeded but can be used)
I believe this is perfect solution if and only if u are giving joins on KEY fields only. Same is applied for wherer clause.
Hope this will help u, if not revert.
Jogdand M B -
Running DBMS_SQL.EXECUTE in Oracle Select Statment
HI i have table Emp which has 3 column namely name,st_date and end_date. table has 3 records as below:
name st_date end_date
X sysdate+10 sysdate+50
Y sysdate+12 sysdate+30
Z sysdate+15 sysdate+35
Now if i run the run select statment select * from emp, it will show above values. but i need the values in the columns to be executed and shown in the select statemtn with alias column i.e. assign sysdate is : 01-jan-2013
so i need the o/p to be:
X 20-Jan-2013 19-Feb-2013
Y 22-Jan-2013 30-Jan-2013
Z 15-Jan-2013 04-feb-2013
i dont want to create a function in plsql and pass the values to it. if u use select name,dbms_sql.execute(dbms_sql.parse(dbms_sql.open(),'select st_date from emp'))) is ok for me.
Advance Thanks for your help!!
i have restriction not able to create function, so i need to try in the sql statment only!!997199 wrote:
HI i have table Emp which has 3 column namely name,st_date and end_date. table has 3 records as below:
name st_date end_date
X sysdate+10 sysdate+50
Y sysdate+12 sysdate+30
Z sysdate+15 sysdate+35
Now if i run the run select statment select * from emp, it will show above values. but i need the values in the columns to be executed and shown in the select statemtn with alias column i.e. assign sysdate is : 01-jan-2013
so i need the o/p to be:
X 20-Jan-2013 19-Feb-2013
Y 22-Jan-2013 30-Jan-2013
Z 15-Jan-2013 04-feb-2013
i dont want to create a function in plsql and pass the values to it. if u use select name,dbms_sql.execute(dbms_sql.parse(dbms_sql.open(),'select st_date from emp'))) is ok for me.
Advance Thanks for your help!!
i have restriction not able to create function, so i need to try in the sql statment only!!How do I ask a question on the forums?
SQL and PL/SQL FAQ
what datatype are st_date & end_date? -
Report writer/Report painter - How to define the range on the selection scr
Hi,
I want to use one field "Fiscal year for CG breakdown" in my customized report in which user can select the year in range ie FROM - to - TO range.
Can anybode tell me how do we define the range in the selection screen?
I have tried using the General data selection.. but its not working.
Edited by: Seema Nakhale on Oct 7, 2008 11:13 AMHi,
Create a variable for the Fiscal Year field in tcode GS11. While creating the variable for the field, use the option "Value Entry Only".
Thereafter refer the variable in the "General Data Selection" for the field with the options "Set" and "Variable" both ticked for the fiscal year. Also enter the variable name created above in the field in General Data Selection.
This will allow you to enter the fiscal year as range while executing the report.
Regards,
Ramanand -
Table list for select statment
hello all,
I been trying to setup a plsql statment to run a select statment from tables that are in a list.
this is what I have done so far as a test and it is not letting me do it and I don't know why can anyone point me in the right direction.
declare
cursor main_log is
select *
from joseph_w.table_name_list;
cml main_log%rowtype;
var1 varchar2(35);
var2 varchar2(35;
begin
open main_log;
fetch main_log into cml;
var1 := cml.schema_name;
var2 := cml.table_name;
select *
from var1.var2;
close main_log;
end;
thanksIn PL/SQL you cannot just "select", as PL/SQL is a server sided language. You must use a record or variable to hold the selected data. Anyway, for selecting from different tables dynamically, you can use (Native) Dynamic SQL or Ref Cursors. Take a look at the documentation, especially the "PL/SQL User's Guide and Reference":
http://www.oracle.com/pls/db102/portal.portal_db?selected=1
Regards,
Gerd
Maybe you are looking for
-
Cost center and profit center in the same report
I am working on creating a report using report painter/writer. my question is, will it be possible to create a report with cost center group in one column and profit center group in another column and the rows with GL account groups. I know that GLPC
-
Dispatcher starts and stops immediately
Dispatcher is starts and stops immediately and all the work process are died state. We don't have the backup of database also? Database in suspect mode , How can recover from this situation? Thanks Srikanth
-
Mac OSX 10.5.8 to Windows 7
I've done a very quick search but not found anything - I know it must be out there but I'm obviously not using the correct search terms... Hoping someone will take pity and help me out. All my music and iPhone stuff is currently on my iMac running 10
-
PB will not start/run on battery
Hey everyone, I posted this on the power & batteries forum, but judging by the dates on the replies to other threads it seems like a VERY slow forum. So here goes... Just got a Powerbook G4 17", 1.67 ghz 2gigs ram but I have a problem. It will not st
-
TS1331 i have tried all the possible way to install itunes on win8 but still not working
microsoft.VC80.CRT.type="win32".version="8.0.50727.6195".publicKeyToken="1fc8b3b 9a1e18e3b".processorArchitecture="x86". how can i solve this error and install itunes on my PC with windows 8 OS?