KeyMgtGetNextValue Usage

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
anilkona
Participant
Posts: 50
Joined: Mon Nov 15, 2004 6:18 pm

KeyMgtGetNextValue Usage

Post by anilkona »

Hello,

Can someone point me to the correct usage of KeyMgtGetNextValue() routine. I see in the definition there is a parameter to this routine. How do we define this parameter? Do we have to pass a constant number value as the argument or is there a place to define the variables and pass that as an argument?

Thanks in advance for the help
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Hi

KeyMgtGetNextValue() is the special routine which will generate sequential numbers. You need to pass the string as parameter and it will be stored inside SDKSequences universe table. This prameter is unique and you cannot have duplicate name. The string is case sensitive. Each time you use this function along with the parameter it will read from the universe and will increase the value in increment and will output the incremented value.

Whenever you want to reset this then you need to update the value in universe.
Syntax:
UPDATE SDKSequences USING DICT VOC SET F1 = 'New_Value' WHERE @ID = 'Sequence_Name';

Thanks
Regards
Siva

Listening to the Learned

"The most precious wealth is the wealth acquired by the ear Indeed, of all wealth that wealth is the crown." - Thirukural By Thiruvalluvar
ranga1970
Participant
Posts: 141
Joined: Thu Nov 04, 2004 3:29 pm
Location: Hyderabad

Re: KeyMgtGetNextValue Usage

Post by ranga1970 »

anilkona wrote:Hello,

Can someone point me to the correct usage of KeyMgtGetNextValue() routine. I see in the definition there is a parameter to this routine. How do we define this parameter? Do we have to pass a constant number value as the argument or is there a place to define the variables and pass that as an argument?

Thanks in advance for the help
You do not need pass constant, this is usually used for one time loads, fro eaxample you have record
col1 col2 col3
a 1 A1
b 2 B1

when you use keyMgt... and run your job for first time your output
col1 col2 col3 col4
a 1 A1 1
b 2 B1 2

but by any chance if you have to rerun the job your output will be

col1 col2 col3 col4
a 1 A1 1
b 2 B1 2
a 1 A1 3
b 2 B1 4

which make your records distinct so either you have to reset KEY in SDK every time you run or use @InrowNumber or @OutrowNumber depending on your situation

you can reset your key in SDK if you use KeyMgt.... as Siva said above
RRCHINTALA
anilkona
Participant
Posts: 50
Joined: Mon Nov 15, 2004 6:18 pm

Thanks

Post by anilkona »

Thanks Ranga and Siva for explanation
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As an FYI, these SDK routines are documented, some better than others - check out the Short and Long Descriptions in their properties. For example, this routine says:
Sequence number generator.
Routine to generate a sequential number. This routine does not support access to a particular sequence by more than one process concurrently. The routine argument is the name associated with the sequence. The routine uses a file to store the next available number. It reads the number once, then increments and stores the value in common, writing the next value back to file each time.
By 'file' it means hash file. You can also read the code to get a better understanding of what it does and how it does it.

Some caveats: It does require a constant value be passed to it if you are expecting a useful series of numbers to come back from it. Each parameter value passed in becomes a key to the hash it uses and starts a new series of numbers if that key doesn't already exist, otherwise you get the next number in sequence for that key. Lastly, because it uses COMMON storage, it is not recommended for use in jobs that take advantage of Row Buffering.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply