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

SELECT statement with different where conditions..

Former Member
0 Likes
614

Hi All,

I am using following select statement to get the data from table BSIS.

Basically, i have to fetch the data abse don GL Account range.

I want to get the data for all GL ranges that i have mentioned in the below select statement.

select bukrs hkont gjahr belnr dmbtr shkzg projk kostl from BSIS

into corresponding fields of table it_othcost

for all entries in it_wbs

where bukrs = c_bukrs

and hkont between '0002102001' and '0002999999'

or hkont between '0002101001' and '0002101003'

or hkont between '0002101007' and '0002101009'

or hkont between '0002101013' and '0002101015'

or hkont between '0002101019' and '0002101024'

and gjahr eq v_year2

and monat between v_fmonth and v_tmonth

and kostl = it_wbs-kostl.

Please tell me how correctly and effieciently i can write the select statement for this requirement?

Basically the above select statement is giving incorrecct data from the database table BSIS.

Regards

Pavan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
586

see, or is a very critical statement in select statements so it would be better if you use a range table.

for example

data : s_hkont type RANGE OF hkont,
       sw_hkont LIKE LINE OF s_hkont .

sw_hkont-sign = 'I'.
sw_hkont-OPTION = 'BT'.
sw_hkont-low = '0002102001'.
sw_hkont-high = '0002999999'.
append sw_hkont to s_hkont.
clear : sw_hkont.
sw_hkont-sign = 'I'.
sw_hkont-OPTION = 'BT'.
sw_hkont-low = '0002101001'.
sw_hkont-high = '0002101003'.
append sw_hkont to s_hkont.
"similarly for other ones.

"now in you select statement use this range table
select bukrs hkont gjahr belnr dmbtr shkzg projk kostl from BSIS
into corresponding fields of table it_othco "try not to use into corresponding 
for all entries in it_wbs
where bukrs = c_bukrs
  and hkont in s_hkont. " and other options

Hi All,

I am using following select statement to get the data from table BSIS.

Basically, i have to fetch the data abse don GL Account range.

I want to get the data for all GL ranges that i have mentioned in the below select statement.

select bukrs hkont gjahr belnr dmbtr shkzg projk kostl from BSIS

into corresponding fields of table it_othcost

for all entries in it_wbs

where bukrs = c_bukrs

and hkont between '0002102001' and '0002999999'

or hkont between '0002101001' and '0002101003'

or hkont between '0002101007' and '0002101009'

or hkont between '0002101013' and '0002101015'

or hkont between '0002101019' and '0002101024'

and gjahr eq v_year2

and monat between v_fmonth and v_tmonth

and kostl = it_wbs-kostl.

Please tell me how correctly and effieciently i can write the select statement for this requirement?

Basically the above select statement is giving incorrecct data from the database table BSIS.

Regards

Pavan

3 REPLIES 3
Read only

Former Member
0 Likes
587

see, or is a very critical statement in select statements so it would be better if you use a range table.

for example

data : s_hkont type RANGE OF hkont,
       sw_hkont LIKE LINE OF s_hkont .

sw_hkont-sign = 'I'.
sw_hkont-OPTION = 'BT'.
sw_hkont-low = '0002102001'.
sw_hkont-high = '0002999999'.
append sw_hkont to s_hkont.
clear : sw_hkont.
sw_hkont-sign = 'I'.
sw_hkont-OPTION = 'BT'.
sw_hkont-low = '0002101001'.
sw_hkont-high = '0002101003'.
append sw_hkont to s_hkont.
"similarly for other ones.

"now in you select statement use this range table
select bukrs hkont gjahr belnr dmbtr shkzg projk kostl from BSIS
into corresponding fields of table it_othco "try not to use into corresponding 
for all entries in it_wbs
where bukrs = c_bukrs
  and hkont in s_hkont. " and other options

Read only

Former Member
0 Likes
586

Hi,

Create a ranges table for Hkont and use it in the where condition using IN operator.

Search forum for sample codes on ranges / see F1 help.

Regards

Karthik D

Read only

Former Member
0 Likes
586

Populate a range for HKONT and pass all the below values .. and use it in where condition ...

select bukrs hkont gjahr belnr dmbtr shkzg projk kostl from BSIS

into corresponding fields of table it_othcost

for all entries in it_wbs

where bukrs = c_bukrs

and hkont in r_hkont

and gjahr eq v_year2

and monat between v_fmonth and v_tmonth

and kostl = it_wbs-kostl.