ABS() function

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
kiran reddy
Participant
Posts: 5
Joined: Wed Apr 20, 2005 6:29 pm
Location: USA

ABS() function

Post by kiran reddy »

Hi,

I have a strange experience working with the abs() function.
We have a reqirement that should take the absolute value of an integer and then rounded to two decimals. When ever we are geting some -ve numbers these are converted to +ve numbers using the abs() function, but it is loosing the precision. like for example
abs(31.33) gives 31.33 as output.
abs(-31.333) is giving 31 as output. Then we took a work around to accomplish this, by multiplying numbers less than zero with -1 and then rounding. Does any one know why is it so ?


Thanks.
Thanks,
Kiran Kumar Reddy
elavenil
Premium Member
Premium Member
Posts: 467
Joined: Thu Jan 31, 2002 10:20 pm
Location: Singapore

Post by elavenil »

Can you check the following the environment variables for the project.

1. APT_DECIMAL_INTERM_PRECISION
2. APT_DECIMAL_INTERM_SCALE
3. APT_DECIMAL_INTERM_ROUND_MODE

Hope this would give a clue to understand why the number is rounded to the whole number.

Regards
Saravanan
dsdesigner
Participant
Posts: 34
Joined: Thu Jul 29, 2004 1:03 pm

Post by dsdesigner »

Hi Kiran,
The DataStage documentation specifies that the input argument to the abs function should be of type int32 and return type is a dfloat . But in that case even your +ve number have to be truncated. I tried it with an example and have noticed that the decimal part of my positive numbers are truncated. Are you sure that in your case for +ve numbers the fraction part was not truncated?

Thanks
kiran reddy
Participant
Posts: 5
Joined: Wed Apr 20, 2005 6:29 pm
Location: USA

Post by kiran reddy »

In fact I didn't find any such environment variables in our project. May be something we need to set it up now ! Thanks for your response.

Also we were getting all -ve numbers from source, so I guess we didn't actually take a +ve number and check, but somehow we got into this mis-conception, Thanks for bringing this up.
Thanks,
Kiran Kumar Reddy
benny.lbs
Participant
Posts: 125
Joined: Wed Feb 23, 2005 3:46 am

Post by benny.lbs »

Saravanan,

I also can not find the environment variables in DS Administrator. They are the User defined variables ?

How can you find the information about the APT variables, what 's the possible value ? any doc can be refered ?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There's an appendix in the Advanced Developer's Guide, which ships as part of the standard manual set.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
benny.lbs
Participant
Posts: 125
Joined: Wed Feb 23, 2005 3:46 am

Post by benny.lbs »

Ray,

For "APT_DECIMAL_INTERM_ROUND_MODE", the book said "Specifies the default rounding mode for any decimal intermediate variables required in calculations. The default is round_inf. "

The default is round_inf, but how can I know other possible value ?

Regards,
Benny.lbs
elavenil
Premium Member
Premium Member
Posts: 467
Joined: Thu Jan 31, 2002 10:20 pm
Location: Singapore

Post by elavenil »

These variables can be found in the Environment varibales section in Advanced PX developer's guide.

Possible values are depends on your requirement, which is how many precision and scale that you need in your requirement.

Regards
Saravanan
benny.lbs
Participant
Posts: 125
Joined: Wed Feb 23, 2005 3:46 am

Post by benny.lbs »

I just want to know the possible value of APT_DECIMAL_INTERM_ROUND_MODE, not precision or scale. Since the default value is round_inf, it is hard for me to guess other possible value.

Would anyone can help ? Thanks a lot.
Simona
Participant
Posts: 7
Joined: Mon Jan 24, 2005 2:25 pm

Post by Simona »

Hi dsdesigner,
Since ABS will for sure truncate the decimal, do you know any other alternative(Function?) to do the ABS without truncation except the workaround posted by Kiran??
Thanks!
dsdesigner
Participant
Posts: 34
Joined: Thu Jul 29, 2004 1:03 pm

Post by dsdesigner »

FABS(). I just stumbled upon this funtion that takes a float as input and calculates the absolute values of the number. I tried with an example and it works good for me.

Maybe Kiran can try this.

Thanks,
Shekar
Simona
Participant
Posts: 7
Joined: Mon Jan 24, 2005 2:25 pm

Post by Simona »

Shekar,
Where do I find FABS(), I check the documentation and cannot even find the FABS() in derivaiton editor! Do I have to customize the pallette or do something else to get this?

Thanks for your help!
dsdesigner
Participant
Posts: 34
Joined: Thu Jul 29, 2004 1:03 pm

Post by dsdesigner »

FYI I am using 7.1 version of Datastage
Thanks,
Shekar
Simona
Participant
Posts: 7
Joined: Mon Jan 24, 2005 2:25 pm

Post by Simona »

I found it! Thank you so much! I just look into Basic Transformer a while ago, that's why!
cdp
Premium Member
Premium Member
Posts: 113
Joined: Tue Dec 15, 2009 9:28 pm
Location: New Zealand

Post by cdp »

Fabs !! Thanks for that dsdesigner, had exactly the same issue, and Fabs worked perfectly !
Post Reply