2009 Jul 09 6:24 PM
MY ztable contains 4 key fields bukrs,vkorg,vbeln,ertim .
SELECT SINGLE * FROM Ztable INTO zitab
WHERE BUKRS = P_bukrs
AND VKORG = P_vkorg
AND vbeln = P_vblen
AND FLAG = 'X'.
Here i am checking whether the record exist or not. but i am not including the key field ertim ie time field in the above query because i am not getting this as input to pass.
But my requirement is to check whether the record exists or not.
Please gurus tell me how to correct it , is there any other way, can i use the any alternative select statement or i need to compulsory add the ertim field also?
SLIN RESULTS :
Syntax check warning
This warning is only displayed in SLIN.
In "SELECT SINGLE ...", the WHERE condition for the key field "ERTIM" does
not test for equality. Therefore, the single record in question may not be
unique.
(You can hide the message using "#EC *)
2009 Jul 09 6:47 PM
Try this.....
SELECT *
FROM Ztable
INTO zitab
upto 1 rows
WHERE BUKRS = P_bukrs
AND VKORG = P_vkorg
AND vbeln = P_vblen
AND FLAG = 'X'.
ENDSELECT.
if sy-subrc eq 0.
write: record exists.
endif.
Try this.....
SELECT *
FROM Ztable
INTO zitab
upto 1 rows
WHERE BUKRS = P_bukrs
AND VKORG = P_vkorg
AND vbeln = P_vblen
AND FLAG = 'X'.
ENDSELECT.
if sy-subrc eq 0.
write: record exists.
endif.
2009 Jul 09 6:28 PM
try :
SELECT distinct * FROM Ztable INTO zitab
WHERE BUKRS = P_bukrs
AND VKORG = P_vkorg
AND vbeln = P_vblen
AND FLAG = 'X'.
if sy-subrc eq 0.
write: record exists.
endif.
2009 Jul 09 6:29 PM
Hi,
Gofor ..SELECT * UPTO 1 ROWS.....ENDSELECT. Instead of SELECT SINGLE...
2009 Jul 09 6:47 PM
Try this.....
SELECT *
FROM Ztable
INTO zitab
upto 1 rows
WHERE BUKRS = P_bukrs
AND VKORG = P_vkorg
AND vbeln = P_vblen
AND FLAG = 'X'.
ENDSELECT.
if sy-subrc eq 0.
write: record exists.
endif.
2009 Jul 09 7:00 PM
Is it not necessary to include the key field to check whether the record exists or not?
and my another question is
to hide the message in slin (You can hide the message using "#EC *)
so i included "#EC * as shown below , but still showing the same message in slin , please correct me if i used it wrongly
SELECT SINGLE * FROM Ztable INTO zitab "#EC *
WHERE BUKRS = P_bukrs
AND VKORG = P_vkorg
AND vbeln = P_vblen
AND FLAG = 'X'.
2009 Jul 10 5:34 AM
hi,
U can try to hide the messages in slin by writing extended check off/on.
Try this
SET EXTENDED CHECK OFF.
SELECT SINGLE * FROM Ztable INTO zitab
WHERE BUKRS = P_bukrs
AND VKORG = P_vkorg
AND vbeln = P_vblen
AND FLAG = 'X'.
SET EXTENDED CHECK ON.
Hope this helps.
Regards,
Sravnthi Chilal
2009 Jul 10 5:55 AM
data:r_ERTIM type range of ertim.
SELECT SINGLE * FROM Ztable INTO zitab
WHERE ertim in r_ertim
BUKRS = P_bukrs
AND VKORG = P_vkorg
AND vbeln = P_vblen
AND FLAG = 'X'.
try to pass empty ranges,this will clear the Slin check.
2009 Jul 10 5:57 AM
Is it not necessary to include the key field to check whether the record exists or not?
2009 Jul 10 6:02 AM
Hi,
It is not always possible to add all the key fields of a table.. It depends on your requirement.. But when you are using SELECT SINGLE it is always safe to use all key fields to get a unique record..
Using key fields ensure performance..
2009 Jul 10 9:56 AM
i need to check whether a record exists or not in the table ,then i need to input all the key fields or not? if yes then what is the correct select statement to use it if two key fields are missing?
2009 Jul 10 10:23 AM
Hi,
As i have already mentioned it is not always essential that you have to use all the key fields.. It depends entirely on your requirement.. If you miss any of the key fields it wil still fetch records for you.. KEY FIELDS ensure performance.. If you mention all key fields then the data fetch from the table will be faster.. But you dont use all key fields, even then the records will be fetched but the performance will be lowered..
Again, if in your requirement two key fields are missing do not use SELECT SINGLE.. It will not fetch unique record always.. For this as already suggested you can use either
SELECT DISTINCT or ..SELECT * UPTO 1 ROWS.....ENDSELECT
Hope i am clear now..
2009 Jul 10 12:58 PM
if your motive is just to check if an entry is ther or not for your selection, then you can try:
select count(*) from ztable where XXXXX
check sy-subrc = 0 for record availability.
or
select field1 upto 1 rows (instead of select * to improve performance)
into w_field1
from ztable
where XXXXX.
endselect.
select single should be used only if you have all the key fields available in the where condition. else use select/endselect.
thanks,
Bikash
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |