‎2008 Oct 24 9:55 AM
Hi,
Of the below 2 set of codes (Set 1 and set 2 ) which is more optimized? And do i get the same output in both the set of codes?
Set 1
SELECT single JOBNAME
FROM tbtco
into w_jobname
WHERE jobname = jobname AND
( status = 'R' OR status = 'Y' ).
IF sy-subrc = 0.
w_jobnam_found = 'Y'.
ENDIF.
set 2
SELECT * FROM tbtco WHERE jobname = jobname
AND ( status = 'R' OR status = 'Y' ).
IF sy-subrc = 0.
jobname_found = 'Y'.
EXIT.
ENDIF.
ENDSELECT.
regds,
M..
‎2008 Oct 24 10:18 AM
Hi,
Set 1 is more optimised and better than Set2. SAP itself recommends not to use Select..Endselect because of the performance issue.
As you juset need to check whether any entry exist for the given criteria then first Set is perfect.
Thanks & Regards,
Navneeth K.
‎2008 Oct 24 9:58 AM
Hi,
If you are selecting only one job, then select single is enough and select ...endselect is not.
However you need to make sure that when you use select single, you use the primary key, always, in the where clause.
Since you aren't using the primary key to select from the table tbtco, there are chances that you will get multiple records and select single will not work as expected.
regards,
Advait
Edited by: Advait Gode on Oct 24, 2008 10:58 AM
‎2008 Oct 24 9:58 AM
1st one is better...
2nd one is similar to aloop and is not usually preffered
‎2008 Oct 24 9:58 AM
Hi madhu,
First of all you will not get same result if there are more data to satisfy your where condition. because SELECT... ENDSELECT works like a loop and will all the data which will satis fy the codition and SELECT SINGLE will choose only the first data which satisfy the condition.
Secondly,if you consider the performance issue , obviously 1st one is better as in SELECT...FROM...INTO works in batch process an losad all the data in the internal table and send it to apps server unlike SELECT... ENDSELECT , where each datum is fetch separately . SELECT....ENDSELECT cuase more load to data-server.
Regards,
Anirban
‎2008 Oct 24 9:59 AM
‎2008 Oct 24 9:59 AM
Hi Madhu,
The Set of code that contains "select single" is the optmized part as it contact database only once and retreives record once based on the given condition.
Where as the second set that has SELECT and ENDSELECT, has to contact database for every single record until the given condition matches....this reduces the performance to a very large extent.
Best Regards,
Ram.
‎2008 Oct 24 10:03 AM
If the objective is to only check if any entry exists in the table with a specific jobname and the statuse has to be R or Y, than the best way is:
SELECT COUNT( * )
FROM tbtco
WHERE jobname EQ jobname
AND (status EQ 'R' OR status EQ 'Y').
IF sy-subrc EQ 0.
==> entry exists
ELSE.
==> entry does not exist
ENDIF.
‎2008 Oct 24 10:18 AM
Hi,
Set 1 is more optimised and better than Set2. SAP itself recommends not to use Select..Endselect because of the performance issue.
As you juset need to check whether any entry exist for the given criteria then first Set is perfect.
Thanks & Regards,
Navneeth K.