Update Sequence number as part of the job sequence

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

rajendharreddy
Participant
Posts: 46
Joined: Tue Aug 21, 2007 5:39 am
Location: Bangalore, India

Update Sequence number as part of the job sequence

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

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rajendharreddy
Participant
Posts: 46
Joined: Tue Aug 21, 2007 5:39 am
Location: Bangalore, India

Post 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
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Change one of the SDK key management routines available under Routines and use this in your sequence.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

rajendharreddy wrote:Can I reset the value from the job sequence?
Sure. A custom routine with DSExecute and "UV" springs to mind.
-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 »

... or a custom routine with Open, RecordLockU, Write and Close.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post 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

Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Thanks for letting know that :lol: Now if one check the SDK key management routines available under Routines/sdk directory you can see how it proceeds there.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Big Statement

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post 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.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post 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.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Fair enough ! :) 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 ...
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
Post Reply