StringToDecimal - behavior with direct Arith ops

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
Kirtikumar
Participant
Posts: 437
Joined: Fri Oct 15, 2004 6:13 am
Location: Pune, India

StringToDecimal - behavior with direct Arith ops

Post by Kirtikumar »

Hi,

I am trying following:
I am getting a column TRAN_AMT. This amount am reading as string from file.
The amount is spaces sometimes which indicates it is 0.

Now I have to generate three columns AmtPls8(as TRAN_AMT + 8) and AmtMult8 (as TRAN_AMT * 8).

If while deriving above columns, I directly use the derivations as:

Code: Select all

AmtPls8 = StringToDecimal(TRAN_AMT) + 8
AmtMult8 = StringToDecimal(TRAN_AMT) * 8
With input as spaces, I am getting the output for the cols as 000123456754.12 and 000987653968.99 respectively whereas actual output should be 8 and 0.

Now I tried a bit diff approach to it. I added one stage variable AmtSVar and code is changed as follows:

Code: Select all

Stage variable:
       AmtSVar = StringToDecimal(TRAN_AMT)
Cols Derivation:
       AmtPls8 = AmtSVar + 8
       AmtMult8 = StringToDecimal(TRAN_AMT) * 8
After this the result was 000000000008.00 and 000000000064.00 respectively meaning for first col the result is OK and during the second calc it again behaves strangely.

Then I change the cols to have derivations as:

Code: Select all

AmtPls8 = AmtSVar + 8
AmtMult8 = AmtSVar * 8
After this am getting proper results.

One more thing if the incoming column value is proper number and not spaces, then everything works fine and no need for the stage variable. But if it spaces, then it needs stage var to make the logic work proper.
Regards,
S. Kirtikumar.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Handle the null explicitly within the expression. Use

Code: Select all

NullToValue(TRAN_AMT,0)
(there may even be a NullToZero function; I'm working from memory here).
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 »

There is one in Server, wouldn't be surprised if the equivalent exists in PX.
-craig

"You can never have too many knives" -- Logan Nine Fingers
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Ray is correct there is NullToZero function in PX.

Krithik you need to use the Trim function to remove the space and then apply NullToZero this should work.
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
Post Reply