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 

Is it possible to use an array as host variable ?
Goto page Previous  1, 2
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Tue Apr 14, 2009 12:05 pm    Post subject: Reply with quote

dbz

Like I said, I've tried this in the past, but have not been able to get this to work. Does my failure mean it can't be done? Of course not. I actually prefer to be wrong on this because this technique would be useful. I base my disagreement on my own failures and the statement in the DB2 manual. I just don't see how DB2 would distinquish between a host variable and a host variable array in the context of the WHERE clause. In the previous examples, the host variables are REDEFINEs of the COBOL variables with the subordinate OCCURS. How would DB2 know that it should be using a host variable array and not just a host variable?

Code:
01 WS-STATE-ARRAY.                                 
   05 WS-STATE-CODE OCCURS 50 TIMES.               
      10 WS-ST-NAME   PIC X(02).                   
                                                   
01 WS-STATE-R REDEFINES WS-STATE-ARRAY PIC X(100).

EXEC SQL
     DECLARE STATE_CURS CURSOR FOR
      SELECT STATE_NAME
        FROM DNTSTATES
       WHERE STATE_CD IN (:WS-STATE-R)
END-EXEC.

Using the State example, how would DB2 know that WS-STATE-R is a host variable array? The way it's defined, it's just a 100 byte character string. How would DB2 know that there are 50 occurences of a 2 byte character strings in the COBOL pgm?

The reason that this would work for dynamic SQL is that you would imbed the IN list values directly into the SQL text. I think you would wind up with the same issues if you tried to use parameter markers.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


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

PostPosted: Tue Apr 14, 2009 2:04 pm    Post subject: Reply with quote

jsharon1248,

1. I apologize. I was incorrect

2. After a little research (thank someone that I have indexed all my code on my pc)
I found that I used a temporary table, IN (Select whatever from temp.table)

3. otherwise, as you stated, each element must be referenced individually.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
mangsk
Beginner


Joined: 05 Jun 2004
Posts: 46
Topics: 18

PostPosted: Tue Apr 14, 2009 2:17 pm    Post subject: Reply with quote

dbzTHEdinosauer, jsharon1248,

Thanks a lot jsharon1248.
jsharon1248 has elaborated the same question I had in my earlier post. But unfortunately the listed 2 alternatives I am trying to avoid. Defining each element is to be avoided because there could be >120 elements there and for dynamic SQL, our shop doesn't allow that.

dbzTHEdinosauer, I tried what you have suggested, but everytime I get SQLCODE=0 whenever I put any of the MATRIX_ID in the first position of the array, provided other 2 MOVE statements are commented out. There is nothing wrong in L or R justification or padded values.
_________________
Regards,
Mangsk
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
dbzTHEdinosauer
Supermod


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

PostPosted: Tue Apr 14, 2009 3:04 pm    Post subject: Reply with quote

Mangsk,

as I said in the previous post, I was incorrect that you could reference an array as an IN List.

need to list each item separately or - nowadays, global temp tables are easy, quick,
and the dba's don't complain too much.

we had a table with 3 columns that we called a scratch pad (our dba's did not allow global temp tables - or dynamic sql).

1st column was application key (every module that required the scratch pad would load this column with program name.

2nd column was integer

3rd column was char 40 (sometimes we had to look for names)

loaded the 3rd column with the input values for the IN List.

then did the cursor select with an IN (select 3rd-column where 1st column = program name.

after the cursor was complete, would delete scratchpad where 1st column = prg name.

sorta hookey, but it worked.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
mangsk
Beginner


Joined: 05 Jun 2004
Posts: 46
Topics: 18

PostPosted: Tue Apr 14, 2009 3:12 pm    Post subject: Reply with quote

dbzTHEdinosauer,

Thanks for the suggestion.
_________________
Regards,
Mangsk
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Tue Apr 14, 2009 3:17 pm    Post subject: Reply with quote

dbz, no apologies necessary. You post more than your share of informative responses. Michael Jordan missed a shot now and then too.

mangsk
No dynamic SQL?!??!? In my opinion, this is one of the most powerful features available to every day grunts like you and me crunching out code. This is an opportunity to educate whoever prohibits dynamic SQL. This is a problem that can be solved very easily with minimal coding using dynamic SQL. If you can't sell that, use dbz's suggestion, declared global temp tables (DECLARE GLOBAL TEMPORARY TABLE). You might need to work with a DBA to get a tablespace and authorizations. These are nice because they're defined to your thread and only your thread can use it. Once the thread is killed, your table goes down with it. All you'd do is update the program to add the DECLARE and loop through INSERTs to populate the table. Then add the IN predicate with the non-correlated sub-query to the temp table (where xyz_col in (select xyz_val from session.tmp_tbl)).
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


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

PostPosted: Tue Apr 14, 2009 4:30 pm    Post subject: Reply with quote

Mangsk,

The pseudo-timestamps are generated via timestamp access.
How many rows do you expect to be returned for each pseudo-timestamp?

If 1 or just a few(<100), then I would suggest changing your logic:

if more than one, do a rowset singleton select for each pseudo-timestamp.
if only 1, then do a singleton select w/o rowset

either way, demand an index on the id column. (after implementation).

reasons:
  1. 100 or so IN list items would be 'somewhat slow'.
  2. with an index, the singleton selects would be 'reasonably fast'.
    • dynamic sql or temp tables would require fighting management,
    • and the dba's just might tell you to do what I am suggesting here.
  3. most importantly, you can implement this in hours, not days of discussion

after the implementation, you then have time to do the necessary politiking to get dynamic sql or temp tables in use at your site.

just a suggestion.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
mangsk
Beginner


Joined: 05 Jun 2004
Posts: 46
Topics: 18

PostPosted: Wed Apr 15, 2009 8:04 am    Post subject: Reply with quote

dbzTHEdinosauer, jsharon1248,

Thanks for all your help.
_________________
Regards,
Mangsk
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Apr 15, 2009 8:47 am    Post subject: Reply with quote

Mangsk,

I was pretty tied up for the past 2 days and I have no way of testing this , but I guess I have to take that array processing does NOT work with host-variable array in DB2. sorry.

Thanks DBZ and Jsharon.

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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