Sequential File Clearing

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
snassimr
Premium Member
Premium Member
Posts: 281
Joined: Tue May 17, 2005 5:27 am

Sequential File Clearing

Post by snassimr »

Hi !

I need to clear file befor job . I wonder if there is any way to do it via BASIC code before the job starting
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Yes, you can do it via BASIC, an OPENSEQ then WEOFSEQ will do it for you. But the job has the option to clear the file, plus you might also put in a "rm <filename>" as an external call before a job.
snassimr
Premium Member
Premium Member
Posts: 281
Joined: Tue May 17, 2005 5:27 am

Post by snassimr »

Sorry ArnWd! But Are you sure WEOFSEQ do something else . Dont I need something with CLEARFILE.

If you can to give all code. I dont succeed to run it.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Are you trying to clear a sequential file or a HASHed file? the OPENSEQ and WEOFSEQ are, as might be guessed from the names, functions for sequential files.

There is no BASIC language statement to clear a hashed file. The TCL command is "CLEAR.FILE <filename>"; you can execute that from a before-job subroutine or from within a BASIC program via the EXECUTE command.
elavenil
Premium Member
Premium Member
Posts: 467
Joined: Thu Jan 31, 2002 10:20 pm
Location: Singapore

Post by elavenil »

If the file is Sequential file, as Arnd mentioned you can use rm/del to delete the file and touch/echo command to create the file again.

You need to check the OS before executing the commands if the code is common for Windows and UNIX.

HTWH.

Regards
Saravanan
snassimr
Premium Member
Premium Member
Posts: 281
Joined: Tue May 17, 2005 5:27 am

Post by snassimr »

I try to clear seq file . EXECUTE hung up.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

snassimr,

please tell us your EXECUTE command. It normally does not hang.

Also, please tell us if you are trying to clear the contents of a sequential or a hash file.
snassimr
Premium Member
Premium Member
Posts: 281
Joined: Tue May 17, 2005 5:27 am

Post by snassimr »

I try to clear seq file.

in Administrator when I run the command CLEAR.FILE filename I get enable to clear file + file name

When I run the Routine Activity of JOB SEQUENCE and befor/after routine with code:

EXECUTE "CLEAR.FILE 'DW_FACT_DIAGNOSIS_TMP'";

I get in sequence :

Attempting to Cleanup after ABORT raised in stage TestClearRoutine..JobControl
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

snassimr,

you cannot use the CLEAR.FILE command on a sequential file.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:? CLEAR.FILE is for hash files, not sequential files. People have mentioned that more than once here.

You can either open it in a BASIC routine and then WEOFSEQ - Write an End-Of-File mark - to it which will 'clear' it - or simply delete the file.

I almost hate to ask - why do you feel you need to 'clear' it? Why not handle it inside the job?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Craig,

I've been trying to get that answer since the first reply. I thought it was a HASH file, and if you do 2 or more writes to the same file from a transform you might get contention, so I like to do an external CLEAR.FILE; but since a sequential file can only be opened once for writing that cannot be the case.
snassimr
Premium Member
Premium Member
Posts: 281
Joined: Tue May 17, 2005 5:27 am

Post by snassimr »

I run 5 instances of job one after other and before i need clear file and do append to it of all rows are going with 5 jobs. I dont want to delete file
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

In the Job Control or wherever ou wish to trigger the clearing of the file, you can specify:

Code: Select all

OPENSEQ 'myseqfile' TO SeqFilePtr THEN WEOFSEQ SeqFilePtr ELSE NULL
CLOSESEQ SeqFilePtr
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can delete the file. The first job will still create it, even when set to append.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply