ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Query on ALCOBJ command...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query on ALCOBJ command...

    I want to lock a file exclusively for a job (no updates/no read from any other job till my job completes). If some one is else is trying to use the file, then i want to send a Message to the User who is trying to use the file. These are the lines of code by which i am trying to do it.

    I have a interactive program (CL which calls a RPG) and then again submits a Job which uses the INVOICE file. I want to know whether i can allocate the file in my 1st CL program (At a time only 1 person should run this Job). How do i achieve this?

  • #2
    Re: Query on ALCOBJ command...

    Code:
    ALCOBJ     OBJ(('yourfilename' *FILE *EXCL *FIRST))
    you can also use the WAIT parameter to make it wait a set amount of time before giving up...

    Dont forget that (a) you need to DLCOBJ at the end and (b) your BATCH job is a new job so will need to handle its own file locking...

    Every other program on the system that tries to use that file, while its being exclusively locked by you, will time out and issue an 'unable to allocate file' exception message. You will need to monitor for this in those programs and issue a user message accordingly...
    predictably positive, permanently punctilious, purposely proactive, potentially priceless, primarily professional : projex

    Comment


    • #3
      Re: Query on ALCOBJ command...

      Originally posted by Jai82 View Post
      I want to lock a file exclusively for a job (no updates/no read from any other job till my job completes). If some one is else is trying to use the file, then i want to send a Message to the User who is trying to use the file. These are the lines of code by which i am trying to do it.

      I have a interactive program (CL which calls a RPG) and then again submits a Job which uses the INVOICE file. I want to know whether i can allocate the file in my 1st CL program (At a time only 1 person should run this Job). How do i achieve this?
      sounds like you are gonna clobber yourself. if you allocate the file in your interactive job then submit a batch job that tries to use that file what happens next? the batch job blows up due to a file lock caused by your interactive job.
      I'm not anti-social, I just don't like people -Tommy Holden

      Comment


      • #4
        Re: Query on ALCOBJ command...

        Thank U. Actually, i am done with the coding . I made a big mistake initially. I allocated a object in CL program 1 and the same file was used in CL Program 2 (submitted from CL1). I din't understand what i was doing for some time . Till i commented out the SBMJOB and called program 2 interactively...

        Comment

        Working...
        X