Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

problem is select query.

itabhishek9
Participant
0 Likes
872

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
825

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

9 REPLIES 9
Read only

Former Member
0 Likes
825

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.

Read only

Former Member
0 Likes
825

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....?

Read only

itabhishek9
Participant
0 Likes
825

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

Read only

0 Likes
825

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.

Read only

viquar_iqbal
Active Contributor
0 Likes
825

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

Read only

0 Likes
825

>

> 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.

Read only

Former Member
0 Likes
825

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.

Read only

0 Likes
825

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 .

Read only

Former Member
0 Likes
826

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