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

Help in select

Former Member
0 Likes
396

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
367

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

2 REPLIES 2
Read only

Former Member
0 Likes
368

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

Read only

Clemenss
Active Contributor
0 Likes
367

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