Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
case statement in a where clause

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Wed Sep 16, 2009 3:40 pm    Post subject: case statement in a where clause
Reply with quote

I am trying to use host variables conditionally in a where clause of my program.

the variables i have declared are:

01 WS-REGULAR-VAR PIC X(1).
01 WS-EXCEPTIONS.
05 CODE1 PIC X(1) VALUE 'A'.
05 CODE2 PIC X(1) VALUE 'B'.
05 CODE3 PIC X(1) VALUE 'C'.

now, only when the value in WS-REGULAR-VAR is 'X' i want to use the values in WS-EXCEPTIONS.

what I am trying is shown below. can i use this or should i be using IN(CODE1,CODE2,CODE3) instead??

exec sql
select
--
--
where
my_field in
case
:WS-REGULAR-VAR = 'X'
then (:WS-EXCEPTIONS)
else (:WS-REGULAR-VAR)
end
and --
and --
with ur
end-exec
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Sep 16, 2009 9:06 pm    Post subject:
Reply with quote

Hello,

Suggest you post some sample data and the result you want when that sample data is processed by this query.

When posting the sample data, use the Code tag for readability. Use Preview to see the post as it will appear to the forum (rather than what is seen in the Reply Editor).
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri Sep 18, 2009 3:36 pm    Post subject:
Reply with quote

Instead of WS-EXCEPTIONS give :CODE1,:CODE2,:CODE3 ...
Using CASE with an IN predicate should be with a fullselect.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Sep 18, 2009 3:50 pm    Post subject:
Reply with quote

best way would be : to do this before your SQL

Code:
01 WS-REGULAR-VAR PIC X(1).
01 WS-EXCEPTIONS.
   05 CODE1 PIC X(1) VALUE 'A'.
   05 CODE2 PIC X(1) VALUE 'B'.
   05 CODE3 PIC X(1) VALUE 'C'.
01 WS-HV.
   05 CODE1 PIC X(1).
   05 CODE2 PIC X(1).
   05 CODE3 PIC X(1).

if WS-REGULAR-VAR = 'X'
then move ws-exceptions to ws-HV
else move WS-REGULAR-VAR to CODE1 of ws-HV
     move WS-REGULAR-VAR to CODE2 of ws-HV
     move WS-REGULAR-VAR to CODE3 of ws-HV
end-if

exec sql
...
where my_field in (:WS-HV)
end-exec
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts WER268A OUTREC STATEMENT : SYNTAX E... frozenblood87 SYNCSORT 12 Sat Aug 26, 2017 9:45 pm
No new posts Suppress value reported by BREAK in D... Learncoholic DFSORT/ICETOOL 3 Wed Aug 16, 2017 6:03 pm
No new posts ON 2 AND EVERY 1 - Statement ??? UmeySan COBOL Programming 2 Tue Jul 25, 2017 1:20 pm
No new posts RFE: DB2 support for mixed case names. Pedro DB2 0 Tue Jul 04, 2017 1:32 am
No new posts ROUNDED Problem with COMPUTE statement shalem COBOL Programming 11 Thu Feb 09, 2017 8:16 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us