Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: REG: Usage of array variables in WHERE predicate of a query
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    Post subject:
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    Post subject:
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: 1002
Location: Oostende, Belgium

PostPosted: Mon May 16, 2011 1:03 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us