can you explain with this ArchiveFiles routine

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
kunj201
Participant
Posts: 15
Joined: Tue May 03, 2005 8:02 pm

can you explain with this ArchiveFiles routine

Post by kunj201 »

Can you explain what formate is the aParameterList and what is does?


* Call Archive routine to move files from working directories to ThisBatchArchive_dir and compress.
* ArchiveFiles(pParameterList,JobName,Output_file,pThisBatchArchive_dir)
* The ArchiveFiles routine will figure out which files in which directories belong to each Job
*

* pParameterList is an array of the form pParameterList<1, n> = ParmName<n>, pParameterList<2, n> = ParmValue<n>

Ans = Screen Output(s) :Code as follow

Code: Select all

DEFFUN GetParam(aParameterList, vParmName) Calling "DSU.GetParam"

*  pParameterList is an array of the form  pParameterList<1, n> = ParmName<n>, pParameterList<2, n> = ParmValue<n>

      vMsgInfo = "Routine: ArchiveFiles"

      aDirList = ""
      aDirNames = ""
      vError = @FALSE
      aAllScreenOutputs = ""

      aParameterList = TRIM(pParameterList)
      vJobName = TRIM(pJobName)
      vOutputFile = TRIM(pOutputFile)
      vThisBatchArchive_dir = TRIM(pThisBatchArchive_dir)


      vListCt = DCount(aParameterList<1>, @VM)

* to test using the test button uncomment the following lines
      vPlist = pParameterList
      aParameterList = ""
      Convert "," to @AM IN vPlist
      vListCt = DCount(vPlist, @AM)
      For ix = 1 to vListCt
         aParameterList<1,ix> = field(vPlist<ix>,"=", 1)
         aParameterList<2,ix> = field(vPlist<ix>,"=", 2)
      Next ix


      aAllScreenOutputs<-1> = "________________________________________________________"
      aAllScreenOutputs<-1> = "Parameter List below contains ":vListCt:" params:":@AM:aParameterList
      aAllScreenOutputs<-1> = "________________________________________________________"

      vSystemType = GetParam(aParameterList, "SystemType")
      If vSystemType = "NT" Then
         cSlash = "\"
         MKDIRcmd = "mkdir "
         LScmd = "dir /b "
         MOVEcmd = "move "
         ZIPcmd = "pkzip "
         CONVERT ":" TO "_" IN vJobName
      End Else
         vSystemType = "UNIX"
         cSlash = "/"
         MKDIRcmd = "mkdir -p "
         LScmd = "ls "
         MOVEcmd = "mv "
         ZIPcmd = "gzip "
      End

      aNOArchive = DOWNCASE(GetParam(aParameterList, "NOArchive"))
      CONVERT "," TO @AM IN aNOArchive

      For iP = 1 to vListCt
         vParmName = DOWNCASE(aParameterList<1,iP>)
         LOCATE vParmName IN aNOArchive SETTING POS THEN
*           * Skip the directories in aNOArchive list
         END ELSE
            Begin Case
               Case Right(vParmName, 4) = "_dir" OR Right(vParmName, 9) = "directory"
                  vParmValue = aParameterList<2,iP>
                  vSlashCnt = DCOUNT(vParmValue, cSlash)
                  aDirList<-1> = vParmValue
                  aDirNames<-1> = field(vParmValue, cSlash, vSlashCnt - 1)
            End Case
         END
      Next iP

      vDirCt = DCount(aDirList, @AM)
      aAllScreenOutputs<-1> = "Directory Names ":vDirCt:" rows:":@AM:aDirNames
      aAllScreenOutputs<-1> = "Directory List  ":vDirCt:" rows:":@AM:aDirList
      aAllScreenOutputs<-1> = "________________________________________________________"

      If vJobName = "" Then
         aAllScreenOutputs<-1> = "NO JobName  Passed - Required ArchiveFiles Routine parameter"
         vError = @TRUE
      End
      If vThisBatchArchive_dir = "" Then
         aAllScreenOutputs<-1> = "NO Archive directory  Passed - Required ArchiveFiles Routine parameter"
         vError = @TRUE
      End
      If vDirCt < 1 Then
         aAllScreenOutputs<-1> = "NO source/target/work directories found in Parameter List"
         vError = @TRUE
      End

      If vError Then
         aAllScreenOutputs<-1> = "***NO files have been Archived***"
         Call DSLogWarn(vMsgInfo:"ERROR - results:":@AM:aAllScreenOutputs, vMsgInfo:"ERROR")
         Ans = 1
      End Else
         aCmd = ""
         aCmd<-1> = MKDIRcmd:vThisBatchArchive_dir
         aAllScreenOutputs<-1> = "***Archive Log***"
         For iD = 1 to vDirCt
            If vOutputFile <> "" Then
               vSUBfile = vOutputFile
               GOSUB SUBarchive
            End
            If vJobName <> "" Then
               vSUBfile = vJobName
               GOSUB SUBarchive
            End
         Next iD

         Call DSLogInfo(vMsgInfo:"NORMAL - results:":@AM:aAllScreenOutputs, vMsgInfo)
         Ans = 0
      End

      RETURN(Ans)

