Converting Numbers to Alphabates

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
bapajju
Participant
Posts: 82
Joined: Wed Nov 19, 2003 11:58 pm

Converting Numbers to Alphabates

Post by bapajju »

Hello,

I have an input string that can have length of 2 or 4 or 6. The values for this stri will look like:

01
1201
120616

we need to convert these values to corresponding Alphabates. So the above string needs to get converted to:
A
LA
LFP

Could anyone please help me in this. How can we achieve this.

Thanks in advance
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hi bapajju,

You can use 'If then Elseif then Else' block. Use it in the derivation of the ouput field you are mapping to.

For example;

Code: Select all


If DSLink.String = '01' Then 'A' Else If DSLink.String = '1201' Then 'LA' Else If DSLink.String = '120616'  Then 'LFP' Else DSLink.String
Naveen.
bapajju
Participant
Posts: 82
Joined: Wed Nov 19, 2003 11:58 pm

Post by bapajju »

Thanks Naveen. Appreciate your suggestion. This is not just limited to these numbers. We need to conver 01 to 26 to all corresponding Alphabates. But trick is the field length can be 2 or 4 or 6.

Thanks
naveendronavalli wrote:Hi bapajju,

You can use 'If then Elseif then Else' block. Use it in the derivation of the ouput field you are mapping to.

For example;

Code: Select all


If DSLink.String = '01' Then 'A' Else If DSLink.String = '1201' Then 'LA' Else If DSLink.String = '120616'  Then 'LFP' Else DSLink.String
Naveen.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

bapaju,

if you always have 2 digit codes and the numbers you have represent the position in the alphabet then you can use the CHAR(64+{number}) to get the appropriate letter. Since you said your string could be 2, 4 or 6 then the one-line derivation could be:

Code: Select all

IF LEN(In.String=2) THEN CHAR(64+In.String[1,2]) ELSE IF LEN(In.String=4) THEN CHAR(64+In.String[1,2]):CHAR(64+In.String[3,2]) ELSE IF LEN(In.String=6) THEN CHAR(64+In.String[1,2]):CHAR(64+In.String[3,2]):CHAR(64+In.String[5,2]) ELSE 'ERROR'
It would be prettier in a subroutine than in a one-liner.








:IF LEN(In.String)>2 THEN
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Write a custom routine. Build a alphabet string with all letters from A to Z. Loop through the input argument two bytes at a time and build an output string, concatenating on the results of pulling AlphaString[number,1] each time.

Or build an array to pluck letters from and take AlphaArray<number>.

Or there is Arnd's way. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Dynamic array manipulation?

Code: Select all

Convert(@FM,"",Chars(Adds(Fold(TheString,2),REUSE(64)))
Last edited by ray.wurlod on Thu Sep 15, 2005 8:18 pm, edited 2 times in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bapajju
Participant
Posts: 82
Joined: Wed Nov 19, 2003 11:58 pm

Post by bapajju »

Thanks Arnd:). It was great. Itried it and it worked perfect. Thanks again
ArndW wrote:bapaju,

if you always have 2 digit codes and the numbers you have represent the position in the alphabet then you can use the CHAR(64+{number}) to get the appropriate letter. Since you said your string could be 2, 4 or 6 then the one-line derivation could be:

Code: Select all

IF LEN(In.String=2) THEN CHAR(64+In.String[1,2]) ELSE IF LEN(In.String=4) THEN CHAR(64+In.String[1,2]):CHAR(64+In.String[3,2]) ELSE IF LEN(In.String=6) THEN CHAR(64+In.String[1,2]):CHAR(64+In.String[3,2]):CHAR(64+In.String[5,2]) ELSE 'ERROR'
It would be prettier in a subroutine than in a one-liner.








:IF LEN(In.String)>2 THEN
Post Reply