‎2009 Oct 11 2:24 PM
Hi all ,
how to Do this simple select in one time
i had this select and i want to know if there is a way to do it in one time without if and else since it similar
if hash_de is not initial .
SELECT SINGLE consumer_O
FROM Z_dab
INTO rv_consomer
WHERE userid = iv_userid
AND hash_de = mv_hash_deviceid.
else.
SELECT SINGLE consumer_O
FROM Z_dab
INTO rv_consomer
WHERE userid = iv_userid.
endif.
i know that this i can do it in dynamic way with brackets but i don't want it .
there is other way to do it except dynamic ?
Regards
Chris
‎2009 Oct 11 3:07 PM
Hi,
If you dont want to do it dynamically with brackets, and want to make use of a single select, check this,
You will have to use a internal table instead of a single variable.
data: begin of itab occues 0,
rv_consomer type string,
hash_de type string,
end of itab.
data: rv_consomer type string.
SELECT consumer_O hash_de
FROM Z_dab
INTO table itab
WHERE userid = iv_userid.
if hash_de is not initial .
loop at itab where hash_de = mv_hash_deviceid.
rv_consomer = itab-rv_consomer.
exit.
endloop.
else.
read table itab index 1.
rv_consomer = itab-rv_consomer.
endif.
write: rv_consomer
Vikranth
‎2009 Oct 11 3:07 PM
Hi,
If you dont want to do it dynamically with brackets, and want to make use of a single select, check this,
You will have to use a internal table instead of a single variable.
data: begin of itab occues 0,
rv_consomer type string,
hash_de type string,
end of itab.
data: rv_consomer type string.
SELECT consumer_O hash_de
FROM Z_dab
INTO table itab
WHERE userid = iv_userid.
if hash_de is not initial .
loop at itab where hash_de = mv_hash_deviceid.
rv_consomer = itab-rv_consomer.
exit.
endloop.
else.
read table itab index 1.
rv_consomer = itab-rv_consomer.
endif.
write: rv_consomer
Vikranth
‎2009 Oct 11 4:11 PM
Hi Chris,
you can just put the hash_de into a range - BTW, souldn't it be
if mv_hash_deviceid. is not initial .Then my proposal is:
data:
lt_range_hash_de type range of Z_dab-hash_de.
field-symbols:
<range_hash_de> like line of lt_range_hash_de.
if mv_hash_deviceid is not initial.
append initial line to lt_range_hash_de assigning <range_hash_de> .
<range_hash_de> = 'IEQ'. "Set SIGN = 'I', OPTION = 'EQ'
<range_hash_de>-low = mv_hash_deviceid .
endif.
SELECT SINGLE consumer_O
FROM Z_dab
INTO rv_consomer
WHERE userid = iv_userid
AND hash_de IN lt_range_hash_de.
If there is no mv_hash_deviceid , the range stays empty. Empty ranghes are ignored in WHERE condition.
Regards,
Clemens