Would like to not create an empty csv file
Moderators: chulett, rschirm, roy
Would like to not create an empty csv file
Hi,
I created a file csv but I would not like to create the latter when it's empty (only column name present), is it possible?
Thanks
I created a file csv but I would not like to create the latter when it's empty (only column name present), is it possible?
Thanks
Unfortunately no, the empty text file will be created by DataStage.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
Since MKS gets installed on a Windows server you can use "wc -l <filename>" platform independantly to get empty files.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Use an after-job subroutine. When a file is opened with OpenSeq statement the System() function can return the file size (among other things). Then use CloseSeq and execute a command to delete the file. Pass the file's pathname as the input argument.
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: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Actually it's the STATUS statement, rather than the System() function, that you need here. This statement returns a dynamic array of information about the file whose file handle is provided.
The following example code has minimum error handling, for purposes of clarity.
The following example code has minimum error handling, for purposes of clarity.
Code: Select all
SUBROUTINE DeleteIfEmpty(aPathname, aErrorCode)
* Setting error code to a non-zero value will abort the job.
aErrorCode = 0
OpenSeq aPathname To hFile
On Error
aErrorCode = Status()
End
Locked
aErrorCode = Status()
End
Then
Status FileInformation From hFile
Then
FileSize = FileInformation<6>
If FileSize = 0
Then
Shell = (If System(91) Then "DOS" Else "UNIX")
Command = (If System(91) Then "DEL " Else "rm ") : aPathname
CloseSeq hFile
Call DSexecute(Shell, Command, Output, ExitStatus)
End
End
End
Else
If Status() = 0 Then CloseSeq hFile
aErrorCode = 2 ; * pathname does not exist or is not a file
End
RETURN
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: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You can, of course, test for the file size in a DOS batch file which you might invoke via the ExecDOS after-job subroutine. You can find the technique more fully documented in DOS help or via an internet search.
In essence the technique involves simply using the z modifier for a FOR variable reference. For example:
The BASIC code I posted earlier has the advantage that it works on all platforms.
In essence the technique involves simply using the z modifier for a FOR variable reference. For example:
Code: Select all
set "filemask=myfile*.txt"
for %%A in (%filemask%) do if %%~zA==0 echo."%%A" is empty
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.