Basic Statement - CREATE
Moderators: chulett, rschirm, roy
Basic Statement - CREATE
Can you tell me what is wrong with this statement that this job control doesn't work?
OPENSEQ "C:\DS305Files\RecentEmployeesBASIC.txt" TO H.RECENT.EMPLOYEES ELSE
CALL DSLogInfo("Attempting to create the RecentEmployeesBASIC.txt file.", "Job seqRecentEmployeesBASIC")
CREATE H.RECENT.EMPLOYEES ELSE
CALL DSLogInfo("Unable to create the RecentEmployeesBASIC.txt file.", "Job seqRecentEmployeesBASIC")
*ABORT
END
The program is Aborted after CREATE statement .
Anka
OPENSEQ "C:\DS305Files\RecentEmployeesBASIC.txt" TO H.RECENT.EMPLOYEES ELSE
CALL DSLogInfo("Attempting to create the RecentEmployeesBASIC.txt file.", "Job seqRecentEmployeesBASIC")
CREATE H.RECENT.EMPLOYEES ELSE
CALL DSLogInfo("Unable to create the RecentEmployeesBASIC.txt file.", "Job seqRecentEmployeesBASIC")
*ABORT
END
The program is Aborted after CREATE statement .
Anka
akrzy,
Your code basically tries to open a sequential file and if it is not already there it will specifically CREATE an empty file. At least that is what is supposed to be happening.
Do not use the ABORT command, the preferred method of stopping any DataStage job from continuing is to call DSLogFatal().
I would recommend always using indentation in your code, it makes it so much easier to understand. The OPENSEQ also has an ON.ERROR that you should use, as a failure CREATE the file could result from the file existing but the user not having read or write access to it, or that the file is already open for writing.
Your code basically tries to open a sequential file and if it is not already there it will specifically CREATE an empty file. At least that is what is supposed to be happening.
Do not use the ABORT command, the preferred method of stopping any DataStage job from continuing is to call DSLogFatal().
I would recommend always using indentation in your code, it makes it so much easier to understand. The OPENSEQ also has an ON.ERROR that you should use, as a failure CREATE the file could result from the file existing but the user not having read or write access to it, or that the file is already open for writing.
Code: Select all
OPENSEQ "C:\DS305Files\RecentEmployeesBASIC.txt" TO H.RECENT.EMPLOYEES
ON.ERROR
CALL DSLogInfo('Got an error, status is "':STATUS():'".',"Job seqRecentEmployeesBASIC")
END
ELSE
CALL DSLogInfo("Attempting to create the RecentEmployeesBASIC.txt file.", "Job seqRecentEmployeesBASIC")
CREATE H.RECENT.EMPLOYEES
ELSE
CALL DSLogFatal("Unable to create the RecentEmployeesBASIC.txt file.", "Job seqRecentEmployeesBASIC")
END ;** of ELSE could not create sequential file
END ;** of ELSE file does not exist
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
akrzy,
so what happens when you run the code with the ON.ERROR, does it enter that branch?
Does the C:\DS305FILES directory exist (i.e. what happens if you just try to open C:\test.txt?
so what happens when you run the code with the ON.ERROR, does it enter that branch?
Does the C:\DS305FILES directory exist (i.e. what happens if you just try to open C:\test.txt?
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
I probably got the syntax wrong. Look at the BASIC manual PDF for the exact command, it might be ON ERROR (actually, now that I think about it, that is the correct form)
<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:
What value is returned by STATUS() when OPENSEQ is executed?
The ELSE clause can be taken for a number of reasons - read the manual on OPENSEQ. For example, of C:\DS305Files does not exist, OPENSEQ will fail, you will not have a valid file variable, and CREATE is therefore doomed.
I don't use CREATE in general. Any operation that writes to the opened file will bring it into existence. Use CREATE only if you must have a 0-byte file if nothing is written to it.
The ELSE clause can be taken for a number of reasons - read the manual on OPENSEQ. For example, of C:\DS305Files does not exist, OPENSEQ will fail, you will not have a valid file variable, and CREATE is therefore doomed.
I don't use CREATE in general. Any operation that writes to the opened file will bring it into existence. Use CREATE only if you must have a 0-byte file if nothing is written to it.
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.
akrzy,
I agree with what Ray said - but I seem to remember a prolonged thread a coupel of weeks ago about the CREATE statement... I never use it but others argued that it ought to be used. My usual syntax for opening and/or creating a sequential file is:
The sequential file won't get created until the first WRITESEQ to it.
I agree with what Ray said - but I seem to remember a prolonged thread a coupel of weeks ago about the CREATE statement... I never use it but others argued that it ought to be used. My usual syntax for opening and/or creating a sequential file is:
Code: Select all
OPENSEQ 'myfile' TO MyFilePtr
THEN
WEOFSEQ MyFilePtr ;** truncate & overwrite existing file
END
ON.ERROR
STOP 'Bad open of myfile, Status is ':STATUS()
END
ELSE
PRINT 'Creating file "myfile"'
END
...
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
akrzy,
you need to be careful with Windoze paths that have embedded spaces in them, but the sample file you mentioned, "C:\DS305Files\RecentEmployeesBASIC.txt" should work. Please remember that the file is going to be created on the server/b] path as specified, not on your local client pc.
you need to be careful with Windoze paths that have embedded spaces in them, but the sample file you mentioned, "C:\DS305Files\RecentEmployeesBASIC.txt" should work. Please remember that the file is going to be created on the server/b] path as specified, not on your local client pc.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>