Count records of hashed file in a routine

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
rodre
Premium Member
Premium Member
Posts: 218
Joined: Wed Mar 01, 2006 1:28 pm
Location: Tennessee

Count records of hashed file in a routine

Post by rodre »

Can the records of a hashed file be counted from a routine into a variable?
Thanks,
Rodre :)
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

Code: Select all

Command = "COUNT ":Arg1
Call DSExecute('TCL', Command, Output, ReturnCode)
Ans = ReturnCode
where Arg1 is the name of the hashed file.

HTH
Kris

Where's the "Any" key?-Homer Simpson
jdmiceli
Premium Member
Premium Member
Posts: 309
Joined: Wed Feb 22, 2006 10:03 am
Location: Urbandale, IA

Question on where to run the command...

Post by jdmiceli »

Hi Kris,

I like your solution - seems simple enough. However, being new to DataStage, I don't know how I would implement this code. Does it get put into a particular stage or is it run from a console somewhere? I would appreciate your educating me on this.

Bestest!
Bestest!

John Miceli
System Specialist, MCP, MCDBA
Berkley Technology Services


"Good Morning. This is God. I will be handling all your problems today. I will not need your help. So have a great day!"
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

If the hashed file is externally pathed, you'll need to write a function to open the file and count the records or use the SETFILE command to created a pointer to it and then use kris007's method. If the hashed file is in the project, you can use kris007's method.

To read the hashed file, you'll write a function to use OPENPATH on the file, then a SELECT statement to select the keys from the file, then there's about 3 different ways to get the list of keys. One method is a READNEXT loop to read each key from the selection stack, incrementing a counter until the READNEXT fails. Another is to to read the stack into an array from the SELECT statement using RTNLIST, then a simple COUNT(array, @AM) will give you the answer.

I'm sure Kim or Ray will cheat and post the code, but here's a quick chance to learn a little DS BASIC.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

You will have to create this routine in the Manager first. And then you can use it in a Transformer Stage or in a Jobsequence within a RoutineActivity or Uservariables stage provided you pass the name of the hashed file as a parameter depending on your requirement.How exactly would you want to use the number of records in the hashed file with in your Job?
Kris

Where's the "Any" key?-Homer Simpson
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Why a routine? Can't you use a job? What do you want to do with the result? Clearly you are unfamiliar with DataStage routines. You can use the supplied before/after routine ExecUV to execute COUNT #HashedFile# command, but what do you want to do with the result?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rodre
Premium Member
Premium Member
Posts: 218
Joined: Wed Mar 01, 2006 1:28 pm
Location: Tennessee

Post by rodre »

Thank you all for the response. :D
One question:
What is the syntax for the pointer SETFILE command? I don't have the Universe manuals. SETFILE /my/hashed/file accessible. I am in a windows enviroment, do I use the g:\work\files\hashfile path?

Ray,
We have a custom logfile that we use to track the status of a sequencer. We currently use a routine to write into the logfile along the way of the sequencer but we want to change this process and write it into a hashfile instead via a routine from the sequncer. The hashfile count gives us the sequence number to use for the next line.
Let me know if you think of a better way to do this... :)
prabu
Participant
Posts: 146
Joined: Fri Oct 22, 2004 9:12 am

Post by prabu »

rodre wrote:Thank you all for the response. :D
One question:
What is the syntax for the pointer SETFILE command?

Code: Select all

HELP SETFILE
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

Code: Select all

SETFILE /hash_file_path/hash_filename hash_filename OVERWRITING
Kris

Where's the "Any" key?-Homer Simpson
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

OVERWRITING is an optional keyword. I counsel caution using it.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kvsudheer
Premium Member
Premium Member
Posts: 20
Joined: Fri Aug 18, 2006 12:01 am
Location: India

Routine to insert job details

Post by kvsudheer »

We have a requirement to write a after job routine which will capture the job level log details along with warning and error messages and insert into a Control Table. I would like to know how we can insert the values obtained from routine into a table.

Thanks in advance for your help.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:!: Welcome aboard, but you really need to start your own thread on this subject, not jump on the end of this one. We don't know details like Server v. PX, operating system or version of DS that a new post would require.

When you do start your thread, clarify what you mean by 'table'... database? Universe?
-craig

"You can never have too many knives" -- Logan Nine Fingers
rameshrr3
Premium Member
Premium Member
Posts: 609
Joined: Mon May 10, 2004 3:32 am
Location: BRENTWOOD, TN

Post by rameshrr3 »

ray.wurlod wrote:OVERWRITING is an optional keyword. I counsel caution using it. ...
He seems to have used overwriting as he possibly is calling this via Before/After job sub routine using ExecTCL , hence the pointer is being recreated repeatedly, once whenever the job runs.
The only advantage of using OVERWRITING this way is to suppress a warning message in the job log file that would otherwise drive a customer nuts. :wink:

Thanks
Post Reply