Page 1 of 1

String To Decimal Conversion Error

Posted: Mon Nov 05, 2018 6:33 pm
by Mohan09
Have a Parallel Job to load the source data into a staging table. Source file has all fields comes in Varchar Format and during loading , i'm converting string to decimal for all decimal fields. If we have a numerical value then loading job completed successfully with no warnings. But if any one of the decimal field has blanks or nulls than i'm getting warning message "Conversion error calling conversion routine decimal_from_string data may have been lost".

For (e.g), my source file has the below columns
ID,INT_RATE,INT_AMT,INT_PEND

Source Datatype
ID - VARCHAR(3),INT_RATE-VARCHAR(7),INT_AMT-VARCHAR(7),INT_PEND-VARCHAR(7)

Values are:
100|10.1|12.2|25.5
101|22.2|55.67|33.78
102||||

Target Datatype
ID - VARCHAR(3),INT_RATE-DECIMAL(5,2),INT_AMT-DECIMAL(5,2),INT_PEND-DECIMAL(5,2)

In order to avoid the warning, have coded like below:
if (INT_RATE = ' ' OR IsNUll(INT_RATE) =1) then Stringtodecimal(0) Else
Stringtodecimal(INT_RATE).

Even after added this condition, i'm getting the warnings. Can someone help me to get rid of this warnings. Thanks..

Posted: Tue Nov 06, 2018 6:12 am
by chulett
Well... perhaps it's as simple as this:

Code: Select all

if (INT_RATE = ' ' OR IsNUll(INT_RATE) =1) then Stringtodecimal("0") Else 
Stringtodecimal(INT_RATE)

Posted: Tue Nov 06, 2018 12:28 pm
by FranklinE
Your input columns are all VarChar(7), your output column is Decimal(5,2). You have two fewer bytes on output, and unless you either trim the string to 5 bytes or increase the decimal to 7,2 you will continue to have the warning.

Posted: Tue Nov 06, 2018 4:25 pm
by chulett
You make a valid point but they stated it was only happening when if "any one of the decimal field has blanks or nulls" so guessing that assertion may not, in fact, be true.

Posted: Mon Nov 19, 2018 1:13 am
by ray.wurlod
This from memory (away from DataStage at the moment). Isn't the default that decimal data type is not allowed to have zero value, but there is a flag in the conversion routines that permits zero-valued zeroes? I think the flag argument is fix_zero.