Regarding Data Base Select Query
Hi All,
I want to extract the data from data base into my internal table
by not giving the exact value but the pattern.
Ex) I want to select the vendor starting with patter '12*'
from LFA table in my internal table.
Which select Query I should use for getting the
Vendor No. starting with pattern '12*' ?.
Points will be rewaded.
Thanks in Advance.
With Regards
Jitendra Gujarathi.
Hi jitendra,
1. simple
2.
select * from lfa1
into table lfa1
where lifnr like '12%'.
regards,
amit m .
Similar Messages
-
Regarding performance in select query
hi to all,
i wrote select query for fetching duplicate records,like select distinct *.
so at runtime it fetches all fields in table (FI dbtable).
but i want to fetch only 8 records,for this i am using
select distinct
field1
field2
..... like this ,it wasnt excuted.
how can i avoid this issue.
in program not much logic is there,only fetching the data and summation,n display.....
plz giv me reply asap.
regards
satyasatya wrote:>
> hi to all,
>
> i wrote select query for fetching duplicate records,like select distinct *.
> so at runtime it fetches all fields in table (FI dbtable).
>
> but i want to fetch only 8 records,for this i am using
> select distinct
> field1
> field2
> ..... like this ,it wasnt excuted.
>
> how can i avoid this issue.
> in program not much logic is there,only fetching the data and summation,n display.....
>
> plz giv me reply asap.
>
> regards
> satya
Hi,
write like this
> select field1
> field2
> .......
> from table
> into ( itab-f1,
> itab-f2,
> ........ )
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Feb 19, 2008 5:14 PM -
Order mismatch in selected data using Select query
Hello Experts,
We are upgrading from 4.6C to ECC6. I came across a select query on a custom table, which gives different order of data from 4.6C to ECC6. Data (no. of records) is same in both the servers but order is different. Table doesn't have indexes in either 4.6C or ECC6. What would be the cause for order change?
Further, in 4,6C, ECC6 and data bases order of the data is totally different. Select query have some conditions in where clause with select options, but in both the cases (4.6C and ECC6) I am not passing any data from the selection screen so am getting entire data from the data base.
Thanks in advance
PhalaniFrom the SAP service market place I found that
1. Unless we use SORT or ORDER BY clause the order of the data is not in our control.
2. In 4.6C, two same select queries never give the result in the same order, if the primary key contains character fields.
Thanks for your help.
Phalani -
Comparing dates in select query.
Hi Experts,
I need to select data from one table such that the date field of the table should be either today's date or earlier date.
How can I write such comparison statement in select query.hi,
select * from <your_table>
where <date_field> <= sy-datum.
endselect .
regards,
burak -
Regarding StoredProcedure or SELECT Query...
Hi every one..,
can any one help me to create a StoredProcedure or a SELECT query....
i know its not the correct place, but some one may had faced this scenario...... : )
pls help me...
i have to select the maximum value for each day...
ie.,
this what by database will hold.
date | time | value
2007-01-02 | 10:00:00 | 1236.75
2007-01-02 | 11:00:00 | 1236.75
2007-01-02 | 12:00:00 | 1236.75
2007-01-03 | 11:00:00 | 1236.75
2007-01-03 | 12:00:00 | 1236.75
2007-01-03 | 13:00:00 | 1236.75
2007-01-04 | 10:00:00 | 1245.5
2007-01-04 | 11:00:00 | 1236.75
2007-01-04 | 13:00:00 | 1255.75
My result set should hold the following values....
2007-01-02 | 12:00:00 | 1236.75
2007-01-03 | 13:00:00 | 1236.75
2007-01-04 | 13:00:00 | 1255.75
how can i write the query....
pls help me..
for two days im struggling to generate the result set...
and finally posted this thread....
Pls pls help me...
waiting for a valuable reply a small boy called....
SivaKumari have to select the maximum value for each
day...
date | time | value
2007-01-02 | 10:00:00 | 1236.75
2007-01-02 | 11:00:00 | 1236.75
2007-01-02 | 12:00:00 | 1236.75
2007-01-03 | 11:00:00 | 1236.75
2007-01-03 | 12:00:00 | 1236.75
2007-01-03 | 13:00:00 | 1236.75
2007-01-04 | 10:00:00 | 1245.5
2007-01-04 | 11:00:00 | 1236.75
2007-01-04 | 13:00:00 | 1255.75
My result set should hold the following values....
2007-01-02 | 12:00:00 | 1236.75
007-01-03 | 13:00:00 | 1236.75
2007-01-04 | 13:00:00 | 1255.75
********select date, max(value)
from table
group by date -
Reducing Data base selection time
Hi,
I need to get the Excise Documnets which are not Billed. For that I've used following logic. But it is taking much time to get the data.
SELECT a~exnum
a~exyear
a~exdat
a~rdoc2
SUM( a~exbed )
SUM( a~ecs )
SUM( a~exaddtax1 )
b~vbtyp
b~knumv
b~bukrs
b~kunrg
FROM j_1iexcdtl AS a INNER JOIN vbrk AS b
ON ardoc2 EQ bvbeln
INTO TABLE lt_excise WHERE a~exdat IN s_fkdat AND
a~status EQ 'C' AND
a~exdat ge '20090401' AND
NOT EXISTS ( SELECT vbeln FROM vbrk WHERE vbeln EQ a~rdoc3 AND
vbtyp EQ 'M' ) AND
b~vbtyp EQ 'U' AND
b~bukrs IN s_bukrs AND
b~kunrg IN s_kunrg
GROUP BY a~exnum
a~exyear
a~exdat
a~rdoc2
b~vbtyp
b~knumv
b~bukrs
b~kunrg.
Pl help to reduce the time for database selection.
Regards,
Rajiv. VHi,
To decrease the load on DB ,you can process Group by and SUM functions in Loop Endloop of resulting table.
Avoid using Subqueries with not condition.I read ,NOT compromises the index and starts linear search.
There are already many discussions on usage on For all entries and Join .So search forum for more details.
The performance of join and For all entries are context oriented.
SELECT a~exnum
a~exyear
a~exdat
a~rdoc2
SUM( a~exbed ) " Avoid using SUM use Control break in loop endloop
SUM( a~ecs )
SUM( a~exaddtax1 )
b~vbtyp
b~knumv
b~bukrs
b~kunrg
FROM j_1iexcdtl AS a INNER JOIN vbrk AS b
ON a~rdoc2 EQ b~vbeln "Rdoc2 is available in secondary index ,I am not sure whether this affects the performance ,EXPERT advice is required
INTO TABLE lt_excise WHERE a~exdat IN s_fkdat AND
a~status EQ 'C' AND
* a~exdat ge '20090401' AND "if possible, try to use indexed fields from VBRK
NOT EXISTS ( SELECT vbeln FROM vbrk WHERE vbeln EQ a~rdoc3 AND "Avoid using Not this would compromise the index or use Delete itab on resulting table
vbtyp EQ 'M' ) AND
b~vbtyp EQ 'U' AND
b~bukrs IN s_bukrs AND
b~kunrg IN s_kunrg
GROUP BY a~exnum " Avoid Group by
a~exyear
a~exdat
a~rdoc2
b~vbtyp
b~knumv
b~bukrs
b~kunrg. -
Regarding Data base Adjustment
Hi All,
while adjusting data base in SE14 i got an error in converting QCM8TAB to TAB so i unlock the table and continue. Actually in this process QCM8TAB is a temporary table its need to be deleted after adjusting. but because of the process was not completed QCM8TAB was not deleted.how to delete QCM8TAB.
Thanks,
AnanthHave u deleted the records in the table and then tried to delete the table from SE11? I think after u delete the records u can also delete the table from SE14.. Try it..
Hope it may helps.
Please reward if it helps.
Thanks in advance,
Phani -
Regarding dates and selection screen
Hi all,
In my selection screen i have 2 date fields(ranges). I have a requirement wherein i have to allow user to select only one date i.e. let the date fields be date1 and date2 when the user enters date1 he should not be allowed to enter date2 and when the user enters date2 then he should not be allowed to enter date1.
when user enters date1 and tries to enter date2 then a message should be displayed.
pls urgent requirement and points are gauranteed.
Regards,
Ravitry this code
slect-options : sdate1 for mkpf-budat,
sdate2 for mkpf-budat.
parameters : rdate1 radiobutton group rb1 user-command date default 'X',
rdate1 radiobutton group rb1.
at selection-screen output.
if rdate1 = 'X'.
loop at screen.
if screen-name = sdate2-low or screen-name = sdate2-high.
screen-input = '0'.
modify screen.
elseif rdate2 = 'X'.
loop at screen.
if screen-name = sdate1-low or screen-name = sdate1-high.
screen-input = '0'.
modify screen.
endif.
at selection-screen.
if rdate1 = 'X'.
clear sdate2[].
elseif rdate2 = 'X'.
clear sdate1[].
endif.
START-OF-SELECTION.
regards
shiba dutta -
Regarding data conflict at Query Report
Hi Experts,
I have an issue like at R3 side the currency field data is showing as 9,999,999.000., when it came to BW side it is showing
data as 9.999.999,000. But in my report i need to show R3 side data only.
Infoobject is defined as currency with dec point.Can anyone let me know of how to change it to show as R3 side data.
Thank you.Hi there,
Can you please check the information from the following links:
http://help.sap.com/saphelp_nw04/helpdata/en/7d/1a1e3f762cd036e10000000a114084/content.htm
http://help.sap.com/saphelp_sm32/helpdata/en/80/1a6806e07211d2acb80000e829fbfe/content.htm
It should help,
Thanks,
Diego Seben. -
How to store select query output in arrays.
i created a varray type variables and now want to assign some data though select query output in pl/sql code as well as in reports 6i.
You're in the wrong forum (this one is for issues with the SQL Developer tool). You were in the right one where you posted first, but don't reuse unrelated threads as you did.
Regards,
K. -
Retrive data base details of all tables
how can i retrive the
table name, no of rows in that table, no of indexs in that table, no of not null col's in that table
of in single data base(genuine query).Here's a starter...
The best way to count the number of rows on a table is not to look in the data dictionaries but to actually count the rows...
Laurent Schneider
http://laurentschneider.com/wordpress/2007/04/how-do-i-store-the-counts-of-all-tables.html
SQL> select
2 table_name,
3 to_number(
4 extractvalue(
5 xmltype(
6 dbms_xmlgen.getxml('select count(*) c from '||table_name))
7 ,'/ROWSET/ROW/C')) count
8 from user_tables
9 where iot_type != 'IOT_OVERFLOW';
TABLE_NAME COUNT
DEPT 4
EMP 14
BONUS 0
SALGRADE 5
Index Organized Table - Overflow Table
If such tables exist they cannot have "count(*)" done on them -
ORA-25191: cannot reference overflow table of an index-organized table Other information is in the various database dictionary views.
Edited by: BluShadow on Sep 3, 2008 12:18 PM
For some reason this new Jive forum doesn't allow "not equals" as in "<" and ">" when posted together in the code. Stupid forum. -
Regarding "select query" on performance basis..
Hi Experts,
I am creating an ALV report,so that i have to collect all data in 1 internal table.
I have to collect data from 3 standard tables i.e.T157E,MSEG,MKPF.
For all entries of T157E, i have to fetch data from MSEG.
But in where condition i have to give POSTING DATE n this field is in MKPF.
Also Database performance analysis is around 98%.
How can i give better performance, please help..
Below is my coding...
(second select query is taking too much time,how can i rectify)
SELECT BWART
GRUND
FROM T157D
INTO CORRESPONDING FIELDS OF TABLE IT_MOV_TYPE.
SELECT MATNR
MJAHR
MBLNR
BWART
WERKS
LGORT
CHARG
GRUND
MENGE
MEINS
FROM MSEG
INTO CORRESPONDING FIELDS OF TABLE IT_MSEG
FOR ALL ENTRIES IN IT_MOV_TYPE
WHERE GRUND = IT_MOV_TYPE-GRUND
AND BWART = IT_MOV_TYPE-BWART
AND WERKS = PLANT
AND LGORT IN ST_L.
SORT IT_MSEG BY MBLNR.
LOOP AT IT_MSEG.
AT NEW MBLNR.
SELECT SINGLE BUDAT
FROM MKPF
INTO V_BUDAT
WHERE MBLNR = IT_MSEG-MBLNR
AND MJAHR = IT_MSEG-MJAHR.
SELECT SINGLE MAKTX
FROM MAKT
INTO V_MAKTX
WHERE MATNR = IT_MSEG-MATNR.
SELECT SINGLE GRTXT
FROM T157E
INTO V_GRTXT
WHERE GRUND = IT_MSEG-GRUND.
ENDAT.
IT_MSEG-BUDAT = V_BUDAT.
IT_MSEG-MAKTX = V_MAKTX.
IT_MSEG-GRTXT = V_GRTXT.
MODIFY IT_MSEG.
ENDLOOP.
Regards,
AnkurBefore you use
FOR ALL ENTRIES IN
Do the following :
1. Sort the Internal table used in the 'FOR ALL ENTRIES IN' clause.
2. Make sure they do not contain duplicates.
3. Last and most importantly include a primary key field(Unique entry) in the select list. The reason, the system gets unique field records based on the where condition. It summarizes the data based on the Data type and field list in the target internal table.
One should be sure the internal table, used in the FOR ALL ENTRIES clause is not empty. If the table is empty, ALL ENTRIES will be selected. (Actually, all WHERE clauses are neglected). Of course, you should also be sure you select on INDEX fields. Otherwise the use of FOR ALL ENTRIES increases the runtime instead of improving it. -
Performance problem in select data from data base
hello all,
could you please suggest me which select statement is good for fetch data form data base if data base contain more than 10 lac records.
i am using SELECT PACKAGE SIZE n statement, but it's taking lot of time .
with best regards
srinivas rathodHi Srinivas,
if you have huge data and selecting ,you could decrease little bit time if you use better techniques.
I do not think SELECT PACKAGE SIZE will give good performance
see the below examples :
ABAP Code Samples for Simple Performance Tuning Techniques
1. Query including select and sorting functionality
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mast-werks,
aenam like mast-aenam,
stlal like mast-stlal,
end of itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on
fmatnr = gmatnr where gstlal = '01' order by fernam.
Code B
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mast-werks,
aenam like mast-aenam,
stlal like mast-stlal,
end of itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on f~matnr =
gmatnr where gstlal = '01'.
sort itab_new by ernam.
Both the above codes essentially do the same function, but the execution time for code B is considerably lesser than that of Code A. Reason: The Order by clause associated with a select statement increases the execution time of the statement, so it is profitable to sort the internal table once after selecting the data.
2. Performance Improvement Due to Identical Statements Execution Plan
Consider the below queries and their levels of efficiencies is saving the execution
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mast-werks,
aenam like mast-aenam,
stlal like mast-stlal,
end of itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on f~matnr =
gmatnr where gstlal = '01' .
sort itab_new.
select fmatnr fernam
fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as
f inner join mast as g on f~matnr =
gmatnr where gstlal
= '01' .
Code D (Identical Select Statements)
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mast-werks,
aenam like mast-aenam,
stlal like mast-stlal,
end of itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on f~matnr =
gmatnr where gstlal = '01' .
sort itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on f~matnr =
gmatnr where gstlal = '01' .
Both the above codes essentially do the same function, but the execution time for code B is considerably lesser than that of Code A. Reason: Each SQL statement during the process of execution is converted into a series of database operation phases. In the second phase of conversion (Prepare phase) an execution plan is determined for the current SQL statement and it is stored, if in the program any identical select statement is used, then the same execution plan is reused to save time. So retain the structure of the select statement as the same when it is used more than once in the program.
3. Reducing Parse Time Using Aliasing
A statement which does not have a cached execution plan should be parsed before execution; this parsing phase is a highly time and resource consuming, so parsing time for any sql query must include an alias name in it for the following reason.
1. Providing the alias name will enable the query engine to resolve the tables to which the specified fields belong to.
2. Providing a short alias name, (a single character alias name) is more efficient that providing a big alias name.
Code E
select jmatnr jernam jmtart jmatkl
gwerks gaenam g~stlal into table itab_new from mara as
j inner join mast as g on jmatnr = gmatnr where
g~stlal = '01' .
In the above code the alias name used is j .
4. Performance Tuning Using Order by Clause
If in a SQL query you are going to read a particular database record based on some key values mentioned in the select statement, then the read query can be very well optimized by ordering the fields in the same order in which we are going to read them in the read query.
Code F
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
end of itab_new.
select MATNR ERNAM MTART MATKL from mara into table itab_new where
MTART = 'HAWA' ORDER BY MATNR ERNAM MTART MATKL.
read table itab_new with key MATNR = 'PAINT1' ERNAM = 'RAMANUM'
MTART = 'HAWA' MATKL = 'OFFICE'.
Code G
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
end of itab_new.
select MATNR ERNAM MTART MATKL from mara into table itab_new where
MTART = 'HAWA' ORDER BY ERNAM MATKL MATNR MTART.
read table itab_new with key MATNR = 'PAINT1' ERNAM = 'RAMANUM'
MTART = 'HAWA' MATKL = 'OFFICE'.
In the above code F, the read statement following the select statement is having the order of the keys as MATNR, ERNAM, MTART, MATKL. So it is less time intensive if the internal table is ordered in the same order as that of the keys in the read statement.
5. Performance Tuning Using Binary Search
A very simple but useful method of fine tuning performance of a read statement is using Binary search addition to it. If the internal table consists of more than 20 entries then the traditional linear search method proves to be more time intensive.
Code H
select * from mara into corresponding fields of table intab.
sort intab.
read table intab with key matnr = '11530' binary search.
Code I
select * from mara into corresponding fields of table intab.
sort intab.
read table intab with key matnr = '11530'.
Thanks
Seshu -
Hi ABAPERS,
I had written one written one 'select single' query to retrieve the data from PRPS table.
but what the data was selecting for OBJNR (Object number)field based on PSPNR(WBS element) .
That OBJNR values in the report is totally different from the database table OBJNR values.How its possible
I am not getting.So can anyone please help me regarding this...
Thanks and Regards
DeepaHi deepa,
Pass the values to the select query where clause as you can see the values in SE16 display.(This is external format)
If a table field as conversion routine, then SAP dosplay some thing on screen and store some thing else in data base.
To check conversion exit go to domain of that field. Here you can see the routine used.
For example you can check domain MATNR. Externally it display with leading zeros. But internally it stores with out zeros.
Thanks,
Vinod. -
Select query taking too much time to fetch data from pool table a005
Dear all,
I am using 2 pool table a005 and a006 in my program. I am using select query to fetch data from these table. i.e. example is mentioned below.
select * from a005 into table t_a005 for all entries in it_itab
where vkorg in s_vkorg
and matnr in s_matnr
and aplp in s_aplp
and kmunh = it_itab-kmunh.
here i can't create index also as tables are pool table...If there is any solutions , than please help me for same..
Thanks ,it would be helpful to know what other fields are in the internal table you are using for the FOR ALL ENTRIES.
In general, you should code the order of your fields in the select in the same order as they appear in the database. If you do not have the top key field, then the entire database is read. If it's large then it's going to take a lot of time. The more key fields from the beginning of the structure that you can supply at faster the retrieval.
Regards,
Brent
Maybe you are looking for
-
How do I re-register my MacBook in my name, rather than the previous owner?
I just purchased a older MacBook, i've reinstalled the OS X Yosemite and did the whole factory reset thing, the previous owner's account, apps and information has all been completely wiped.. How ever I think the MacBook is still some how registered t
-
GL account assginment interest calculation
Hi as per client requirement we are create 3 interest indicator for customer's account respectively 12%,15% and 18% and create and assign 3 General Ledger account ( individual ) in GL master ( FS00 ).after then client wants create only one genera
-
Quick Time Pro will not launch
10/04/10: I downloaded Quick Time 7 and purchased a key for Pro. I can open video files with QT7Pro but I cannot launch Quick Time from either the short cut that was created or from the All Programs. The only thing that happens is that the Apple Quic
-
I want to send an e mail message existing , am prevented by red plus circle on right of subject line?
-
Will my photos be lost/damaged?
I've updated my 2010 iMac with OS X 10.9 (from 10.6.8) and I can't access my photos without updating iPhoto. The text reads: "Your photo library will not be readable by previous versions of iPhoto after the upgrade. If I upgrade, will my photos be lo