Page 1 of 1

Routine help needed

Posted: Wed Sep 03, 2008 8:55 pm
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

Posted: Wed Sep 03, 2008 9:46 pm
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.

Posted: Thu Sep 04, 2008 2:05 am
by Novak
Thanks a lot Ray, it worked!

Regards,

Novak

Posted: Thu Sep 04, 2008 2:44 am
by ray.wurlod
Please mark the thread as Resolved, using the green button at the top.