Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
hitesh_gabani
Participant
693

This is very useful to every ABAP Developers while writing query in program.


 

Kindly avoid OR conditions in where clause reason behind this is followings:


 

  1. 1. It degrade the Performance

  2. 2. Sometimes it will fetch all records from the db table.


 

To overcome this problems use IN clause instead of OR if the Field Name should be same.


 

For example,


 

SELECT MBLNR MJAHR


     FROM MSEG


     INTO IST_MSEG


     WHERE BWART = '101' OR BWART = '543' OR BWART = '545'.


 

Instead of Above Query you can use following Query:


 

SELECT MBLNR MJAHR


     FROM MSEG


     INTO IST_MSEG


     WHERE BWART IN ('101','543','545').


 

When you have different field with OR condition.


 

For example,


 

SELECT MBLNR MJAHR ZEILE


     FROM MSEG


     WHERE MBLNR = '30204095' OR BWART = '101' OR BWART='543' OR EBELN = '123' OR EBELN = '456'.


 

Than might be confusion that how to write query for above case.


 

For that you can create TYPE RANGE OF BWART AND EBELN.


 

Use Following Query,


 

SELECT MBLNR MJAHR ZEILE


     FROM MSEG


     WHERE MBLNR = '30204095' AND BWART IN R_BWART AND EBELN IN R_EBELN.


 

For example,


 

SELECT MBLNR MJAHR


     FROM MSEG


     INTO IST_MSEG


     WHERE MBLNR = P_MBLNR AND BWART = '101' OR BWART = '543’.


 

Instead of Above Query you can use following Query:


 

SELECT MBLNR MJAHR


     FROM MSEG


     INTO IST_MSEG


     WHERE (MBLNR = P_MBLNR AND BWART = '101') OR (MBLNR = P_MBLNR AND BWART = '543').


 

Hope you have understand and if any confusion than comment on it.



Labels in this area