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 query?

Former Member
0 Likes
669

I hav a Ztable & need to fetch data from thr.

User will enter the year & BSTAT is blank & all other if he wish he'll enter.

I have used this logic:

refresh itab.

select * into table itab

from ztable

where bstat = ''

and djahr = djahr1

or belnr in belnr1

or werks in werks1

or KOSTL in kostl1

or ANLN1 in anln11

or AUFNR in aufnr1.

Is it correct plz guide

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
650

Hi Abhut,

If you the variable you want to use in select query and if you want that the value of those variables to be empty,but your select query should work then declare those variables as select-options with no interval and no extension .

if there is a range then no need to add no extension and no inerval.

SELECT * INTO TABLE itab

FROM ztable

WHERE bstat is initial

AND djahr IN djahr1

AND belnr IN belnr1

AND werks IN werks1

AND kostl IN kostl1

AND anln1 IN anln11

AND aufnr IN aufnr1

6 REPLIES 6
Read only

Former Member
0 Likes
650

Hi,

Declare all the input fields as SELECT-OPTIONS with no intervals no-extensions so dey ll appear like parameters but behave as sel-options(if left empty all records ll be selected)

SELECT * INTO TABLE itab
FROM ztable
WHERE bstat EQ ' '
AND   djahr IN djahr1
AND   belnr IN belnr1
AND   werks IN werks1
AND   kostl IN kostl1
AND   anln1 IN anln11
AND   aufnr IN aufnr1.

Cheers,

jose.

Read only

Former Member
0 Likes
650

hi,

u r query is correct.... but if u want to select particular fields frm the table don't use select *. bcoz it 'll create a performance issuse instead of that use select (particular fields) from table.

Thanks.

Arunprasad.P

Read only

Former Member
0 Likes
650

Does the 'ZTABLE' have data when .... 'BSTAT' is empty....

if yes ... then the query is ok ..... and i think u should use 'AND' instead of 'OR'.

but i thing i would suggest .... that don't use * rather mention the fields that u want ....even if u want all the fields try to mention them .... depending on the no. of fields in the table .... because it is performance wise better ..

Edited by: Anjali on Mar 7, 2008 4:55 AM

Read only

Former Member
0 Likes
650

Hi,

It seems to be fine, but according to standards.

But make eure if you are using IN fir fetching data then you this field should be a select-option on the selection screen.

refresh itab.

select * into table itab

from ztable

where bstat = space and

djahr EQ djahr1 or

belnr in s_belnr1 or

werks in s_werks1 or

KOSTL in s_kostl1 or

ANLN1 in s_anln11 or

AUFNR in s_aufnr1.

Please reward if its helpful.

Regards,

Abhishek

Read only

Former Member
0 Likes
651

Hi Abhut,

If you the variable you want to use in select query and if you want that the value of those variables to be empty,but your select query should work then declare those variables as select-options with no interval and no extension .

if there is a range then no need to add no extension and no inerval.

SELECT * INTO TABLE itab

FROM ztable

WHERE bstat is initial

AND djahr IN djahr1

AND belnr IN belnr1

AND werks IN werks1

AND kostl IN kostl1

AND anln1 IN anln11

AND aufnr IN aufnr1

Read only

Former Member
0 Likes
650

Hi da,

Try this...

You no need to worry about other fields ...

refresh itab.

select * into table itab

from ztable

where bstat = ''

and djahr = djahr1.

Regards.

Balakumar.G.