Varchar to Decimal issue

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
challard1
Participant
Posts: 22
Joined: Sat May 14, 2016 10:38 am

Varchar to Decimal issue

Post by challard1 »

I have a file with a varchar numeric field containing a maximum of 6 caracters (for example 3.45 or 23.45 or 234.56). I need to load this field in a DB2 table where the field is defined (decimal 5,2).

I have tried many possibilities using stringtodecimal function with no success mainly due to the decimal point in the source field I believe.

What is the easiest way to succeed ?

Thanks in advance for your help.
Cyrille Hallard
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Please show us the exact syntax you are using and the error / issue you are seeing.
-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 »

Use a format string with the function, to describe the format of the string (including, presumably, the European decimal placeholder).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
challard1
Participant
Posts: 22
Joined: Sat May 14, 2016 10:38 am

Post by challard1 »

Here is the exact syntax:

Input variable ADHPCT
Defined Varchar 6
Value : 98.27

Stage variable svAdhpct
Defined Decimal 5,2

Transformation variable svAdhpct
StringToDecimal(link.ADHPCT)

Output variable ADHPCT
Defined Decimal 5,2
Result in DB2 table : 0.00
Cyrille Hallard
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As Ray noted, use a format string in your function call.
-craig

"You can never have too many knives" -- Logan Nine Fingers
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

Blunt object through window approach: Stage variable svADHchar Char(6) -- StringToString (ADHPCT) (set PADCHAR to 0x20); svAdhpct -- StringToDecimal (Trim(svADHchar)).

Have I mentioned yet today that putting numeric values in VarChar fields is a royal pain in the arse? :roll:
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
challard1
Participant
Posts: 22
Joined: Sat May 14, 2016 10:38 am

Post by challard1 »

Thanks Craig and Franklin.
I have tried Franklin advice ... with no success for now.
Got same results. Will investigate further.
Cyrille Hallard
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

Just remembered that you indicated the output value as 0.00. Sometimes this is from a type conversion failure that you might miss because it's a warning level log entry.

Try increasing the size of the decimal ADHPCT to 6,2 or more. Stage variables are usually defaulted to signed, and that might be why the conversion is defaulting to zero.

Also, insert a peak. What you see on DB2 may not be what you see in the buffer.
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
challard1
Participant
Posts: 22
Joined: Sat May 14, 2016 10:38 am

Post by challard1 »

Finally resolved the issue. The problem was the input file. It was a DOS format file, so the last field of the record ADHPCT was not map properly. After adding the Record delimiter field = DOS format, problem was fixed.
Thanks everyone for your help on this topic.
Cyrille Hallard
Post Reply