MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using host variable in IN predicate

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
kbn
Beginner


Joined: 14 Nov 2005
Posts: 13
Topics: 10

PostPosted: Wed Aug 29, 2007 1:09 am    Post subject: Using host variable in IN predicate Reply with quote

Hi,

I have a table A which has columns TYPE, NUMBER, NAME.

I want to read the table for only few types. I have types in WS-TYPE which has the value 'X', 'Y', 'Z'

Shall I use the following query?

SELECT TYPE, NUMBER, NAME
FROM A
WHERE TYPE IN (:WS-TYPE)

thanks,
kbn
Back to top
View user's profile Send private message
vivek1983
Intermediate


Joined: 20 Apr 2006
Posts: 222
Topics: 24

PostPosted: Wed Aug 29, 2007 2:27 am    Post subject: Reply with quote

kbn,

Why not use '=" instead of "IN" since you are checking only a single value?

Regards,
Vivek G
_________________
Vivek G
--------------------------------------
A dream is just a dream. A goal is a dream with a plan and a deadline. (Harvey Mackay)
Back to top
View user's profile Send private message
dr_te_z
Beginner


Joined: 08 Feb 2007
Posts: 18
Topics: 3

PostPosted: Wed Aug 29, 2007 3:35 am    Post subject: Reply with quote

Nice topic. When I faced the same problem I coded
Code:
where type in (:ws1 , :ws2 , :ws3 , :ws4 , :ws5 , :ws6 , :ws7)
(actually 50 parameters)
The DB2-guru on site told me that it was safe, because db2 will compress/distinct all the double's found in the "IN" before accessing the data. So effectively I threw this to the database
Code:
where type in ('x','y','z','x','x','x','x')
but DB2 would look-up value 'x' only once.
I still wonder if that DB2-guru knew what he was talking about..... Can anyone acknowledge or did I create a monster Twisted Evil ?
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Wed Aug 29, 2007 4:10 am    Post subject: Reply with quote

kbn,

you can try this:
Code:

01  WS-TYPE.
     05  WS-TYP-1             PIC X(01) VALUE 'X'.
     05  WS-TYP-2             PIC X(01) VALUE 'Y'.
     05  WS-TYP-3             PIC X(01) VALUE 'Z'.

SELECT TYPE, NUMBER, NAME
FROM A
WHERE TYPE IN (:WS-TYPE)


assuming TYPE is 1 char.

But since this seems to be rather static (values for desired TYPE are always the same), would suggest that you form the IN list in the SQL as TYPE IN ('X','Y','Z')
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
vivek1983
Intermediate


Joined: 20 Apr 2006
Posts: 222
Topics: 24

PostPosted: Wed Aug 29, 2007 7:44 am    Post subject: Reply with quote

dbzTHEdinosauer,

Code:


  01  WS-TYPE.
     88  WS-TYP-1             PIC X(01) VALUE 'X'.
     88  WS-TYP-2             PIC X(01) VALUE 'Y'.
     88  WS-TYP-3             PIC X(01) VALUE 'Z'.

SELECT TYPE, NUMBER, NAME
FROM A
WHERE TYPE IN (:WS-TYPE)


WS-TYP-1,2,3 should be in 88 levels right?
Please let me know if I am missing something.

Regards,
Vivek G
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Aug 29, 2007 7:58 am    Post subject: Reply with quote

vivek1983,

1. DBZ has the right definition.
2. 88 level items are condition items

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Wed Aug 29, 2007 7:59 am    Post subject: Reply with quote

vivek1983,
well, first of all an 88 level does not contain a Picture clause, only level nbr, reference name and value. Even if you had generated the correct data definitions, you need a SET statement to populate WS-TYPE with something.

2nd, I interpreted
Quote:
I have types in WS-TYPE which has the value 'X', 'Y', 'Z'
to mean that the OP had an IN list containing three values: X, Y and Z.

If I misinterpreted the OP's question, then I provided info when it was not needed.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group