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

ABAP SQL Query (Select data from intervals)

Former Member
1,798

Hi All,

From To Temp

101 200 1111

201 300 2222

301 400 3333

401 500 4444

501 600 5555

From, To & Temp are three Fields.

Consider the above table, if i enter input as 150, need to pick 1111.

If the input is inbetween of From & To values means I want to pick the exact

Data from temp field.

Thanks

Hema

Edited by: hema prabakaran on Jan 19, 2009 7:54 AM

Edited by: hema prabakaran on Jan 19, 2009 8:30 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,063

Hi,

If it is ur R/3 database table than u can directly select using following query

Select temp from <DB_table>

into <variable> where

from <= <input_variable_value> and to >= <input_variable_value>.

and if u have selected all the values in some internal table than

Loop at <internal Table> where from <= <input_variable_value> and to >= <input_variable_value>.

<variable> = <work area>-temp.

exit.

endloop.

6 REPLIES 6
Read only

Former Member
0 Likes
1,063

1. loop your internal table.

2. Check whether your input is less than To in internal table using conditional statements.

3. If yes pick the temp value and exit the loop..

4. Else repeat the process.

Giving exact code will be spoonfeeding

Read only

Former Member
0 Likes
1,063

Hi Hema.

As your table layout you can select as follow sql query

table is named ur_table

From To Temp

101 200 1111

201 300 2222

301 400 3333

401 500 4444

501 600 5555

SELECT temp INTO lv_temp

FROM ur_table

WHERE from >= v_input_value

AND to <= v_input_value.

Hope it helps.

Sayan

Edited by: Sayan Churatao on Jan 19, 2009 4:30 AM

Edited by: Sayan Churatao on Jan 19, 2009 4:31 AM

Read only

peter_ruiz2
Active Contributor
0 Likes
1,063

Hi,

use this for your SELECT statement

SELECT from to temp

FROM <table>

INTO TABLE i_tab

WHERE from <= value

AND to >= value.

regards,

Peter

Read only

Former Member
0 Likes
1,064

Hi,

If it is ur R/3 database table than u can directly select using following query

Select temp from <DB_table>

into <variable> where

from <= <input_variable_value> and to >= <input_variable_value>.

and if u have selected all the values in some internal table than

Loop at <internal Table> where from <= <input_variable_value> and to >= <input_variable_value>.

<variable> = <work area>-temp.

exit.

endloop.

Read only

Former Member
0 Likes
1,063

Hi,

Suppose yu enter a value in a parameter say p_temp and you need the value of temp for which p_temp lies between from and to value, you may use

select * from ztable into table itab.

loop at itab.

if p_temp >= itab-from and p_temp <= itab-to.

write itab-temp.

exit.

else.

continue.

endif.

Hope this helps.

Thanks and regards,

Sachin

Read only

Former Member
0 Likes
1,063

Hi

Data: itab type table of tbl with header line.

select * from tbl into table itab.

if sy-subrc eq 4.

Message E000(YJK).

else.

loop at itab.

if v_temp between itab-from and itab-to.

write itab-temp.

exit.

else.

continue.

endif.

endloop.

endif.

You can use the above code.

It is not possible to use select stmt with your i/p variable in the where clause as that field is not present in table.

hope this helps

Regards,

Jayanthi.K