Page 1 of 1

Convert String to Decimal in subroutine

Posted: Fri Apr 10, 2009 12:45 am
by srilaxmi
Hi,

I have a After job subroutine which calls a UNIX script using DSExecute function and the script returns a decimal value.

I want to add this output value to another variable.
The problem is iam unable to add them, as the value in Ouput value type is nonnumeric and this can't be added to numeric value.

The process is explained below:

Call DSExecute("UNIX",commd, Output,SystemReturnCode)
Here commd = "script_name params"

Upon execution this script returns a decimal value(say -20.625), in "Output" variable which is the return value from the script.

Now i want to add this Output value to another variable.
b=19.99
Ex: result=Output+b

The result iam getting is 19.99 and its giving a warning as below:
"Program "DSU.rtrejectamount": Line 15, Nonnumeric data when numeric required. Zero used. "

Please let me know how to convert this Output variable into Numeric data.


Thanks,
Sri

Posted: Fri Apr 10, 2009 7:28 am
by chulett
Server BASIC routines are not "strongly typed" so not typically an issue as everything is handled as a string under the covers. Post your routine code so we can see what all is going on in there, especially around Line 15.

I'm also curious what you're going to do with this computed value? You've got nowhere to put it "after job" except land it somewhere and if you try to return this value from the routine, the job will interpret that as a failure of said routine. Just wondering...

Posted: Fri Apr 10, 2009 10:09 am
by ray.wurlod
The UNIX command output has a line terminator, which will have been converted to a field mark. You need to trim this from the result before proceeding to use the result in an arithmetic expression.

Search the forums for how to accomplish this.

Posted: Fri Apr 10, 2009 11:15 am
by chulett
Ah... duh, should have caught that. That or reference only the first element of the Output dynamic array in your expression.

Posted: Wed Apr 15, 2009 12:00 am
by srilaxmi
Hi,

1
2
3
4 Filename="test.dat"
5 Jobname="testjob"
6 scriptsdir="/usr/testdir"
7 scriptname="amt.ksh"
8 commd="ksh":" ":scriptsdir:"/":scriptname:" ":Filename:" ":Jobname:" ":"outputfile.dat"
9 Call DSExecute("UNIX",commd, Output,SystemReturnCode)
10
11 b=10
12
13
14
15 Ans=Trim(Output) + b



This is the code im using to test using server routine(Transform Function).
The output im getting is 10. but it should be 106158.512(Output value) + 10(b value).

Here i have tried with "Trim" function, still getting the same warning
"Program "DSU.rtrejectamount": Line 15, Nonnumeric data when numeric required. Zero used."

Chulett, i write this computed value to a file.

Thanks,
Sri

pass the value you want to add as a parameter to the command

Posted: Wed Apr 15, 2009 12:34 am
by changming
srilaxmi wrote:Hi,

1
2
3
4 Filename="test.dat"
5 Jobname="testjob"
6 scriptsdir="/usr/testdir"
7 scriptname="amt.ksh"
8 commd="ksh":" ":scriptsdir:"/":scriptname:" ":Filename:" ":Jobname:" ":"outputfile.dat"
9 Call DSExecute("UNIX",commd, Output,SystemReturnCode)
10
11 b=10
12
13
14
15 Ans=Trim(Output) + b



This is the code im using to test using server routine(Transform Function).
The output im getting is 10. but it should be 106158.512(Output value) + 10(b value).

Here i have tried with "Trim" function, still getting the same warning
"Program "DSU.rtrejectamount": Line 15, Nonnumeric data when numeric required. Zero used."

Chulett, i write this computed value to a file.

Thanks,
Sri
I don't know why the command return a txt value. but can you change your command, say that command can accept a number parameter and then calculate inside the command. If that work, you don't need to worry the return data type. Please let me know whether this works.

Posted: Wed Apr 15, 2009 1:43 am
by ray.wurlod
You have to trim @FM rather than white space.

Posted: Wed Apr 15, 2009 4:03 am
by srilaxmi
changming, I think way will work. I will try that out.

ray, I did't get what trim @FM means, please explain.

Posted: Wed Apr 15, 2009 1:35 pm
by ray.wurlod
You need to specify, in the Trim() function, that you want to remove @FM characters (the default is to remove white space characters). The full form of the Trim() function has three arguments. You can get away with only two.

Code: Select all

Trim(ActivityName.$CommandOutput,@FM)