Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Difference between Check and where statement.

Former Member
0 Likes
2,370

Hello everybody i know that where clause is efficient than check condition.

But i want to know if in the following example,

even after finding SBOOK_WA-CARRID = 'LH' ,

DOES THE CHECK CONDITION TERMINATES?? OR KEEP SEARCING TILL THE END OF INTERNAL TABLE?

IN THE 2nd EXAMPLE,

DOES THE WHERE CLAUSE EXHIBIT THE SAME PHENOMENON?

1st example:

SELECT * FROM SBOOK INTO SBOOK_WA.

CHECK: SBOOK_WA-CARRID = 'LH' AND

SBOOK_WA-CONNID = '0400'.

ENDSELECT.

-


2nd example:

SELECT * FROM SBOOK INTO SBOOK_WA

WHERE CARRID = 'LH' AND

CONNID = '0400'.

ENDSELECT.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,942

Hi,

If you code select statement with where condition then it

is very efficient.Because the where condition will execute first and then the select

statement will get data from data base with selected fields,

if you code the select statement after that if you put check statement,

first select statement will execute with out key base.Means the performance decreases.

(see searching known thing is easy than unknowing thing.).

so its better to go for select statement with where condition.

regards

swami.

8 REPLIES 8
Read only

Former Member
0 Likes
1,942

Hi

the check statement will work as desired, but performance wise the second select query with th where clause is better

regards

parminder

Read only

Former Member
0 Likes
1,942

Hi,

Check statement will give low performance compare to where.

B'cause After selecting the record for database table you are checking the value.

WHERE: At the time of selection records from table you are checking. So based on condition record will select otherwise it will go for nect record with that database connection only.

In first example. : It will terminate the selection.No next search...

Second : it will continue the search....

Read only

Former Member
0 Likes
1,943

Hi,

If you code select statement with where condition then it

is very efficient.Because the where condition will execute first and then the select

statement will get data from data base with selected fields,

if you code the select statement after that if you put check statement,

first select statement will execute with out key base.Means the performance decreases.

(see searching known thing is easy than unknowing thing.).

so its better to go for select statement with where condition.

regards

swami.

Read only

Former Member
0 Likes
1,942

Ok ,,Now i want to know if the condition SBOOK_WA-CARRID

= 'LH' is repeated for the 2nd time in the database table.Then will the Check & Where condition continue to search for it even after having encountered the above mentioned condition already??

Read only

Former Member
0 Likes
1,942

Hi,

If where clause is used in select query, it filters the database records according to the condn. and retrieves values into the internal table.

When, check statement is used, it checks for the condition only after the selection. This will increase the execution time.

In addition, the statements after check statemnt (in the same event) will be executed only if the condition mentioned in check statement is true.

Reward if helpful.

Regards,

Ramya

Read only

dhruv_shah3
Active Contributor
0 Likes
1,942

Hi,

First Example will not work.

Second Example will work.

Regards,

Dhruv Shah

Read only

Former Member
0 Likes
1,942

My question is ,

IF SBOOK_WA-CARRID = 'LH' CONDITION IS AGAIN PRESENT IN THE DATABASE TABLE ,,,,WILL THE CHECK CONDITION SEARCH IT AGAIN EVEN AFTER FINDING IT FOR THE FIRST TIME IN THE TABLE???OR SIMPLY TERMINATE IN THE FIRST TIME THE CONDITION SATISFIES??

SIMILARLY DOES THE WHERE CLAUSE CONTINUE SEARCHING EVEN AFTER HAVING FOUND THE CONDITION FOR THE FIRST TIME??

PLEASE HELP ME IN THIS ASPECT.

Read only

Former Member
0 Likes
1,942

hi saswat,

If it's an internal table, why do you want to select it instead of looping/reading it?

and incase u're looping it, you need not worry for the number of fetches, because it brings you all the relevant records having given the condition.

even otherwise, if it's a select to a database table, one select statement will fetch you all the relevant records for the given where/check condition. So both the clauses will bring in ALL the records in ONE go be it a select to a db table / looping an ITAB.

Thanks,

VV