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:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |