sql select statement with field having multiple values
i have few check-boxes on my selection screen.Each check-box corresponds to a value which a field of a table can take.I have to then fire a select query where a particular field of a table can have all values whose corresponding check-box is selected.
Suppose i have 5 check-box corresponding to values a1,a2 till a5.
Now if check-box 1 ,3 and 4 is checked then the filed of table can have values a1 or a3 or a4.
select * from table where field = a1 or field = a2 or field = a3.
One way to do this is creating 5 variables and then doing something like this
if checkbox1 checked
then var1 = a1
var1 = '0' //something which would never occur in the field of the table
and so on for all checkboxes.
select * from table where field = var1 or field = var2 or field = var3 or field = var4 or field = var5.
Is there a better way to do this.
Raymond Giuseppi replied
Define a TYPE RANGE data and fill it with the checked values
DATA: my_range TYPE RANGE OF my_element.
IF checkbox1 IS NOT INITIAL.
APPEND INITIAL LINE TO my_range ASSIGNING <value>.
<value>-sign = 'I'.
<value>-option = 'EQ'.
<value>-low = field1.
SELECT * FROM my_table WHERE field IN my_range.
You could also use some dynamic assignment to checkbox and value with field symbols (or the obsolete DO VARYING for the nostalgics only.)