FDMEE Import Script Function round(float(strField),0) Returns Incorrect Value

1. The import script below (which is intended to round amounts to 0 decimal places) is being used in an import format for a file based load and is not correctly rounding amounts with more than 12 digits before the decimal place:

def rounding(strField,strRecord):
return strField
2. To give a specific example, if you had the amount 2416602525799.16 in your source file and it was processed by the import script above it would be rounded to 2416602525800 rather than to 2416602525799 as would be expected if you are seeing this issue.

3. The same figures can be rounded without any problems at all when trying the same process in an interactive Jython session (which can often be a useful debugging tool with simple Jython scripts). You can start an interactive Jython session to try this by running:

java -jar C:\Oracle\Middleware\odi\oracledi.sdk\lib\jython.jar
Then create the same function contained in your import script before calling it with a test value:

>>> def rounding(strField,strRecord):
… strField=round(float(strField),0)
… return strField

>>> rounding(2416602525799.16, ‘randomStuff’)

this is due to Precision is being lost when converting the Jython float data type into a Java data type before inserting into the TDATASEG table.

to fix this –

1. Create an import script named rounding as below (please note that the function name must be the same as the script name) which uses the Java BigDecimal data type:

import java.math.BigDecimal as BigDecimal
def rounding(strField,strRecord):
strField = BigDecimal(strField).setScale(0,BigDecimal.ROUND_HALF_UP)
return strField
2. Update the file based import format to use this script on the amount column where the rounding is being done.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s