Basic Statement - CREATE

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
akrzy
Participant
Posts: 121
Joined: Wed Dec 08, 2004 4:46 am

Basic Statement - CREATE

Post 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
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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
akrzy
Participant
Posts: 121
Joined: Wed Dec 08, 2004 4:46 am

Post 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?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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?
akrzy
Participant
Posts: 121
Joined: Wed Dec 08, 2004 4:46 am

Post by akrzy »

When I try using ON.ERROR job doesn't compiled.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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)
akrzy
Participant
Posts: 121
Joined: Wed Dec 08, 2004 4:46 am

Post 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...
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
akrzy
Participant
Posts: 121
Joined: Wed Dec 08, 2004 4:46 am

Post 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
akrzy
Participant
Posts: 121
Joined: Wed Dec 08, 2004 4:46 am

Post 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 :(
Post Reply