IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

REG: Usage of array variables in WHERE predicate of a query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
MoganaKumaran

New User


Joined: 26 Jun 2007
Posts: 20
Location: Chennai

PostPosted: Mon May 16, 2011 12:28 pm
Reply with quote

All,

I have framed a query like this ( is it possible to use array var in WHERE clause )

select * from
tab1

where itm_typ in (:WS-ITM-TYP(1),:WS-ITM-TYP(2),:WS-ITM-TYP(3),
:WS-ITM-TYP(4),:WS-ITM-TYP(5),:WS-ITM-TYP(6),
:WS-ITM-TYP(7),:WS-ITM-TYP(8),:WS-ITM-TYP(9) ..... upto 25

We have declared an array

01 TABLES.
05 WS-ITM-TYP-CD-TABLE OCCURS 25 TIMES INDEXED BY ITM-INX
10 WS-ITM-TYP PIC S9(04) COMP VALUE ZEROS.

The value for this WS-ITM-TYP is populated from another parm table and the values are populated by using UNSTRING .At present we have 10 values and the values might be added in future, so we are using an array .

Kindly clarify if its possible to use array variables in WHERE predicate of a query.


Thanks in advance.

Regards,
mohan
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon May 16, 2011 12:34 pm
Reply with quote

what sql error are you receiving?
Back to top
View user's profile Send private message
MoganaKumaran

New User


Joined: 26 Jun 2007
Posts: 20
Location: Chennai

PostPosted: Mon May 16, 2011 12:39 pm
Reply with quote

Hi Dick,

It gives a precompiler error exactly at the line nbr where my array var are used in WHERE clause

ILLEGAL SYMBOL "(". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: . CONCAT || / - + MI


Thanks & Regards,
Mohan
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Mon May 16, 2011 1:03 pm
Reply with quote

Use REDEFINES?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon May 16, 2011 1:14 pm
Reply with quote

from the manual:

Example 4: The following example obtains the phone number of an employee in
DSN8910.EMP where the employee number (EMPNO) is a value specified within
the COBOL structure defined below.
Code:

77 PHNUM PIC X(6).
01 EMPNO-STRUCTURE.
  05 CHAR-ELEMENT-1 PIC X(6) VALUE '000140'.
  05 CHAR-ELEMENT-2 PIC X(6) VALUE '000340'.
  05 CHAR-ELEMENT-3 PIC X(6) VALUE '000220'.
...
EXEC SQL DECLARE PHCURS CURSOR FOR
          SELECT PHONENO FROM DSN8910.EMP
           WHERE EMPNO IN
                           (:EMPNO-STRUCTURE.CHAR-ELEMENT-1,
                            :EMPNO-STRUCTURE.CHAR-ELEMENT-2,
                            :EMPNO-STRUCTURE.CHAR-ELEMENT-3)
END-EXEC.

EXEC SQL OPEN PHCURS
END-EXEC.

EXEC SQL FETCH PHCURS INTO :PHNUM
END-EXEC.



the db2 precompiler is not able to resolve an index/subscripted address.
Back to top
View user's profile Send private message
MoganaKumaran

New User


Joined: 26 Jun 2007
Posts: 20
Location: Chennai

PostPosted: Mon May 16, 2011 1:22 pm
Reply with quote

Dick,

The values for this array var are passed dynamically from a Application parm table.I should not harcode the values in my application program.

If any item types need to be added/changed/deleted ,no changes should be made to the program.

Thanks & Regards,
Mohan
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon May 16, 2011 2:30 pm
Reply with quote

oh for crying-out-loud.

I provided you with the syntax.

as prino said,
redefine the lvl 1 as a table.
do your dynamic load,
open the cursor
fetch
close.

you are welcome.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts STEM usage in REXX CLIST & REXX 14
Search our Forums:

Back to Top