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.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply