Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Lock states for objects in AS400

Lock states for objects in AS400
Lock states for objects in AS400,Exclusive lock,*EXCL lock,Valid lock state combinations,Exclusive allow read lock,*EXCLRD lock,Shared for update lock,*SHRUPD lock,Shared no update lock,*SHRNUP lock,Displaying the lock states for objects,WRKOBJLCK,Shared for read lock,*SHRRD lock,lock mechanism in as400
Lock states for objects in AS400

Introduction to Lock states

A lock state basically tells us whether this object is in use or is shared. An object can be allocated to a Job or shared with more than one Job-based upon its use (READ or UPDATE)

  • The File and its member are always allocated *SHRRD.
  • File data is allocated based upon the level of lock states applied as discussed below in this blog.
  • Five Lock States

    There are Five lock states on objects in AS400. Let's discuss them.

    Exclusive (*EXCL)

  • When an Exclusive lock is applied to an object then it is fully allocated to the requestor's Job. Once this lock is applied by the Job, no other jobs can use the object.
  • If an object is already allocated to another job then the requester Job cannot get the exclusive lock on the object.
  • We can apply this locked state on an object when we do not want any other job to have access to the object until the object is in use by the Job.
  • Exclusive allow read (*EXCLRD)

  • The object is allocated to the requester's job. But still, other Jobs can get access to the object in reading mode.
  • We can apply this locked state on an object when we do not want any other job to perform any other operation other than reading.
  • Shared for update (*SHRUPD)

  • The object can be shared with another job for UPDATE or READ operation.
  • Therefore, other Jobs can either request for Shared-for-read lock state or a Shared-for-update lock state on an object.
  • We can apply this locked state on an object when we want to UPDATE the object and also allow the other Jobs to perform READ or UPDATE on the same object.
  • Shared no update (*SHRNUP)

  • The object can be shared with another job if another job requests either for a shared-no-update lock state or a shared-for-read lock state.
  • We can apply this locked state on an object when we do not want to UPDATE the object and also ensure that no other job can UPDATE the object.
  • Shared no read (*SHRRD)

  • The object can be shared with another job if another job does not request exclusive use of the object.
  • Another Job can request an exclusive-allow-read, shared-for-update, shared-for-update, shared-for-read, or shared-no-update lock state.
  • Valid lock state combinations

    The below table tells a valid lock state combination for an object that can be applied by one or more than one job.

    If one Job obtains this locked state Another Job can obtain this locked state
    *EXCL None
    *EXCLRD *SHRRD
    *SHRUPD *SHRUPD or *SHRRD
    *SHRNUP *SHRNUP or *SHRRD
    *SHRRD *EXCLRD, *SHRUPD, *SHRNUP, or *SHRRD

    Displaying the lock states for objects

    We can display the lock states on an object using the following CL command on command line AS400.

    WRKOBJLCK  OBJ(Library_Name/Object_Name)  OBJTYPE(Object_Type)

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain