Page 1 of 1

Basic Statement - CREATE

Posted: Mon Jun 06, 2005 9:07 am
by akrzy
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

Posted: Mon Jun 06, 2005 9:34 am
by ArndW
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.

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

Posted: Mon Jun 06, 2005 11:11 am
by akrzy
Ok,
I think that my code is correct.
i can change ABORT->DSLogFatal();

But still I hvae message in log: "Unable to create the RecentEmployeesBASIC.txt file"

Why the CREATE statement doesn't want to create new file?

Posted: Mon Jun 06, 2005 11:19 am
by ArndW
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?

Posted: Mon Jun 06, 2005 11:29 am
by akrzy
When I try using ON.ERROR job doesn't compiled.

Posted: Mon Jun 06, 2005 11:32 am
by ArndW
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)

Posted: Mon Jun 06, 2005 11:45 am
by akrzy
Yes,
It should be ON ERROR but still I don't know how to use it.
COuld you help me and advise me what is correct form to use that clause?

In BAsic pdf. I don't find any example.
And during compilation I have still error.


Please help...

Posted: Mon Jun 06, 2005 3:13 pm
by ray.wurlod
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.

Posted: Tue Jun 07, 2005 12:24 am
by ArndW
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:

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

...
The sequential file won't get created until the first WRITESEQ to it.

Posted: Tue Jun 07, 2005 1:50 am
by akrzy
It is the problem with directory.
I can create file direct on C dysk but I can't create it in any other directory.

I chacked that they aren't only to read.

Posted: Tue Jun 07, 2005 1:53 am
by ArndW
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.

Posted: Tue Jun 07, 2005 2:22 am
by akrzy
I have server and client on the same machine.
I tried using different directory and it works only for C dysk.
It's strange...
I don't know what is wrong with my WIndows directories :(