Limiting Select query to given number of hits in select paarameter.
Hello,
I have to selec data from a custom table.
SELECT-OPTIONS : S_RECNO FOR ZCUST-RECNO,
parameters: p_maxhit(8).
SELECT * FROM ZCUST into TABLE it_ZCUST
where recno in s_recno.
Now in the select parameters I have option for Maximum data records. How can I limit above selection to maximum hit specified in select parameter (p_maxhit) ?
Regards,
Jainam.
try this way:
TYPES: BEGIN OF it_vbak,
vbeln TYPE vbak-vbeln,
END OF it_vbak.
DATA: lt_vbak TYPE STANDARD TABLE OF it_vbak,
wa_vbka TYPE it_vbak.
SELECT vbeln UP TO 3 ROWS FROM vbak
INTO TABLE lt_vbak.
LOOP AT lt_vbak INTO wa_vbka.
WRITE: sy-tabix.
ENDLOOP.
Similar Messages
-
Select query performance improvement - Index on EDIDC table
Hi Experts,
I have a scenario where in I have to select data from the table EDIDC. The select query being used is given below.
SELECT docnum
direct
mestyp
mescod
rcvprn
sndprn
upddat
updtim
INTO CORRESPONDING FIELDS OF TABLE t_edidc
FROM edidc
FOR ALL ENTRIES IN t_error_idoc
WHERE
upddat GE gv_date1 AND
upddat LE gv_date2 AND
updtim GE p_time AND
status EQ t_error_idoc-status.
As the volume of the data is very high, our client requested to put up some index or use an existing one to improve the performance of the data selection query.
Question:
4. How do we identify the index to be used.
5. On which fields should the indexing be done to improve the performance (if available indexes donu2019t cater to our case).
6. What will be the impact on the table performance if we create a new index.
Regards ,
RaghavQuestion:
1. How do we identify the index to be used.
Generally the index is automatically selected by SAP (DB Optimizer ) ( You can still mention the index name in your select query by changing the syntax)
For your select Query the second Index will be called automatically by the Optimizer, ( Because the select query has u2018Updatu2019 , u2018uptimu2019 in the sequence before the u2018statusu2019 ) .
2. On which fields should the indexing be done to improve the performance (if available indexes donu2019t cater to our case).
(Create a new Index with MANDT and the 4 fields which are in the where clause in sequence )
3. What will be the impact on the table performance if we create a new index.
( Since the index which will be newly created is only the 4th index for the table, there shouldnu2019t be any side affects)
After creation of index , Check the change in performance of the current program and also some other programs which are having the select queries on EDIDC ( Various types of where clauses preferably ) to verify that the newly created index is not having the negative impact on the performance. Additionally, if possible , check if you can avoid into corresponding fields .
Regards ,
Seth -
Questions on the most efficient select query..
What is the difference between the two select query & please explain y is the 2nd select query more efficient??
DATA: MAX_MSGNR type t100-msgnr.
MAX_MSGNR = '000'.
SELECT * FROM T100 INTO T100_WA
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100_WA-MSGNR > MAX_MSGNR.
MAX_MSGNR = T100_WA-MSGNR.
ENDSELECT.
DATA: MAX_MSGNR type t100-msgnr.
SELECT MAX( MSGNR ) FROM T100 INTO max_msgnr
WHERE SPRSL = 'D' AND
ARBGB = '00'.Hi,
First never use Check statement in the Select.
Next thing Select ... end select.
Coming to ur question In case of first select it will fetch each record from the data base and compares that record value with the variable(MAX_MSGNR) and assigns the value to the variable. And this process will continue till the select reads all the records of the data base. Also these operations happens on the data base server. SO this query not only affect ur program but also others who is accessing the same data base.
Second query is most efficient because of the aggregate function MAX. Here it will fetch all the records in single go and checks the max value for that column using
optimising algorithm. So number of checks, assignments(single assignment) and fetches will be less compared to first select. This is the main reason. Hope this clarified ur doubt.
Another thing is in first query we are selecting all the fields where as in second we are selecting only one field(required)
Thanks,
Vinod.
Edited by: Vinod Kumar Vemuru on Mar 13, 2008 4:55 PM -
Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query
Hi All,
There is a Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query in a report painter.
This query is working fine when executed in 4.7 system where as it is running for more time in ECC6.0.
Select query is on the table COSP.
SELECT (FIELD_LIST)
INTO CORRESPONDING FIELDS OF TABLE I_COSP PACKAGE SIZE 1000
FROM COSP CLIENT SPECIFIED
WHERE GJAHR IN SELR_GJAHR
AND KSTAR IN SELR_KSTAR
AND LEDNR EQ '00'
AND OBJNR IN SELR_OBJNR
AND PERBL IN SELR_PERBL
AND VERSN IN SELR_VERSN
AND WRTTP IN SELR_WRTTP
AND MANDT IN MANDTTAB
GROUP BY (GROUP_LIST).
LOOP AT I_COSP .
COSP = I_COSP .
PERFORM PCOSP USING I_COSP-_COUNTER.
CLEAR: $RWTAB, COSP .
CLEAR CCR1S .
ENDLOOP.
ENDSELECT.
I have checked with the table indexes, they were same as in 4.7 system.
What can be the reson for the difference in execution time. How can this be reduced without adjusting the select query.
Thanks in advance for the responses.
Regards,
Dedeepya.Hi,
ohhhhh....... lots of problems in select query......this is not the way you should write it.
Some generic comments:
1. never use SELECT
endselect.
SELECT
into table
for all entries in table
where.
use perform statment after this selection.
2. Do not use into corresponding fields. use exact structure type.
3. use proper sequence of fields in the where condition so that it helps table go according to indexes.
e.g in your case
sequence should be
LEDNR
OBJNR
GJAHR
WRTTP
VERSN
KSTAR
HRKFT
VRGNG
VBUND
PARGB
BEKNZ
TWAER
PERBL
sequence should be same as defined in table.
Always keep select query as simple as possible and perform all other calculations etc. afterwords.
I hope it helps.
Regards,
Pranaya -
How to pass the feild names of a select query dynamically?
Hi
How can we pass the feilds names in select query dynamically?
For example in my selection screen i wil be giving the table name, and feilds in that table.....
those feilds should be taken in my select query...
instead of
PARAMETERS : tab_name TYPE ddobjname .
SELECT *
FROM (tab_name)
INTO TABLE <newtab>
UP TO 25 ROWS.
parametrs : feild1 like-------
feild2----
i need select feild1 feild2 feild3 FROM (tab_name)
INTO TABLE <newtab>
UP TO 25 ROWS.by the way, contrary to popular belief there is no performance problem when using
SELECT * FROM dbtab INTO CORRESPONDING FIELDS OF TABLE itab WHERE ...
as long as the structure of itab contains only the required fields.
I ran some benchmarks against this and above construct is maybe 0.1% slower (Oracle 10g) than a
SELECT f1 f2 f3 f4 ... FROM dbtab INTO TABLE itab WHERE ...
but is saves you from maintaining a potentially very long field list in your code. So when you need additional fields later on, you just add them to the DDIC structure or type definition and that's it.
Maybe something you want to factor in here.
Cheers
Thomas -
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. -
Problem in select query in QUERY INFOSET
Hi All
I have requirement to find the sales text maintained for sales order in mass in production. By using the FM READ_TEXT i can pass the necessary values to get the sales text. We dont want to write a program and then transprot to P01. So what i did in SQ02 i create a infoset and worte code in the infoset. Here i am facing the problem that in the select query where clause what ever on the selection screen values, for that the query need to fetch the records. But selection screen is dymically selected based on SQVI t-code.
In select query if i write like this
SELECT TDOBJECT TDNAME TDID TDSPRAS
FROM STXH
INTO TABLE IT_TEXT_DETAIL
WHERE TDOBJECT EQ C_KNMT .
Here i have hardcoded KNMT so it will fetch only that value irrespective of any values on the selection screen. How to get the values based on the selection screen. I debugged the query it automatically generates the code for selection screen which i am not able to pass in the program.
SAP has generated this code
select-options SP$00004 for STXH-TDOBJECT.
select-options SP$00005 for STXH-TDNAME.
select-options SP$00006 for STXH-TDID.
If i pass SP$00004 on where clause its giving me error. So how to pass it dynamically. Waiting for experts answer.
Regards
VijayHi Vijay,
In this case concatenate 'TDOBJECT' 'EQ' C_KNMT INTO V_WHERE (Say) SEPERATED BY SPACE.
DATA : v_where(90) type c.
clear v_where.
CONCATENATE 'TDOBJECT'
'EQ'
C_KNMT
INTO V_WHERE
SEPERATED BY SPACE.
SELECT TDOBJECT TDNAME TDID TDSPRAS
FROM STXH
INTO TABLE IT_TEXT_DETAIL
WHERE (V_WHERE) .
Try to do this and let me know in case of any.
Regards,
SRinivas -
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 -
Performance improvement for select query
Hi all,
need to improve performace for the below select query as it is taking long time
SELECT vbeln pdstk
FROM vbuk INTO TABLE it_vbuk1 FOR ALL ENTRIES IN it_likp
WHERE vbeln = it_likp-vbeln AND
wbstk = 'C' AND "pdstk = ' ' AND
vbtyp IN gr_delivery AND
( fkstk = 'A' OR fkstk = 'B' ) OR
( fkivk = 'A' OR fkivk = 'B' ).
Regards,
KumarHi,
Check if it_likp is sorted on vbeln.
SELECT vbeln pdstk
FROM vbuk INTO TABLE it_vbuk1 FOR ALL ENTRIES IN it_likp
WHERE vbeln = it_likp-vbeln AND
wbstk = 'C' AND
vbtyp IN gr_delivery AND
( ( fkstk = 'A' OR fkstk = 'B' ) OR <-- check this condition , if ( ) is needed ...
( fkivk = 'A' OR fkivk = 'B' ) ) .
Regards,
Srini. -
Need some help with the Select query.
Need some help with the Select query.
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
select single vkorg abgru from ZADS into it_rej.
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
This is causing performance issue. They are asking me to include the where condition for this select query.
What should be my select query here?
Please suggest....
Any suggestion will be apprecaiated!
Regards,
DeveloperHello Everybody!
Thank you for all your response!
I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table
select vkorg abgru from ZADS into it_rej.
Earlier :
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
Now :
DATA : BEGIN OF IT_REJ occurs 0,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
I guess this will fix the issue correct?
PLease suggest!
Regards,
Developer. -
Issue with one Select Query in PBS Archive Translation Tool
Hi All,
Iam having X mark symbol against the select query from EKET table
This is the select query in my actual program and when i convert this using PBS Archive Translation Tool i have a X mark against this select query
SELECT SINGLE BANFN FROM EKET INTO V_BANFN WHERE EBELN = BSEG-EBELN AND
EBELP = BSEG-EBELP AND
ETENR = '0001'.
I guess i have to modify this select query because EKET table has transaction data and we cannot ignore this X mark.
Let me know if iam wrong
ALso , iam confused whether a select query with X needs to fixed or can be ignored
ThanksHi ,
Any Suggestions
Thanks -
Select query failing to return all values
So I've just completed my first batch insert into DocumentDB and ran into the following irregularity while verifying my documents were added correctly. I am seeing this issue through the Portal Query Explorer and the Python SDK.
I have found 4 id values that are in my collection, but won't get returned in a Select all type query.
Queries I've used to select just that item/document. These work correctly and return my document. Therefore, I assume the document is in the collection.
SELECT * FROM Matches m WHERE m.id = "2997"
SELECT VALUE m.id FROM Matches m WHERE m.id = "2997"
However, when doing a broader SELECT query, some ids are not returned.
SELECT * FROM Matches
SELECT VALUE m.id FROM Matches m
Neither of the above queries return the document with id "2997". I've three other ids where this is the case.
Am I missing something obvious here, or is there a bug? I've added all ~991 documents into the collection using the same batch program.
Edit: Here's a test program I've drawn up to show this issue (you can take my word for it that the clients are initialised correctly): https://gist.github.com/Fitzpasd/1dde776b00eacf68b361
And this prints:
1
991
False
False
False
TrueI also have some issues with pages. When I execute a simple query like:
SELECT x FROM Root x
or
SELECT s FROM Root x JOIN s IN x.Children
(The Children array contains more than 100 items)
And I use the AsDocumentQuery() method in the c# API, iterating through the pages works fine (the continuation token is returned in the request)
But when I execute the following query:
SELECT s FROM Root x JOIN s IN x.Children WHERE x.id = "<guid>"
the continuation token is not returned so I can't get to the next pages.
Is this related to the same bug ? -
i want to count the no. of employees whose endda = '31/12/9999' and stat2 = '3'.
tables are pa0000.
can anyone tell me the select query?DATA: w_noemp TYPE i.
SELECT COUNT(*) INTO w_noemp FROM pa0000
WHERE endda = '99991231'
AND stat2 = '3'. -
Getting Time-Out at Select Query
Dear All,
I am getting Time-Out at particular Select Query.
This error i am getting since last 3 days, before it was working fine. And there is no any change made to program in last 3 days.
select a~qmnum
matnr
kunum
iwerk
spart
into corresponding fields of iviqmel
from ( qmih as a
inner join qmel as b on b~qmnum = a~qmnum )
for all entries in i_tab
where qmart in ('FS', 'ZP')
and iwerk = i_tab-iwerk
and matnr = i_tab-matnr
and kunum = i_tab-kunum
and spart = i_tab-spart.
append iviqmel.
endselect.
In Program table QMEL also using the proper Index.
Can you please give me any suggestion that how to come out from this issue.
Regards,
DharmeshHi Rob,
I run the SQL Trace also, Query is using correct Index.
and I had also chenge the select query.
if not i_tab[] is initial.
select a~matnr a~kunum a~spart
b~qmnum b~iwerk
into corresponding fields of table iviqmel
from qmel as a inner join
qmih as b
on a~qmnum = b~qmnum
for all entries in i_tab
where a~qmart in ('FS', 'ZP')
and a~matnr = i_tab-matnr
and a~kunum = i_tab-kunum
and a~spart = i_tab-spart
and b~iwerk = i_tab-iwerk.
endif.
even its geving time out error.
Regards,
Dharmesh -
Hi,
Can you pls guide me on the use of Dyanamic WHERE Clause in a Select Query?
I came across the syntax:
SELECT * FROM za004 INTO TABLE ia004 WHERE (options).
Here Options is an internal table of type 'RFC_DB_OPT'
But I am unable to fill this internal table correctly.
Can some one pls guild me with sample code.
Regards,
Pankaj Bist.Check this :
DATA: BEGIN OF lt_options OCCURS 10.
INCLUDE STRUCTURE rfc_db_opt.
DATA: END OF lt_options.
CONCATENATE 'PERIV EQ ' '''' 'V8' '''' ' AND' INTO " <-- PERIV is the field name
lt_options-text.
APPEND lt_options.
CONCATENATE 'BDATJ EQ ' '''' l_pyear '''' INTO
lt_options-text.
APPEND lt_options.
Use lt_options in where condition.
Maybe you are looking for
-
Instrument readings in Veristand with a remote system
I am new to National Instruments hardware and Veristand and I'm trying to use an instrument with Veristand to see if I can get readings from that instrument. I am using a PC with Windows Vista and I'm connected through a network to a PXI 8108 control
-
I know, second post, but I got a hold of some old panther cd's from school. So I put disk one in.... and hello? Questionmark. I've tried booting it using open firmware too... also using the command "boot cd:,\\:tbxi". I don't know if this will help,
-
Daisy chaning firewire to import or just use USB?
Two options for importing/downloading video from a camcorder to an external drive. 1. connect the camcorder to the firewire 400 port on the external hard drive, and then connec the external hard drive to the macbook using the other firewire 400 port.
-
Looking to move iTunes interface from one machine to another
I have a NAS server with about 1TB of music and movies on it, most of which I uploaded from my CD and DVD collection. I have a laptop that has all of that 1TB of data loaded into the iTunes interface, yet none of the data is actually stored on the l
-
How to know when the process to be killed
I want to run 4 .exe programs under win98 in sequence, how should i know when does the .exe program end?