Can we extract the decimal part alone using Iconv/Oconv

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
kruthika
Participant
Posts: 21
Joined: Mon May 31, 2004 11:14 pm

Can we extract the decimal part alone using Iconv/Oconv

Post by kruthika »

Can we extract the decimal part alone using Iconv/Oconv.

I arrived at the solution by using the following code.
Substrings("3435.676",Index("3435.676",'.',1)+1,Len("3435.676"))
But it seems to be a round about.

Can we achieve the same using Iconv or Oconv....

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

Post by ArndW »

Hello Kruthika,

although ICONV and OCONV are quite efficient functions, they are a bit too powerful for your specific request and will not be the most efficient. The INDEX function as you have used it is fast, you could also use the FIELD function if your number is in the format "nnnnn.dddd", i.e. FIELD(In.mynumber,'.',2) for that portion after the decimal.

You can also use the INT() function to strip off decimal portions or if you really wish to stick with ICONV/OCONV look at the MD conversion code description in the Basic User's Guide pages 819 onwards.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Re: Can we extract the decimal part alone using Iconv/Oconv

Post by ArndW »

kruthika wrote:Can we extract the decimal part alone using Iconv/Oconv.

I arrived at the solution by using the following code.
Substrings("3435.676",Index("3435.676",'.',1)+1,Len("3435.676"))
But it seems to be a round about.

Can we achieve the same using Iconv or Oconv....

Thanks
Sorry, I forgot to suggest a modification of what you did that would perform somewhat better:

In.MyNumberColumn[INDEX(In.MyNumberColumn,'.',1)+1,999]

The "999" is meant to be longer than the rest of the string, DS will stop parsing at the end of the string. This saves your LEN() call [which, if you wanted to be correct, needs to be decremented by your start position; but because DS does stop at the end of the string will work nonetheless :))
kruthika
Participant
Posts: 21
Joined: Mon May 31, 2004 11:14 pm

Post by kruthika »

Thanks Arnd...

Field function itself suits my need.
Kruthika
Post Reply