Page 1 of 1

the number of records

Posted: Wed Dec 15, 2004 6:23 pm
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

Re: the number of records

Posted: Wed Dec 15, 2004 6:31 pm
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.

Posted: Wed Dec 15, 2004 7:35 pm
by ray.wurlod
A small observation, if I may. The number of records in a file can never be less than zero.

Posted: Wed Dec 15, 2004 8:00 pm
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)

Posted: Wed Dec 15, 2004 9:06 pm
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:

Posted: Wed Dec 15, 2004 9:32 pm
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.

Posted: Thu Dec 16, 2004 2:26 pm
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

Posted: Thu Dec 16, 2004 2:55 pm
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