03-12-2007 10:31 AM
Hi,
I am trying to use a where condition in my loop statement as follows:
LOOP AT lt_sales_orders WHERE sales_org = l_salesorg AND
division = l_division AND
distr_chan = l_distchan AND
sales_off = l_salesoff.
Here, l_salesorg, l_division, l_distchan, l_salesoff are <b>optional</b> input parameters. This query works well when all these input parameters are non-empty.
But if the user does not enter anything in any of the parameters, it tries to match it with a blank entry while I dont want that. Rather I just want to exclude the check for that parameter from my where clause. I know that we can use the 'if else elseif' statement to form a where clause.
But is there a better way of doing it?
( I cannot use the 'LIKE' operator )
Thanks and Regards,
Reena
03-12-2007 10:41 AM
hi Reena,
You cannot put a check in your where clause (to check if it is intial, then skip this field from where condition).
Yes, as you mentioned, the option is to do if..elseif..condition check to
frame the where clause...i dont see any other options...
Hope this helps,
Sajan Joseph.
03-12-2007 10:37 AM
before loop u can put the
so and so variable and ..if not initial
then loop statement...
endloop.
endif....
regards
vijay pawar
03-12-2007 10:39 AM
Hello Reena,
Make the change like this:
LOOP AT lt_sales_orders WHERE sales_org IN l_salesorg AND
division IN l_division AND
distr_chan IN l_distchan AND
sales_off IN l_salesoff.
If the input fields L_salesorg are parameter fields then built range table and use IN operator.
Hope this solve ur problem.
Vasanth
03-12-2007 11:20 AM
Hi Vasanth,
Thanks for your reply.
Using 'IN' operator still tries to match the blank value. Didnt help
DATA: r_division TYPE RANGE OF bapiorders-division,
r_division_line LIKE LINE OF r_division,
r_division_line-sign = 'I'.
r_division_line-option = 'BT'.
r_division_line-low = l_division.
r_division_line-high = l_division.
And in the loop i used:
division in r_division
Any other inputs?
Thanks and Regards,
Reena
03-12-2007 11:31 AM
Hello Reena,
When u r builting the RANGE make this change
DATA: r_division TYPE RANGE OF bapiorders-division,
r_division_line LIKE LINE OF r_division,
if not l_division is initial. " Add this line
r_division_line-sign = 'I'.
r_division_line-option = 'EQ'.
r_division_line-low = l_division.
*r_division_line-high = l_division. "Remove this
Append r_division
endif.
Hope this will solve ur problem.
Thanks !!
Vasanth
03-12-2007 10:39 AM
Hi,
Declare l_salesorg, l_division, l_distchan, l_salesoff as Select-options instead of paramters. If you want you can give as No extenstion for all of them.
The once data is fetched into Internal table lt_sales_orders, then use the following Statements:
Delete lt_sales_orders where NOT sales_org IN l_salesorg.
Delete lt_sales_orders where NOT division IN l_division.
Delete lt_sales_orders where NOT distchanIN l_distchan.
Delete lt_sales_orders where NOT sales_off IN l_salesoff.
Regards,
Anji
03-12-2007 11:25 AM
Hi,
I cannot use 'Select-Options' since this is an RFC and the input data is coming from an external application.
I have to use import paramters.
Thanks and Regards,
Reena
03-12-2007 11:36 AM
U do one thing... use 'IN' and also include the condition all parameters are not initial..
here is example code:
Loop at itab where x in p_x
and y in p_y
and z in p_z
and ( x is not initial or
y is not initial or
z is not initial ) ... in case you wanted the loop even if one of the parameters are not empty. Otherwise repalce the 'OR''s in the loop with AND.
Hope u got the point.
03-12-2007 10:41 AM
hi Reena,
You cannot put a check in your where clause (to check if it is intial, then skip this field from where condition).
Yes, as you mentioned, the option is to do if..elseif..condition check to
frame the where clause...i dont see any other options...
Hope this helps,
Sajan Joseph.
03-12-2007 10:43 AM
Hi,
make parameters as select-options and then delete
Delete lt_sales_orders where NOT sales_org IN l_salesorg .
Delete lt_sales_orders where NOT division IN l_division.
Delete lt_sales_orders where NOT distchanIN l_distchan.
Delete lt_sales_orders where NOT sales_off IN l_salesoff.
regards,
nagaraj
03-12-2007 10:46 AM
LOOP AT lt_sales_orders WHERE sales_org = l_salesorg AND
division = l_division AND
distr_chan = l_distchan AND
sales_off = l_salesoff and
sales_org ne space and
division ne space and
distr_chan ne space and
sales_off ne space.
03-12-2007 10:49 AM
Hi,
Replace your parameters with 'select-options' on selection screen in the following way:
SELECT-OPTIONS l_val FOR ... NO INTERVALS NO-EXTENSION.
From the user point of view they will act similarily to ordinary parameters but in the code you can use 'IN' operator..
LOOP AT ... WHERE VAL IN L_VAL....
03-12-2007 10:51 AM
Hi Prabhakar,
Try this ..........
LOOP AT lt_sales_orders WHERE
<b>l_salesorg IS NOT INITIAL AND </b>
<b>l_division IS NOT INITIAL AND </b>
<b>l_distchan IS NOT INITIAL AND </b>
<b>l_salesoff IS NOT INITIAL AND </b>
sales_org = l_salesorg AND
division = l_division AND
distr_chan = l_distchan AND
sales_off = l_salesoff AND.
Hope,your question is answered.If you have any queries, you are welocome
Reward,if helpful to you.
Regards,
V.Raghavender.
03-12-2007 10:54 AM
Hi,
Try like this, i hope you will get the solution.
LOOP AT lt_sales_orders WHERE
(sales_org = l_salesorg OR sales_org IS INITIAL)
AND (division = l_division OR division IS INITIAL)
AND (distr_chan = l_distchan OR distr_chan IS INITIAL) AND
sales_off = l_salesoff OR sales_off IS INITIAL).
Regards,
Sandhya
03-12-2007 11:16 AM
Hi ,
See this is not required when u are dealing with sales area .
loop at where ... <cond1> ...<cond2>..<cond3> ...<cond4>
In the select itself u can make the sales area org/dit chnl/division in the where clause .
If u r using with some sequence or a criteria
sort itab by org dischl division offfice
loop .
read table jtab with key salorg = itab-salsorg
dischl = itab-distchnnl
division = itab-div
office = '1001'.
if sy-subrc eq 0.
process operation.
endif.
endloop.
in this u can use a case of fixed values also in place of itab .
replace itab- area with ur parameter values and check .
try this .
regards,
Vijay
03-14-2007 12:01 PM
Thanks a ton for all your inputs.
However, I was not able to use any of the solutions mentioned. I ended up using 'if' 'elseif' statements.
Thanks again !
Regards,
Reena