Routine help needed

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
Novak
Participant
Posts: 97
Joined: Mon May 21, 2007 10:08 pm
Location: Australia

Routine help needed

Post by Novak »

Hi,

I am far from good in writing routines and was hopeful somebody could tell me why is it that the I get my file twice written to?

2 arguments passed to a routine are: InputArg and ErrorCode

InputArg = "echo 'test line' >> target file"

The routine's code is as follows:

___________________________________________________________
Deffun DSRMessage(A1, A2, A3) Calling "*DataStage*DSR_MESSAGE"
Equate RoutineName To "ExecDOS"

* If InputArg is empty, log a Warning-type message and return
If Trim(InputArg) = "" Then
Message = DSRMessage("DSTAGE_TRX_E_0011", "No command to execute.", "")
GoTo ErrorExit
End

vCmd = InputArg
GoSub RunNTCmd


* Sub routine
*==============================================
RunNTCmd:
vMessage = "RunNTCmd: " : vCmd
*Call DSLogInfo(vMessage, "JobControl")

Call DSExecute("NT", vCmd, vOut, vRet)
vMessage = "NT Cmd = " : vCmd : @FM : "Return Code = " : vRet : @FM : "Output = " : vOut

If vRet = 0 then
vMessage = "NT Command Successful ":@FM:vMessage
*Call DSLogInfo(vMessage,"JobControl")
End Else
vMessage = "NT Command Failed " : Dquote(vRet) : @FM : vMessage
*Call DSLogWarn(vMessage, "JobControl")
End

* Exit with no error.
ErrorCode = 0
GoTo NormalExit

* Exit with error, logging warning message first.
ErrorExit:
Call DSLogWarn(Message, RoutineName)
ErrorCode = 1

NormalExit:


After I run this my file will contain :

test line
test line




Regards,

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

Post by ray.wurlod »

After GoSub RunNTCmd there is nothing to prevent your code falling through the RunNTCmd code again.

You need to branch away. Perhaps a GoTo NormalExit or RETURN immediately following the GoSub statement.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Novak
Participant
Posts: 97
Joined: Mon May 21, 2007 10:08 pm
Location: Australia

Post by Novak »

Thanks a lot Ray, it worked!

Regards,

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

Post by ray.wurlod »

Please mark the thread as Resolved, using the green button at the top.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply