‎2009 Jul 10 6:16 AM
Hello SDNites,
I have a req where I need to use select query to fetch data. But the conditions which is to be placed in this select query has 3 checkboxes corresponding to the same field. Either of them can be selected at a time. Please let me know how can we put this condition effectively in one select query.
Thanks,
Abhishek
‎2009 Jul 10 7:05 AM
Hi,
This can be done by dynamic where condition;
DATA : lv_condition(100) type C.
IF rad_button1 EQ 'X'.
lv_condition = 'Field = 10'.
ELSEIF rad_button2 EQ 'X'.
lv_condition = 'Field = 20'.
ELSE.
lv_condition = 'Field = 30'.
ENDIF.
Select * into itab from db_tab Where ( lv_condition ).See F1 help for where condition for more details.
Regards
Karthik D
‎2009 Jul 10 6:18 AM
IF CHECKBOX 1 IS SELECTED.
WRITE THE SELECT ACCORDING TO THAT.
ELSEIF CHECKBOX 2 IS SELECTED.
WRITE THE SELECT ACCORDING TO THAT.
ELSEIF CHECKBOX 3 IS SELECTED.
WRITE THE SELECT ACCORDING TO THAT.
ENDIF.
‎2009 Jul 10 6:19 AM
Can u please explain the problem in a better way. What is the data u need to select and what are the check boxes are they on the selection-screen....?
‎2009 Jul 10 6:23 AM
Thanks for the reply,
I explain my issue in a more detailed manner,
I have a 3 check boxes in my selection screen. All of them correponds to the the same field(Customer status).
My select query req is to fetch the data for the checkbox which is selected. At a time 1 checkbox can be selected, or 2 or 3(in any combination).
Is there any way to fulfill this req in a single select query. If not then 7 select queries need to be used to fulfill this req.
Thanks,
Abhishek
‎2009 Jul 10 7:10 AM
Hi Abhishek,
Depending on your check box selection u can concatenate the string for where ckause....
For eg:-
concatenate `'` 'A' `'` into fs.
concatenate `'` 'F' `'` into fs1.
if cb1 = 'X' and CB2 = 'X'.
CONCATENATE 'bstyp' '=' FS 'OR' 'bstyp' '=' FS1 INTO FS SEPARATED BY SPACE.
endif.
select * from dbtab into table itab where (fs).
depending on ur check box selection u can change ur VARIABLE FS to be used in where clause....... But u just need to use single select query.
‎2009 Jul 10 6:28 AM
Hi
Try this
If checkbox1 = 'X' or checkbox2 = 'X' or checkbox3 = 'X'.
move value of field in variable V1.
endif.
select abc
xyz
from table
into itab
where field eq V1.
Hope this helps.
Viquar Iqbal
‎2009 Jul 10 6:37 AM
>
> If checkbox1 = 'X' or checkbox2 = 'X' or checkbox3 = 'X'.
> move value of field in variable V1.
> endif.
IMO There is no need to check with IF condition unless you think condition will always true.
And the Above IF condition will always true, which is really non-sense to me.
‎2009 Jul 10 6:40 AM
i think u can do it by range table
Example- Suppose three checkbox are
1 Customer is active
2 Customer is inactive
3 Customer is blocked from trading
and the field correspond to these status is field1(suppose) in table KNA1.
Ranges: r_field1 for kna1-field1.
If Customer is active checkbox = 'X'.
r_field1-low = 1 (the value should be as same as mentioned in table kNA1 for this status)
r_field-option = 'EQ'.
r_field-sighn = 'I'.
append r_field.
endif.
Perform the same case for rest of two status.
Now use it in below query as follows
select * from kna1 where field1 in r_field1.
hope this wil help u.
‎2009 Jul 10 7:01 AM
Dear Abhishek ,
you have a 3 check boxes in selection screen. All of them correponds to the the same field(Customer status).
select query req is to fetch the data for the checkbox which is selected. but can you tell me which value you are passing and to which column you are passing value
i.e if 1st chk box selected what you are passing if two then what if three then what .
just tell me what you are passing and to which column you are passing . will give you good solution
Regards
Deepak .
‎2009 Jul 10 7:05 AM
Hi,
This can be done by dynamic where condition;
DATA : lv_condition(100) type C.
IF rad_button1 EQ 'X'.
lv_condition = 'Field = 10'.
ELSEIF rad_button2 EQ 'X'.
lv_condition = 'Field = 20'.
ELSE.
lv_condition = 'Field = 30'.
ENDIF.
Select * into itab from db_tab Where ( lv_condition ).See F1 help for where condition for more details.
Regards
Karthik D