Counting 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
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Counting the number of records.

Post 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
ucf007
Charter Member
Charter Member
Posts: 18
Joined: Fri Feb 27, 2004 2:25 pm

Routine ...

Post 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
*************************************************************
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

ReturnValue is the exit status of the command - you don't need to parse the output.
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