Deleting hash files (2)

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
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Deleting hash files (2)

Post by gpbarsky »

Hi.

Is there any command to delete several has files from one single command ?

I am looking for something liek "DELETE.FILE p3*", and everything beginning with p3 should be deleted.

Thanks.


Guillermo P. Barsky
Buenos Aires - Argentina
mhester
Participant
Posts: 622
Joined: Tue Mar 04, 2003 5:26 am
Location: Phoenix, AZ
Contact:

Post by mhester »

Guillermo ,

From TCL or the command window do the following -

>SELECT VOC LIKE MJH...

2 record(s) selected to SELECT list #0.
>>DELETE.FILE
DELETEd "MJH1", Type 30.
DELETEd file "D_MJH1", Type 3, Modulo 1.
DELETEd file definition record "MJH1" in the VOC file.
DELETEd "MJH2", Type 30.
DELETEd file "D_MJH2", Type 3, Modulo 1.
DELETEd file definition record "MJH2" in the VOC file.

I had two files named MJH1 and MJH2.

Hope this helps,

Michael Hester
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Post by gpbarsky »

[:)][:)][:)][:)][:)]

Hi Michael. Thanks for your response.

I am not executing the DELETE.FILE command from a TCL window. I am finishing a job control, and I want to delete all generated hash files, from within the job (BASIC code).

Is there a way to do this ?

And thanks again.

[:)][:)][:)][:)][:)]

Guillermo P. Barsky
Buenos Aires - Argentina
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Guillermo

Michael is probably on a plane so I will answer.

.
.
.



cmd = 'SELECT VOC LIKE p3...'
execute Cmd capturing output
open 'VOC' to VOC else stop
loop while readnext id
read VocRec from VOC, id then
VocType = VocRec[1,1]
if VocType = 'F' then
Cmd = 'DELETE.FILE ':id
execute Cmd
end
end
repeat



.
.
.
Kim.


Kim Duke
DsWebMon - Monitor over the web
www.Duke-Consulting.com
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

For this approach to work, you will need to have used a pattern to the names of your hashed files, and they will have to have been created with CREATE.FILE in the local account.
Otherwise you will need to adjust the code to use DELETE.FILE, DROP TABLE or rm (or del) as appropriate. If there is no pattern to the naming of hashed files, you really need to create a list of hashed files that you need to delete.
The totally general solution is quite complex. One approach might be to check the log for commands that create hashed files, but this falls over if the hashed files were created in a different job. You really do need to operate from the job's own design information, and perhaps this will involve decoding parameter values with which the job was started (which can be had from the job log "start" event).

Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Post by gpbarsky »

[:)][:)][:)][:)][:)]

Kim, Ray:

Thank you for your help [^][^].

The hash files are being created from the running server jobs. I checked the log and this is the message:

Executing Command =
CREATE.FILE p3210000050auxHash_Filial_Asterisco_Tarj.h DYNAMIC

And like this, I have several files that are the consecuence of the execution of an order. All the generated hash files match the "p3210000050*" criteria.

So, I will try with Kim's formula, and then I will post here if everything work fine.

Thanks again.

[:)][:)][:)][:)][:)]

Guillermo P. Barsky
Buenos Aires - Argentina
mhester
Participant
Posts: 622
Joined: Tue Mar 04, 2003 5:26 am
Location: Phoenix, AZ
Contact:

Post by mhester »

Kim knows me to well [:)] Indeed I was on a plane!

I also wanted to point out that the use of "Execute" within BASIC code within DS should be avoided. There has been a long standing unwritten warning regarding its use. It may work 999 times out of 1000 and then fail. I have seen a command similar to what Kim outlines return bogus select lists or no select list at all.

The preferred approach would be to use the Perform statment rather than the Execute statement.

Execute creates a new environment for the executed command. Stacked @variables are initiliazed to 0 among other things.

Perform on the other hand does not create a new environment for the executed command and things like common, @variables etc... retain their values.

Regards,

Michael Hester
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Post by gpbarsky »

Michael, Kim:

I tried with the followinf code:

job = "DelHashFiles2"
cmd = 'SELECT VOC LIKE p2210000153*'
PERFORM Cmd
OPEN 'VOC' to VOC else CALL DSLogFatal("Out of OPEN",job)
CALL DSLogInfo("Out of OPEN fine.",job)
LOOP WHILE READNEXT id
CALL DSLogInfo("Enters the cycle.",job)
read VocRec from VOC, id
THEN
VocType = VocRec[1,1]
IF VocType = 'F'
THEN
Cmd = 'DELETE.FILE ':id
CALL DSLogInfo("File to be deleted=":id,job)
**PERFORM Cmd
END
END
ELSE
CALL DSLogFatal("Out of READ",job)
END
REPEAT

But it never entered to the cycle. The only message that I can see in the log is "Out of OPEN fine.".

Is there anything wrong in these lines ? [?][?]

Thanks in advance.


Guillermo P. Barsky
Buenos Aires - Argentina
mhester
Participant
Posts: 622
Joined: Tue Mar 04, 2003 5:26 am
Location: Phoenix, AZ
Contact:

Post by mhester »

The statement -

cmd = 'SELECT VOC LIKE p2210000153*'

should be

cmd = 'SELECT VOC LIKE p2210000153...'

The * wildcard is not recognized.

Regards,

Michael Hester

p.s. I did not really look at the rest of the code. My suggestion is based on the fact that the rest of the code is logically correct.
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Post by gpbarsky »

Michael:

Thank you for your response.

I replaced the asterisc by the three consecutive dots, but I'm getting the same results as described in my post above. [:(]

Guillermo P. Barsky
Buenos Aires - Argentina
mhester
Participant
Posts: 622
Joined: Tue Mar 04, 2003 5:26 am
Location: Phoenix, AZ
Contact:

Post by mhester »

Guillermo,

I rewrote a bit and it works. The code could certainly be more efficient, but you'll get the idea and this should work for what you are doing. This code is for a server routine. Of course you should replace the PRINT statements with calls to DSLogInfo. This is a debug technique that I use when writing routines. You can test and then double click the results pane and see the output.


job = "DelHashFiles2"
Ans = 0
EOF = 0
cmd = "SELECT VOC LIKE 'p2210000153...'"
PERFORM cmd
OPEN 'VOC' to VOC else PRINT "ERROR OPENING VOC"
PRINT "SUCCESSFULLY OPENED VOC"
LOOP
READNEXT ID ELSE EOF = 1
WHILE NOT(EOF)
PRINT "INSIDE OF LOOP"
READ VOCREC FROM VOC, ID THEN
IF VOCREC[1,1] = 'F' THEN
cmd = 'DELETE.FILE ':ID
PRINT "DELETING FILE ":ID
PERFORM cmd
END
END ELSE
PRINT "UNABLE TO READ VOC RECORD"
END
REPEAT

Regards,

Michael Hester
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Post by gpbarsky »

Michael:

IT WORKED FINE [:)]. Thank you very much.

I added some counters to have the total read and the total deleted. When I run the job, both totales were displayed to 1. And I guess that this is because of the wildcard that I'm using in the delete command.

I really could check that several hash files were deleted by this operation.

Thanks again.


Guillermo P. Barsky
Buenos Aires - Argentina
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Guillermo

BASIC is not the same as other languages. I do not think. END on one line and ELSE on the next is the same as END ELSE on the same line. I would have to test it.

Kim.

Kim Duke
DsWebMon - Monitor over the web
www.Duke-Consulting.com
Post Reply