SUBarchive:
      vCmd = LScmd:aDirList<iD>:vSUBfile:"*"
      Call DSExecute(vSystemType, vCmd, pScreenOutput, pSystemReturnCode)
      If vSystemType = "NT" Then
         vCheckNoFiles = left(trim(pScreenOutput), 14)
      End Else
         vCheckNoFiles = trim(field(pScreenOutput,": ", 2))
         vCheckNoFiles = trim(field(vCheckNoFiles,@AM, 1))
      End
*            Call DSLogInfo(vMsgInfo:"DEBUG - :":@AM:vCmd:@AM:pScreenOutput:@AM:"<":vCheckNoFiles:">", vMsgInfo)

      If vCheckNoFiles = "No such file or directory" OR vCheckNoFiles = "File Not Found" Then
*         aAllScreenOutputs<-1> = pScreenOutput
*         aAllScreenOutputs<-1> = "--------------------"
*                  * skip it
      End Else
         aCmd<-1> = MKDIRcmd:vThisBatchArchive_dir:aDirNames<iD>
         aCmd<-1> = MOVEcmd:aDirList<iD>:vSUBfile:"* ":vThisBatchArchive_dir:aDirNames<iD>
         aCmd<-1> = ZIPcmd:vThisBatchArchive_dir:aDirNames<iD>:cSlash:vSUBfile:"* "
         vCmdCnt = DCOUNT(aCmd, @AM)
         FOR iC = 1 TO vCmdCnt
            vCmd = aCmd<iC>
            Call DSExecute(vSystemType, vCmd, pScreenOutput, pSystemReturnCode)
            If pScreenOutput = "" Then pScreenOutput = "OK"
            aAllScreenOutputs<-1> = vCmd
            aAllScreenOutputs<-1> = pScreenOutput
            aAllScreenOutputs<-1> = "--------------------"
         NEXT iC
         aCmd = ""
      End
Last edited by kunj201 on Tue Aug 01, 2006 8:52 am, edited 1 time in total.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Could you please edit your post and put code tags around the logic so I can read it? :cry:
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kunj201
Participant
Posts: 15
Joined: Tue May 03, 2005 8:02 pm

Post by kunj201 »

kcbland wrote:Could you please edit your post and put code tags around the logic so I can read it? :cry: ...
Sorry about that...I edited it..pls reply. thanks again :)
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

kunj201, are you asking what this program does?
kunj201
Participant
Posts: 15
Joined: Tue May 03, 2005 8:02 pm

Post by kunj201 »

ArndW wrote:kunj201, are you asking what this program does? ...
well...yes. Also, the major concern is over the 1at arg of pParameterList...what is the format of it, what info it should be included, where to store and what it does

Thanks,
Nikunj
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

It appears to be a dynamic array of directory path parameter names and their associated values. Your function appears to gather a list of tokens like this:

Load_dir=/here/load
Work_dir=/here/work
Temp_dir=/here/temp
etc.

and copy the contents to an archive directory that the function creates.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Post Reply