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 

Multi Row fetch with multiple records from a input dataset

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


Joined: 01 Jun 2010
Posts: 3
Topics: 1

PostPosted: Thu Sep 22, 2011 1:14 am    Post subject: Multi Row fetch with multiple records from a input dataset Reply with quote

Hi All

I am trying to incorporate Multi Row fetch logic into my code.
The loginc I am trying to accomplish is something like this..

Fetch multiple records from an inout dataset which contains employee number , and SSN..

Now use these two fields in the WHERE condition of MULTI ROW FETCH ROWSET to fetch all the matching rows from the table...

Example;;

n INPUT file I have
Code:

Employee SSN
03934847 384864856
20348475 930857593
83487294 203834749
02303847 222323223


Now I can have multiple rows in the table for each of this combination.
To fetch all of them I am trying to declare cursor as
Code:

DECLARE CURSOR CRSY-TEST
   WITH ROWSET POSITIONING
   FOR
  SELECT EMP-NAME, DESIGNATION
  FROM EMP-TABLE
  WHERE EMPLOYEE = :EMP
    AND   SSN          = :SSN
;


I am populating the whole HOST VARIABLE ARRAY of EMP n SSN with all the 4 records from input dataset..

After this FETCH for Multi Rows..

Will this work?? I searched for all manuals and forums to see if I can have a HOST VARIABLE ARRAY in WHERE but no success.. Sad
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


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

PostPosted: Thu Sep 22, 2011 2:56 am    Post subject: Reply with quote

Host Variable Arrays are not for WHERE Clause.
best you can do is create an IN List Array.
and, can one emp have more than one ssn
and can an ssn be assigned to more than one emp?
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
justaprogrammer
Beginner


Joined: 01 Jun 2010
Posts: 3
Topics: 1

PostPosted: Thu Sep 22, 2011 4:31 am    Post subject: Reply with quote

I seriously doubt the feasibility behind using IN because I dont know how many records are there in input file.. In case I restrict it to a particular number of reads per cycle then in case if any cycle reads lesser than a specified number of predefined records I will not have anything for file which will be equivalent to SQLERRD(3) in DB@ which can cause me a lot of coding efforts to decide the IN factor for predicate..


Any dbzTHEdinosauer, thanks for the reply.. I had posted this infact to see if there is a possibility of HOST VARIABLE ARRAY for WHERE for which your answer is a well satisfactory one..

Thanks Again..
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Sep 22, 2011 10:26 am    Post subject: Reply with quote

justaprogrammer,

How about Fetching the rows using a BETWEEN for both EMP and SSN. Populate the low and high-values for both EMP and SSN from your file

ex: untested

Code:

DECLARE CURSOR CRSY-TEST
   WITH ROWSET POSITIONING
   FOR
  SELECT EMP-NAME
        ,DESIGNATION
    FROM EMP-TABLE
   WHERE EMPLOYEE BETWEEN :L-EMP AND :H-EMP
     AND SSN      BETWEEN :L-SSN AND :H-SSN
;


Now you have all the rows from table and use that against the internal table you loaded the keys from the file.

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
justaprogrammer
Beginner


Joined: 01 Jun 2010
Posts: 3
Topics: 1

PostPosted: Thu Sep 22, 2011 10:37 pm    Post subject: Reply with quote

kolusu

I had thought of Between and eve tried that on SPUFI with COUNT(*) so as to see if it looks feasible.. but compared to 200 rows I shold have fetched with my file contents I ended up with 2000.. thats for my particular instance.. When the file size will increase and the difference between the high and the low value this count will keep on increasing..

and I believe its much better to use 200 individual fetch rather than selecting 10 times of the rows expected for my code..

Please correct me if I am wrong..
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


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

PostPosted: Fri Sep 23, 2011 3:54 am    Post subject: Reply with quote

justaprogrammer,

you never did answer my question about employee and ssn.
i would think that one or the other would be sufficient; using both would be unnecessary.

also, is there more than one name and destination for each employee?

i would think, based on the little info that you have provided, that a singleton select for each employee would suffice
and that you would not need a cursor.

following up on that thought / not knowing anything about the table/
why not unload the employee table / are there millions and millions of rows?
and do a simple match / or even a dfsort joinkeys/ to extract your information.

the two steps:
  • he unload
  • match
/ even thru a cobol program/ would probably require less resources than thousands of selects.

you have provided little or no information,
and have biased the question based on your presentation.

provide some information to dispute my alternative solution.

and last but not least. yes there is a point of diminishing returns with respect to number of rows retrieved by each FETCH.
But until that point is reached / and it is different in everycase/
pounding thru memory is often faster / though requires more code/
that leaving it up to db2 to make the same decisions.
_________________
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