I have an existing sequential file that was generated by an earlier DS job - joblog.txt in the below example.
Now In my job Control code for a set of different jobs I need to add a few more lines to this file.
But I seem to be overwrting whats already existing in that file. I have attached my code below
FileName = "/fmac/users/c10265/joblog.txt"
OPENSEQ FileName to FILE
Then
Call DSLogInfo ("File": FileName: "OPen","JobControl")
End
Else
Call DSLogInfo ("Creating File","JobControl")
End
TXT = "The row count is ":Rowcount
WRITESEQ TXT to FILE else
Call DSLogFatal("Could not update the file: ":FileName, "OutputFile" )
End
TXT1 = " No of rows that do not match = " :Mismatch
WRITESEQ TXT1 to FILE else
Call DSLogFatal("Could not update the file: ":FileName, "OutputFile" )
End
WEOFSEQ FILE
CLOSESEQ FILE
I've haven't done any work with PX but if the Basic is the same as in Server than here are my observations.
Once you open your file you need to perform a Seek to move your file pointer to the end of your file in order to append data. Opening and then writing directly will over write any existing data that is at the beginning of the file. Also as you are writing an EOF marker (WEOFSEQ) after you execute your two write statements you are effectively truncating any remaining data in the file.
Also note that the comment "Creating File" in the Else statment of OpenSeq will not actually create the file. If you need to create a file use the statement Create.
The syntax for Seek and Create can be found in the Basic Basic Quide pdf installed with your Datastage client.
I have not used the SEEK statement in a long time but I believe the following syntax would position the file pointer to right before the EOF of an open sequential file.
xcb wrote:...
Also note that the comment "Creating File" in the Else statment of OpenSeq will not actually create the file. If you need to create a file use the statement Create...
xcb,
the file will be created using the code mprashant has; there is another current thread dealing with the elegance of using this method, but regardless of stylistic issues it will work as coded.
If you don't believe it, just write a user-function and enter a this 4-liner:
xcb wrote:...
Also note that the comment "Creating File" in the Else statment of OpenSeq will not actually create the file. If you need to create a file use the statement Create...
xcb,
the file will be created using the code mprashant has; there is another current thread dealing with the elegance of using this method, but regardless of stylistic issues it will work as coded.
If you don't believe it, just write a user-function and enter a this 4-liner: