Hex to integer in transfrmer stage

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
dsxuserrio
Participant
Posts: 82
Joined: Thu Dec 02, 2004 10:27 pm
Location: INDIA

Hex to integer in transfrmer stage

Post by dsxuserrio »

Hello
I have a varchar which has three hexnumbers as input to transformer. I extract each hex number and use them as 3 output fields.

Input : 0000FE00230064


0000FE 0023 0064
fld 1 fld 2 fld 3

Result I need
254 35 100



How can I convert the individual fields to integer values in the transformer??

Thanks for your time and input
dsxuserrio

Kannan.N
Bangalore,INDIA
Rboudr2035
Participant
Posts: 2
Joined: Wed Jun 09, 2004 7:09 am

Post by Rboudr2035 »

Give this a try: ICONV(input[1,6],'MX'):' ':ICONV(input[7,4],'MX'):' ':ICONV(input[11,4],'MX')
chalasaniamith
Participant
Posts: 36
Joined: Wed Feb 16, 2005 5:20 pm
Location: IL

Re: Hex to integer in transfrmer stage

Post by chalasaniamith »

this is Radix conversion
MX - converting hexadecimal to decimal

First # : ICONV(input[1,6],'MX')
Second #: ICONV(input[7,4],'MX')
Third #: ICONV(input[11,4],'MX')

use concatenation for all these
ICONV(input[1,6],'MX'):' ':ICONV(input[7,4],'MX'):' ':ICONV(input[11,4],'MX')
dsxuserrio
Participant
Posts: 82
Joined: Thu Dec 02, 2004 10:27 pm
Location: INDIA

Post by dsxuserrio »

Hi
I tried that. I am getting the following error message

Link DSLink18, Column DEVICE_CODE: ICONV(DSLink15.DEVICE_CODE,'MX")
Variable 'ICONV' not defined

I am using this in the transformer stage.

Thanks
dsxuserrio

Kannan.N
Bangalore,INDIA
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

dsxuserrio,

unfortunately the ICONV and OCONV functions only exist in the Server Transform stage :cry: , which is why you are getting this error.

You have a couple of choices in solving this. Easiest in terms of getting up and running is to use a BASIC transform stage in Px. The downside is that you are losing a lot of performance (which is why you are using Px in the first place, right?). But with that stage the ICONV and OCONV functions will work. Your second option is to code a small C program that does this cast() for you; then you can bind it into Px and call it from a transform stage. This is relatively easy and quick to do and will also perform faster in Px than the first solution.
T42
Participant
Posts: 499
Joined: Thu Nov 11, 2004 6:45 pm

Post by T42 »

That was a VERY fun challenge. I love questions like this -- as it help me expand my knowledge of EE.

Here is the answer:

"0x" : [input field].

Yup, you have to append 0x before your number in order for DataStage to recognize it as a Hex number. It will automatically be converted if the output field is defined as an Integer.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Is that actually documented anywhere?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
T42
Participant
Posts: 499
Joined: Thu Nov 11, 2004 6:45 pm

Post by T42 »

Nope. But I was reading the Orchestrate document (6.x -- can't find my 7.x copy. :oops: ), did a search for "hex", and noticed that some places goes: Integer = "0000", hexadecimal = "0x000"... blah blah.

So I thought, "Hmm, maybe...", and did the above mentioned solution. Worked. :o

That was fun. :D
dsxuserrio
Participant
Posts: 82
Joined: Thu Dec 02, 2004 10:27 pm
Location: INDIA

Post by dsxuserrio »

T42
Thanks for your suggestion. I tried what you suggested in DS 7.5. It did not work for me.
I prefixed my hex data with 0x.

The data was something like 0x00CF. It had a type varchar.

I tried Integer as output. Also I tried AsInteger function. Both did not work.
dsxuserrio

Kannan.N
Bangalore,INDIA
T42
Participant
Posts: 499
Joined: Thu Nov 11, 2004 6:45 pm

Post by T42 »

Unfortunately, I am not able to test my solution on 7.5. I did test it on 7.1r2, and it worked.

I did not do anything special (AsInteger() or anything like that) -- just plain straight varchar to integer conversion, doing the conversion with the values you provided. It produced the expected results.

Anyone else here with EE 7.5?
banactp
Participant
Posts: 52
Joined: Tue Feb 22, 2005 2:55 pm

Post by banactp »

The String to Integer conversion does not seem to work in 7.5:

Numeric string expected for input column

is the error message received from the transform. The problem seems to be with the '0x' prefix - I can't even get AsInteger("0x00ab") to work.
Post Reply