Problem while using Fmt function

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
sumesh.abraham
Participant
Posts: 153
Joined: Thu May 11, 2006 1:52 am
Location: Bangalore

Problem while using Fmt function

Post by sumesh.abraham »

Hi All,

I'm reading a record from a sequential file which has a numeric value.
For eg: If the input is a negative number as -123456, the output should be -00000123456.00000(11 digits after '-' sign and five digits after decimal point).
If the input is a positive number as 123456, the output should be
000000123456.00000 (12 digits before decimal point nd five digits after decimal point).

I tried Fmt function, but i'm confused how to padd zeros to left and right side simultaneously. In the transformer i've declared the Length as 18, scale as 5 and Display as 18.
The derivation is

Code: Select all

If IsNull(DSLink3.Field001) Then 000000000000.00000 Else If Substrings(DSLink3.Field001,1,1)="-" Then  "-":Fmt(Substrings(DSLink3.Field001,2,10),"12'0'L") Else ""
Is it possible to use 'L' and 'R' together in Fmt function.

Thanks in advance,
Sumesh
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Sumesh,

You don't need to use the L and R functions, or even any string formatting options at all, you can use FMT(DSLink3.Field001,'18"0"R5')
sumesh.abraham
Participant
Posts: 153
Joined: Thu May 11, 2006 1:52 am
Location: Bangalore

Post by sumesh.abraham »

Thanks.

But, when i use the following inputs output is not correct.

Code: Select all

Input: -1234. Output :0000000-1234.00000
Similiarly  1234:1234.00000
Why the negative sign is coming after zeros?
For positive number the output is not correct.

Code: Select all

-12345678901234:0-12345678901234.0
For long input the output is not proper.
The expression which i used is as follows.

Code: Select all

If IsNull(DSLink3.Field001) Then 000000000000.00000 Else If Substrings(DSLink3.Field001,1,1)="-" Then  Fmt(DSLink3.Field001,'18"0"R5') Else  

Fmt(DSLink3.Field001,'18"0"R5') 
Thanks a lot,
Sumesh
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Try this

Code: Select all

If IsNull(DSLink3.Field001) Then 000000000000.00000 Else If Substrings(DSLink3.Field001,1,1)="-" Then  "-": FMT(DSLink3.Field001[2,Len(input.key1)-1],'18"0"R5') Else Fmt(DSLink3.Field001,'18"0"R5')
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
garthmac
Charter Member
Charter Member
Posts: 55
Joined: Tue Oct 21, 2003 9:17 am
Location: UK

Post by garthmac »

Add in an extra little part (Iconv(DSLink3.Field001,"MCN"):

Ans = If DSLink3.Field001[1,1]="-" Then "-":Fmt(Iconv(DSLink3.Field001,"MCN"),'18"0"R5') Else Fmt(DSLink3.Field001,'18"0"R5')
Garth
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You probably have a PRECISION of 14 set, so using FMT and a number with more digits is not going to work correctly.

Try

Code: Select all

IF DSLink3.Field001<0 THEN -':FMT(ABS(DSLink3.Field001),'11"0"R'):'.00000' ELSE FMT(DSLink3.Field001,'12"0"R'):'.00000'
Note I used the ABS() function in case the sign is trailing in the input.
Post Reply