the number of records

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
DSkkk
Charter Member
Charter Member
Posts: 70
Joined: Fri Nov 05, 2004 1:10 pm

the number of records

Post by DSkkk »

hi,
i need a routine to count the number of records in the input file. if the number of records in a file is less than zero then my further sequence should stop from running. i get a failure when there is no file at all but my sequence should stop when there is a file with zero records. if a job runs with a file having zero records then my remaining sequences which should run after this job are aborting.
so if anyone could help me in writing a routine, i would really appreciate it.
thanks in advance
g.kiran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: the number of records

Post by chulett »

DSkkk wrote:if the number of records in a file is less than zero then my further sequence should stop from running.
You might want to restate that requirement. :wink:

How about a simple "wc -l" command? That would return the number of records in a file and you could then make decisions based on that. Your routine could execute it using DSExecute and capture the results.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

A small observation, if I may. The number of records in a file can never be less than zero.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSkkk
Charter Member
Charter Member
Posts: 70
Joined: Fri Nov 05, 2004 1:10 pm

Post by DSkkk »

i meant that the records are equal to zero then the job should not continue to run.

is DSExecute used in unix??
but i want to get the number of records in datastage compare it then proceed(data stage is in windows environment)
g.kiran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No, DSExecute is a DataStage function that can be used to run operating system commands, amongst other things.

You are going to need to be a little more specific so we can help. You marked your Server platform as "UNIX" in your first post but also just said that "data stage is in windows environment". When you built routines and execute commands via something like DSExecute, those commands will run where your Server software is installed.

Not sure what the equivalent on a Windows server would be, but on UNIX you could write a routine that takes a full filename as an argument and uses "wc -l" to get the number of records in it. The result could be passed back as the 'Ans' or return code. Use it in a Sequencer job with a Routine Activity stage and then follow it with a Nested Exception stage. If the count is greater than zero, run your next job or series of jobs. If zero, branch around those jobs. Use a Sequence stage set to 'Any' to bring the two streams back together if you need to.

Hope this helps! :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
dsxdev
Participant
Posts: 92
Joined: Mon Sep 20, 2004 8:37 am

Post by dsxdev »

Hi
To get the line count of a file in a Routine you can use this piece of code.

Code: Select all

Call DSExecute("UNIX","wc -l ":strFileName,Output,SystemReturnCode)

If Output=0 Then 
-- logic to be implemented
End

You can read a Job parameter from the routine and assign the variable strFileName the file name.

Output is the output of the command
SystemReturnCode is the return code from unix command.
Happy DataStaging
DSkkk
Charter Member
Charter Member
Posts: 70
Joined: Fri Nov 05, 2004 1:10 pm

Post by DSkkk »

actually my source is in XML and we convert it into flat files using a Loadscript. the header will have record count in it. if i use wc -l then the header also gets counted and it will not show zero rows in it. can i create a sequence where i can get the count gives no of rows because datastage grabs only the data directly( not the header)
my file looks like this
<?xml version="1.0" encoding="utf-8" ?>
<batch recordcount=" 13703" source="ABC" createdate="2004-12-15 00:00:00 ">
<email transDate="2004-12-14 00:00:0" delv="N"><eaddr>caroleclem@abc.net</eaddr></email>


so the if do a wc -l then i will count the above two lines too
can anyone please give me the solution
g.kiran
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Change the logic only slightly. If those two lines are always there, then the test becomes

Code: Select all

Call DSExecute("UNIX", "wc -l " : filename, Output, ExitStatus)
Convert @FM To "" In Output  ;* remove any "line feeds"
If Trim(Output) <= 2 Then
   * logic for empty file
End
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