Page 1 of 1

Hex to decimal and Ascii conversion in Server jobs

Posted: Mon Aug 03, 2009 5:03 am
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

Posted: Mon Aug 03, 2009 5:38 am
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.

Posted: Mon Aug 03, 2009 6:15 am
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.

Posted: Mon Aug 03, 2009 6:43 am
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? :?

Posted: Mon Aug 03, 2009 6:53 am
by ArndW
Is it a pure binary format? Try reading it as "binary" into an integer.

Posted: Mon Aug 03, 2009 7:05 am
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:

Posted: Mon Aug 03, 2009 7:10 am
by ArndW
Naah, I'm just doing long multiple job compiles and surf DSXchange while they run:)

Posted: Mon Aug 03, 2009 7:20 am
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.

Posted: Mon Aug 03, 2009 7:33 am
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.

Posted: Mon Aug 03, 2009 7:49 am
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

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

Posted: Mon Aug 03, 2009 5:05 pm
by ray.wurlod
Moderator: please move to Server forum