Getting Max Row From DB2 To Be Used DownStream

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
dtatem
Participant
Posts: 54
Joined: Wed Jun 09, 2004 7:50 am

Getting Max Row From DB2 To Be Used DownStream

Post by dtatem »

I want to get the max(row_id)+1 from a db2 table then use this value as a parameter to pass into my surrogate stage.. what is the best way to implement this?

I can create the DB2 job first to get the result...but then I want to use that result downstream, how would I pass it to be used downstream?

Thanks

dtatem
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

UserStatus is a good candidate in such situations.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

USER STATUS is not present in parallel jobs.
For a parallel job. You can load the value into a flat file and then use execute command stage to cat the value and pass it as a parameter value to your next job, via job sequence.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

My bad, did not check the "Job Type".
Not sure why this feature was excluded from the Parallel jobs. :?
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
dtatem
Participant
Posts: 54
Joined: Wed Jun 09, 2004 7:50 am

Getting Max Row From DB2 To Be Used DownStream

Post by dtatem »

DSguru2B wrote:USER STATUS is not present in parallel jobs.
For a parallel job. You can load the value into a flat file and then use execute command stage to cat the value and pass it as a parameter value to your next job, via job sequence.
Thanks, seems kinda complex can you provide some additional information? Kinda new at this


dtatem
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

DSguru2B wrote:USER STATUS is not present in parallel jobs.
So? Use a Server job to get the max value. Have it pass the value via Sequence job and USERSTATUS to the PX job.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

So, a px job cannot be used. But as you said, a server job is a perfectly viable solution.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Rubbish! A parallel job can certainly be used. Put a DB2 stage feeding a reference link to a Lookup stage, and execute the query in the DB2 stage.

Code: Select all

SELECT 'X', MAX(surrkey) + 1 FROM tablename
The trick is to make sure that the reference input to the Lookup stage uses Entire partitioning, so that the same initial value is available on all partitions.

Upstream use a Column Generator stage to generate the constant value 'X'. Use this as the lookup key.

Downstream, in a Transformer stage, you increment as required; you will need an expression based upon the partition number and partition count to guarantee uniqueness. Search the forum or Vincent's blogs; the expression has been given a number of times before.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dtatem
Participant
Posts: 54
Joined: Wed Jun 09, 2004 7:50 am

Getting Max Row From DB2 To Be Used DownStream

Post by dtatem »

ray.wurlod wrote:Rubbish! A parallel job can certainly be used. Put a DB2 stage feeding a reference link to a Lookup stage, and execute the query in the DB2 stage.

Code: Select all

SELECT 'X', MAX(surrkey) + 1 FROM  ...[/quote]

with the lookup stage, what am I joining on? I am not sure on this...if you can mock up a dsx and email it to me that would be great


dtatem
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You are joining on the constant value 'X'.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

ray.wurlod wrote:Rubbish! A parallel job can certainly be used.
....and who said it cant be. The job type argument was based on specifically using USER STATUS. Any other method, including the one you advised, has no relation to the "USER STATUS with Parallel Job" discussion.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Nothing to stop you using the user status area in a parallel job. Though you will need to create a parallel routine that invokes DSSetUserStatus() - the one from the C-callable API.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Or - I assume - use a BASIC Transformer in the PX job, with all the caveats that brings to the table. It's not that Parallel jobs "don't have a user status area" - they do. It's just that it is not quite as simple to get to in a Parallel job as it is in Server. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
dtatem
Participant
Posts: 54
Joined: Wed Jun 09, 2004 7:50 am

Post by dtatem »

Ray:

Getting back to your reply on "Rubbish! A parallel job can certainly be used. Put a DB2 stage feeding a reference link to a Lookup stage, and execute the query in the DB2 stage. Code: SELECT 'X', MAX(surrkey) + 1 F ..."

If I understand what you are referring to, I use a sequential File going into a lookup stage with the DB2 statement you mentioned. In the sequential File I Have one column 'X' joining to the DB2 stage which also have a colum 'X'

Is this is what you mean?

thanks,
dtatem
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not quite.

What I mean is a new column, generated in a Column Generator stage (that is, not in the file itself). The column name can be anything you like; the value in it must be 'X' for every row.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply