Hex to decimal and Ascii conversion in Server jobs

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
sandeepJajee
Participant
Posts: 12
Joined: Sat Jun 27, 2009 5:44 am

Hex to decimal and Ascii conversion in Server jobs

Post by sandeepJajee »

Hi,
I have got 1 requirment to convert the hexadecimal value from input file to Ascii and Decimal using Server jobs?

Ex:Say for column di=21 47 37 63 is hex value to be coverted
into Decimal and ascii.
Datatype for input column is number.

output:
Asci value: !G7c
Decimal value : 33715599

I need to do this in server Jobs.so if anyone knows then please share your thoughts.?

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

Post by ArndW »

For the moment, let us not use "hex" conversion, but ask what datatype you are converting from. Is is a COBOL type COMP-3 field? If so, there are builtin conversions in the SDK or the CFF stage available to you.
sandeepJajee
Participant
Posts: 12
Joined: Sat Jun 27, 2009 5:44 am

Post by sandeepJajee »

Hi,

Its not a cobol type 3 field.
Input is coming from Datastage Tx.we can incorporate this conversion at Tx level itself but there are lot of columns to be applied so each column there will be three fields di_hex,di_dec_di,asc .so we wwant to restrict these column.

So we want to incorporate this logic at datastage level an there are some transformation to be applied and load in to target database.
Regards,
Sandeep Jajee
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why do you say you need to convert them to "decimal and ascii" and state that would mean "three fields" if you did it at the source? What would be in this "ascii" field? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Is it a pure binary format? Try reading it as "binary" into an integer.
tjr
Participant
Posts: 19
Joined: Wed Jun 15, 2005 6:37 am

Post by tjr »

ArndW wrote:Is it a pure binary format? Try reading it as "binary" into an integer. ...
Hey Arnd, it looks like you are very busy in Frankfurt :lol:
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Naah, I'm just doing long multiple job compiles and surf DSXchange while they run:)
sandeepJajee
Participant
Posts: 12
Joined: Sat Jun 27, 2009 5:44 am

Post by sandeepJajee »

Hi,

Its not a Pure Binary format.

i would like to tell with 1 example.
Say for column DI and its values which are in Hex Format.
DI
--
31 32 33 34 35 36 37 38
21 47 37 63
31 32 33 34

My requirment
-----------

if length of DI field is<=4 the i have to use Decimal Value
else if Length is >=5 then i have to use Ascii Value.

So for field 31 32 33 34 35 36 37 38 ,length is >=5 then target value should be Ascii equivalent 12345678.

I am trying to write user defined routine.
Regards,
Sandeep Jajee
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You are making it too complex. the hex values you showed "31 32 33 34 35 36 37 38" are simple ASCII representations of the numbers you need, just read the field as ASCII instead of as a binary one.
sandeepJajee
Participant
Posts: 12
Joined: Sat Jun 27, 2009 5:44 am

Post by sandeepJajee »

Hi,

I have got the solution.one of my friend helped me to write this Routine.
Thanks for your Response.

*********************************************************************************************************************************
* Remove the FF value and convert the multiple occurences of space to single space and then convert space to comma delimeter
*********************************************************************************************************************************

VarArg = Ereplace(Trim(Trim(InHexBaseNumber,"FF","A"),' ','R'),' ',',')
TokenCnt = Dcount(VarArg,',')

* Set the flag depending on number of tokens

TokenFlag = 0
If TokenCnt <= 4 Then TokenFlag =1
If TokenCnt >=5 Then TokenFlag =2
Ans = ''

*********************************************************************************************************************************

* If Number of tokens <=4 then convert Hex to Decimal
* If Number of tokens >=5 then covert Hex to Ascii

*********************************************************************************************************************************



If TokenFlag > 0 Then
For vcnttoken = 1 to TokenCnt step 1
var = Field(VarArg,',',vcnttoken)
Begin Case
Case TokenFlag =1
Ans= Ans:Iconv(var,'MX')
Case TokenFlag =2
Ans= Ans:Iconv(var,'MX0C')
End Case
Next
End

*********************************************************************************************************************************
Regards,
Sandeep Jajee
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Moderator: please move to Server forum
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply