DeleteSeq???

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
ogmios
Participant
Posts: 659
Joined: Tue Mar 11, 2003 3:40 pm

DeleteSeq???

Post by ogmios »

You can open ASCII files from DataStage with OpenSeq, write to them, close them. But is there also a function to delete files from within a BASIC program? I haven't found any so far.

Ogmios
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Just make a call to the o/s and 'del' or 'rm' them...

-craig
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

And the easiest way to do this from DataStage BASIC is via the DSExecute() function.

If System(91) = 0
Then
Shell = "UNIX"
RmCmd = "rm "
End
Else
Shell = "DOS"
RmCmd = "DEL /S "
End
Command = RmCmd : PathnameOfFile
Call DSExecute(Shell, Command, Output, ExitStatus)


Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And you may want to use "rm -f " for Unix.

It won't last long, but Ray has hit a magic posting number - 666! [}:)]

-craig
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Ray

I turned this into a function. Very dangerous.

Code: Select all

* ------------------------------------------------------------
* KgdRemoveDir(DirName)
* Decription: This routine will remove DirName
* Written by: Kim Duke
* Notes:
* ------------------------------------------------------------
* $INCLUDE DSINCLUDE JOBCONTROL.H
      Ans = @FALSE
      If System(91) = 0 Then
         Shell = "UNIX"
         Sep = '/'
         RmCmd = 'rm -rf '
      End Else
         Shell = "DOS"
         Sep = '\'
         RmCmd = 'DEL /S '
      End
      print "Shell = ":Shell
      print "Sep = ":Sep
* ------------------------------------------------------------
      OpenPath DirName To FileVariable Then
         Close FileVariable
         Command = RmCmd:DirName
         print Command
* ------------------------------------------------------------
         * Call DSExecute(Shell, Command, Output, ErrorCode)
         If ErrorCode > 0 Then
            Ans = @FALSE
            print "ErrorCode = ":ErrorCode
            goto TheEnd
         End Else
            Ans = @TRUE
         End
      End
* ------------------------------------------------------------
TheEnd:
      print "Ans = ":Ans

Also MakeDir

Code: Select all

* ------------------------------------------------------------
* KgdMakeDir(DirName)
* Decription: This routine will make all the dirs in DirName
* Written by: Kim Duke
* Notes:
* ------------------------------------------------------------
* $INCLUDE DSINCLUDE JOBCONTROL.H
      Ans = @FALSE
      If System(91) = 0 Then
         Shell = "UNIX"
         sep = '/'
      End Else
         Shell = "DOS"
         sep = '\'
      End
      print "Shell = ":Shell
      print "sep = ":sep
* ------------------------------------------------------------
      NoOfDirs = dcount(DirName, sep)
      for i=1 to NoOfDirs
         tmpDir = field(DirName, sep, 1, i)
         OpenPath tmpDir To FileVariable On Error
            cmd = "mkdir ":tmpDir
            print cmd
* ------------------------------------------------------------
            Call DSExecute(Shell, cmd, output, ErrorCode)
            If ErrorCode > 0 Then
               Ans = @FALSE
               print "ErrorCode = ":ErrorCode
               goto TheEnd
            End Else
               Ans = @TRUE
            End
         End Then
            Ans = @TRUE
            Close FileVariable
         End Else
            cmd = "mkdir ":tmpDir
            print cmd
* ------------------------------------------------------------
            Call DSExecute(Shell, cmd, output, ErrorCode)
            If ErrorCode > 0 Then
               Ans = @FALSE
               print "ErrorCode = ":ErrorCode
               goto TheEnd
            End Else
               Ans = @TRUE
            End
         End
      next i
* ------------------------------------------------------------
TheEnd:
      print "Ans = ":Ans

I am using these to automate documentation. I have a function documentor like JobReport on ADN. I will post it soon. I think the KgdMakeDir(DirName) is very useful.
Mamu Kim
Post Reply