Page 1 of 2
Update Sequence number as part of the job sequence
Posted: Thu Jan 03, 2008 4:00 am
by rajendharreddy
Hi,
Every load we need to update key management value so that it starts from 1. We know that we can update this value from command line from the DS Administrator. This is a manual step.
But here we want to automate the job sequence in such a way that before running the job sequence, the sequence number should be updated to 1. Meaning it has to be run as part of the job sequence.
Can anybody help me how to update from the job sequence?
Thanks.
Posted: Thu Jan 03, 2008 4:02 am
by ray.wurlod
Where's it stored? My choice would be to use the SDK key management routines, and to use an appropriate command to reset the named sequence in the SDKSequences hashed file.
Posted: Thu Jan 03, 2008 4:40 am
by rajendharreddy
Hi,
The value gets stored in a hash file. I have used following update statement to reset the value from the DS Administrator.
UPDATE SDKSequences USING DICT VOC SET F1='1' WHERE @ID='fff'
Can I reset the value from the job sequence?
Thanks
Posted: Thu Jan 03, 2008 5:44 am
by JoshGeorge
Change one of the SDK key management routines available under Routines and use this in your sequence.
Posted: Thu Jan 03, 2008 8:42 am
by chulett
rajendharreddy wrote:Can I reset the value from the job sequence?
Sure. A custom routine with DSExecute and "UV" springs to mind.
Posted: Thu Jan 03, 2008 2:40 pm
by ray.wurlod
... or a custom routine with Open, RecordLockU, Write and Close.
Posted: Thu Jan 03, 2008 5:02 pm
by JoshGeorge
FUNCTION KeyMgtReset(Arg1,Arg2)
Input: Arg1 - Name of the sequence
Input: Arg2 - Value to be set
Description: If this routine is called for the first time in a new environment and if the named sequence (Arg1) does not exist, this routine will create a new one and set the initial value as Arg2. If named sequence (Arg1) exists a reset happens.
Code: Select all
* Declare shared memory storage.
Common /Sequences/ Initialized, NextVal, SeqFile
EQUATE RoutineName TO 'KeyMgtReset'
If NOT(Initialized) Then
Initialized = 1
Open "SDKSequences" TO SeqFile
Else EXECUTE "CREATE.FILE SDKSequences 2 1 1"
Open "SDKSequences" TO SeqFile
Else Ans = -1
End
Ans = 0
* Reset the sequence value, and write back to file.
NextVal = Arg2
Writeu NextVal On SeqFile, Arg1 Else Ans = -1
Posted: Thu Jan 03, 2008 6:15 pm
by ray.wurlod
That's TERRIBLE code!! You need to own the update lock before a Write to a hashed file, to prevent lost updates. You merrily proceed with your (unprotected) write even if the file could not be opened.
Code: Select all
FUNCTION ResetSDKSequence(SequenceName, ResetValue)
* If SequenceName is not provided, routine returns.
* If SequenceName does not exist it is created.
* If ResetValue is not provided, 1 is used.
* Returns NULL if any problem, ResetValue if successful.
$INCLUDE UNIVERSE.INCLUDE FILEINFO.H
Equate RoutineName To "ResetSDKSequence"
COMMON /Sequences/Initialized, NextVal, SeqFile
Ans = @NULL
If UnAssigned(SequenceName) Or IsNull(SequenceName) Or Trim(SequenceName) <= " "
Then
Message = "Sequence name not given."
Call DSLogWarn(Message, RoutineName)
GoTo MainExit
End
If UnAssigned(ResetValue) Or IsNull(ResetValue) Or Not(Num(ResetValue))
Then NewVal = 1
Else NewVal = ResetValue
* Open SDKSequences file if it is not already open.
If Not(FileInfo(SeqFile, FINFO$IS.FILEVAR))
Then
Open "SDKSequences" To SeqFile
On Error
Message = "System error (" : Status() : ") opening SDKSequences file."
Call DSLogWarn(Message, RoutineName)
GoTo MainExit
End
Else
Command = "CREATE.FILE SDKSequences 2 1 4"
Command<-1> = "IF @SYSTEM.RETURN.CODE >= 0 THEN INSERT INTO DICT SDKSequences(ID,F1,LOC,F4,F5,F6) VALUES ('NextVal','D','1',NextVal','7R','S');"
Call DSExecute("UV", Command, Output, ExitStatus)
If ExitStatus = DSJE.NOERROR
Then
Open "SDKSequences" To SeqFile
On Error
Message = "System error (" : Status() : ") opening SDKSequences file."
Call DSLogWarn(Message, RoutineName)
GoTo MainExit
End
Else
Message = "Unable to open newly-created SDKSequences file."
Call DSLogWarn(Message, RoutineName)
GoTo MainExit
End ; * end of innter Open attempt
End
Else
Message = "Unable to create SDKSequences file."
Message<-1> = Output
Call DSLogWarn(Message, RoutineName)
GoTo MainExit
End
End ; * end of Open statement
End ; * end of test whether file already open
* Attempt to set exclusive record update lock on sequence record.
RecordLockU SeqFile, SequenceName
On Error
Message = "System error (" : Status() : ") setting lock on sequence."
Call DSLogWarn(Message, RoutineName)
GoTo MainExit
End
Locked
Message = "Can not reset sequence that is locked by user number " : Status() : "."
Call DSLogWarn(Message, RoutineName)
GoTo MainExit
End ; * end of RecordLockU statement
* Write new sequence value into sequence record (which releases lock).
Write NewVal To SeqFile, SequenceName
On Error
Message = "System error (" : Status() : ") writing to SDKSequences file."
Call DSLogWarn(Message, RoutineName)
End
Then
Ans = NewVal
End
Else
Message = "Unable to write to SDKSequences file. Status = " : Status() : "."
Call DSLogWarn(Message, RoutineName)
End ; * end of Write statement
MainExit:
RETURN(Ans)
Posted: Thu Jan 03, 2008 6:24 pm
by JoshGeorge
Thanks for letting know that
![Laughing :lol:](./images/smilies/icon_lol.gif)
Now if one check the SDK key management routines available under Routines/sdk directory you can see how it proceeds there.
Big Statement
Posted: Thu Jan 03, 2008 6:31 pm
by ray.wurlod
Everything in the SDK was put together in a hurry, and it shows.
Nearly every routine in the SDK can be improved.
Posted: Thu Jan 03, 2008 6:36 pm
by JoshGeorge
Rightly said. As I have noted earlier I just changed one of the SDK key management routines for what OP asked. Have tested it and works fine.
Change one of the SDK key management routines available under Routines and use this in your sequence.
Posted: Thu Jan 03, 2008 9:15 pm
by ray.wurlod
Have you though? Have you, for example, tested it when someone else is in the process of updating the same sequence name?
Posted: Thu Jan 03, 2008 9:50 pm
by JoshGeorge
Have you tested the same with "KeyMgtGetNextValue" routine available under Routines/sdk directory? "KeyMgtReset" routine falls into the same category, not for concurrent update as "KeyMgtGetNextValueConcurrent" routine.
Posted: Fri Jan 04, 2008 12:36 am
by ray.wurlod
Not being the author, nor responsible for the author, I find no reason to test. If I believe an SDK routine is suitable for my purposes, I use it; if I believe it needs improvement, I create and use an improved version.
I do believe that a "reset" routine falls into the category of needing to manage locking better than the supplied routines do it.
Posted: Fri Jan 04, 2008 1:18 am
by JoshGeorge
Fair enough !
![Smile :)](./images/smilies/icon_smile.gif)
For those whose find the above routine is suitable, use it, if someone believe it needs improvement, please create and use.
ray.wurlod wrote: If I believe an SDK routine is suitable for my purposes, I use it; if I believe it needs improvement, I create and use ...