Get record count as a User Variable

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
syang@collaborative.com
Premium Member
Premium Member
Posts: 33
Joined: Tue Sep 02, 2014 7:43 am

Get record count as a User Variable

Post by syang@collaborative.com »

Hi guys,

This is the requirement:
If table A's record count is 0, don't run job.

I am running Job_A, which loads data into Table_A. Job_B will load data from Table_A into Table_B by truncate and insert. If Table_A is empty, Table_B will be truncated and 0 records will be inserted.

I am trying to get the record count of Table_A and use it as a User Variable in a nested condition.
If count(*) of Table_A > 0 then run Job_B

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

Post by chulett »

Simplest way? Use a Server job to get the count and store it in USERSTATUS then interrogate that to trigger the second job or not.
-craig

"You can never have too many knives" -- Logan Nine Fingers
syang@collaborative.com
Premium Member
Premium Member
Posts: 33
Joined: Tue Sep 02, 2014 7:43 am

Post by syang@collaborative.com »

Thanks for the info. I have not worked with any server jobs, as I'm very new to DataStage. How would I set the UserStatus to the count of a table? I've been looking on this forum, and read about using a transformer, but no real detail on how the mechanics of how this is done.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

It's been discussed quite a bit so there's a lot to wade through when you search for it. I've found a fairly representative example in this post. If that all gets too complicated, you could always simply write the count to a flat file and then use something to read it back into the sequence job... in UNIX you could cat the file while in Windows a type would do it. You could do that in a custom routine or straight up in an Execute Command stage. Many ways to skin this cat. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
syang@collaborative.com
Premium Member
Premium Member
Posts: 33
Joined: Tue Sep 02, 2014 7:43 am

Post by syang@collaborative.com »

Thanks Craig. I ended up writing a routine to get the Link count.

I used this: DSGetLinkInfo(handle, Stage_Name, Link_Name, DSJ.LINKROWCOUNT)

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

Post by chulett »

If you've just loaded it and can use the link row count from the load job, then that works. I was thinking you wanted to check a table and that a single count of the records in the table would be a way to go.
-craig

"You can never have too many knives" -- Logan Nine Fingers
collabxchange
Premium Member
Premium Member
Posts: 34
Joined: Thu Aug 28, 2014 8:48 pm
Location: United States

Post by collabxchange »

Originally, I wanted to do an actual count of Table_A on the database, but I'm limited on time. This routine can check if any records were inserted into Table_A daily. It's no where near perfect, but will get the job done.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you want it bad, you get it bad. :idea:
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