numeric and char series generators

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
dsproj2003
Participant
Posts: 21
Joined: Wed Oct 01, 2003 11:53 am

numeric and char series generators

Post 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
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post 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
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post 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
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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
dsproj2003
Participant
Posts: 21
Joined: Wed Oct 01, 2003 11:53 am

Post by dsproj2003 »

Thanks a lot to all of you for those inputs.

Regards,
Nitin
Post Reply