Page 1 of 1

numeric and char series generators

Posted: Wed Jul 16, 2003 11:36 am
by dsproj2003
Hi,

For a given input file, I need to append a generated (alphanumeric) series in a new column (and direct that to output file).

The series should look like AA0001, AA0002....., AA9999, AB0001, AB0002,............, AB9999, ......ZZ0001,....,ZZ9999

Could you suggest me some in-built function which I could use here?

What should be the simplest way of achieving this?
Its very urgent.

Thanks.

Regards,
Nitin

Posted: Wed Jul 16, 2003 11:43 am
by tonystark622
Nitin,

I don't know of an easy way to do this. The best way might be to copy and modify the KeyMgtGetNextValue routine to handle your particular algorithm.

Good Luck!

Tony

Posted: Wed Jul 16, 2003 12:59 pm
by kcbland
You can write a very simply DataStage function that does this. What you need to do is clarify your functional requirements:

What is the starting value? Does it always start with AA0000? Do you want to pass in a seed value? Do you need to continue where a previous job run left off? Does a given sequence correlate to any given conditions? How do you handle topping off at ZZ9999, do you roll over or start with AAA0000?

This is a simple function, you just have to be specific. You will write a function that does the simple algebra to increment your counter. What you have to decide is if you're starting with a seed value, referencing a seed value, correlating to a given condition, etc. Then, you will either use a stage variable or a COMMON statement in the function to "remember" your value from row to row.

Let us know, we'll help out.


Kenneth Bland

Posted: Wed Jul 16, 2003 12:59 pm
by kduke
Nitin

You using the UNIX split command? You could use options on the split command to make this easier.

Create a routine: (this should be close enough)

GetNextId(Arg1)

LastKey = Arg1

if LastKey = then
Ans = "AA0001"
end else
KeyXX = LastKey[1,2]
KeyNum = LastKey[3,4]
if KeyNum = "9999" then
KeyNum = "0001"
KeyX = KeyXX[2,1]
if KeyX = "Z" then
KeyX = "A"
Key1 = char(seq(KeyXX[1,1])+1)
KeyXX = Key1 : KeyX
end else
KeyX = char(seq(KeyX)+1)
Key1 = KeyXX[1,1]
KeyXX = Key1 : KeyX
end
end else
KeyNum += 1
KeyNum = fmt(KeyNum, "40R")
end
Ans = KeyXX : KeyNum
end

return(Ans)


Kim.

Posted: Wed Jul 16, 2003 6:35 pm
by ray.wurlod
My usual observation.
That kind of code only works with ASCII alphabetic characters.
It may need modification to work with alphabetic characters in other character sets (for example Greek, Russian and so on) in the NLS world.

Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518

Posted: Fri Jul 18, 2003 2:58 pm
by dsproj2003
Thanks a lot to all of you for those inputs.

Regards,
Nitin