Has anyone implemented this before:
Input file will be placed on the Unix server. On a daily basis, the file might be empty. If the file is empty and my sequencer runs, don't abort the job since there are no records in the file to be process but terminate normal, else process existing rows
I realized that this might have to be done during some kind of script...hence my limitation...I am not a shell script writer. Can someone provide some kind of feedback on how to implement this??
thanks,
dtatem
Checking For Existing Rows In an Input File Before Executing
Moderators: chulett, rschirm, roy
You can find different ways of checking the file size by doing a search. Keywords of search are "check for empty file". Depending upon the result, you can branch your execution.
PS: It does not have to be a script, even a BASIC routine will do the trick. Search for it.
PS: It does not have to be a script, even a BASIC routine will do the trick. Search for it.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Re: Checking For Existing Rows In an Input File Before Execu
hello i am not aware how job sequencer or Routine_Activity works in datastage, but i think below code will enable you to check the file size, and then do further processing.
name of routine: file1
-----------------------code of routine file1---------------------------------
stat=''
if Arg1=@null or Arg1="" then
Ans=0;
PRINT "Enter proper file name"
goto file1:
end
Else
OPENSEQ Arg1 TO test THEN STATUS stat FROM test THEN PRINT ''
field6 = stat<6,1,1>
field8 = stat<8,1,1>
field5 = stat<5,1,1>
PRINT "filesize:": field6
PRINT "userid:": field8
PRINT "permissions:": field5
if trim(field6)=0 then
PRINT " FILE IS EMPTY"
end
CLOSESEQ test
Ans ='STATUS() IS ':STATUS()
end
file1:
----------------------------end of routine file1--------------------------
name of routine: file1
-----------------------code of routine file1---------------------------------
stat=''
if Arg1=@null or Arg1="" then
Ans=0;
PRINT "Enter proper file name"
goto file1:
end
Else
OPENSEQ Arg1 TO test THEN STATUS stat FROM test THEN PRINT ''
field6 = stat<6,1,1>
field8 = stat<8,1,1>
field5 = stat<5,1,1>
PRINT "filesize:": field6
PRINT "userid:": field8
PRINT "permissions:": field5
if trim(field6)=0 then
PRINT " FILE IS EMPTY"
end
CLOSESEQ test
Ans ='STATUS() IS ':STATUS()
end
file1:
----------------------------end of routine file1--------------------------
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Welcome aboard.
All DataStage processes are background processes, so INPUT and PRINT statements don't really do it. However, well spotted that field #6 of the dynamic array returned by the STATUS statement can return the size of the file.
The following function can be called from a Routine activity. Create a server routine whose type is "transform function".
All DataStage processes are background processes, so INPUT and PRINT statements don't really do it. However, well spotted that field #6 of the dynamic array returned by the STATUS statement can return the size of the file.
The following function can be called from a Routine activity. Create a server routine whose type is "transform function".
Code: Select all
FUNCTION FileIsZeroSize(Pathname)
* Returns 1 if file exists and is of zero size, returns 0 if file exists and is larger.
* Returns @NULL if file can not be opened.
OpenSeq Pathname To filevar
On Error
Ans = @NULL
End
Then
Status FileData From filevar
Then
Ans = (FileData<6> = 0)
End
Else
Ans = @NULL ; * could not stat file
End
CloseSeq filevar
End
Else
If FileInfo(filevar, 0) Then CloseSeq filevar
Ans = @NULL
End ; * end of OpenSeq statement
RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 612
- Joined: Thu May 03, 2007 4:59 am
- Location: Melbourne
Re: Checking For Existing Rows In an Input File Before Execu
Modify that this way and try. If Ans = 0, file is not empty, if Ans = 1 then empty else any error Ans = 9.
You can try any of the below unix commands also
ExCmnd = "wc -l ":pathplusfilename
** You can use -
** "test -z ":pathplusfilename or
** "[-z ":pathplusfilename" ]"
Call DSExecute ("UNIX",ExCmnd,Output,SystemReturnCode)
sachin1 wrote: -----------------------code of routine file1---------------------------------
Code: Select all
**Arg1 = PathPlusFileName
Ans = 0
OpenSeq PathPlusFileName To FileVar Then
STATUS stat FROM FileVar THEN
if stat<6,1,1> = 0 then
Ans = 1
End Else
Call DSLogInfo("File not empty","JobControl")
End
End
Else
Ans = 9
Call DSLogWarn("File Open error : ":PathPlusFileName ,"JobControl")
End
ExCmnd = "wc -l ":pathplusfilename
** You can use -
** "test -z ":pathplusfilename or
** "[-z ":pathplusfilename" ]"
Call DSExecute ("UNIX",ExCmnd,Output,SystemReturnCode)
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>