Convert String to Decimal in subroutine
Moderators: chulett, rschirm, roy
Convert String to Decimal in subroutine
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
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
Sri
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...
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...
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Search the forums for how to accomplish this.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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
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
Sri
pass the value you want to add as a parameter to the command
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.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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.