Convert String to Decimal in subroutine

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
srilaxmi
Participant
Posts: 22
Joined: Thu Feb 28, 2008 5:21 am

Convert String to Decimal in subroutine

Post 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
Sri
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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...
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ah... duh, should have caught that. That or reference only the first element of the Output dynamic array in your expression.
-craig

"You can never have too many knives" -- Logan Nine Fingers
srilaxmi
Participant
Posts: 22
Joined: Thu Feb 28, 2008 5:21 am

Post 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
Sri
changming
Participant
Posts: 68
Joined: Wed Oct 13, 2004 3:35 am

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

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You have to trim @FM rather than white space.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
srilaxmi
Participant
Posts: 22
Joined: Thu Feb 28, 2008 5:21 am

Post by srilaxmi »

changming, I think way will work. I will try that out.

ray, I did't get what trim @FM means, please explain.
Sri
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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)
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