Page 1 of 1

Counting the number of records.

Posted: Thu Sep 15, 2005 10:40 am
by I_Server_Whale
Hi All,

Is there any function which returns the number of records in flat-file? Any help is very much appreciated.

Thanks,
Naveen.

Posted: Thu Sep 15, 2005 12:33 pm
by ArndW
In DataStage you would have to read through the whole file to get that number. In UNIX it would be "wc -l" and if you have DS installed on your workstation that command will also work in Windows from a DOS shell.

Routine ...

Posted: Thu Sep 15, 2005 2:16 pm
by ucf007
Here is a sample routine that works with DS/Solaris/Unix
*************************************************************
** Routine: GetFileNbRows
** Creator: Youssef Loudiyi
** Company: BI Expertise - www.biexpertise.com
*************************************************************
**** Get the line count for .upd files in the Load folder
*Prepare and execute the count

UnixStmt = "wc -l ":FullFileName:" | awk '{print $1}' $1"
Call DSExecute('UNIX',UnixStmt,StdOut, ReturnValue)

*Check if the sentence "Cannot open" is found in the Standard Output, if so, there was no file in the folder.
IF INDEX(OConv(StdOut,"MCL"),"cannot open",1) THEN
Ans = 0
END
ELSE
IF ReturnValue = 0 then
Ans = Left(StdOut,Len(StdOut)-1)

END
ELSE
Call DSLogFatal("Error while trying to execute the 'wc -l' unix command on ":FullFileName, "IDWLineCounter")
END
END
*************************************************************

Posted: Thu Sep 15, 2005 4:32 pm
by ray.wurlod
ReturnValue is the exit status of the command - you don't need to parse the output.