ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Capturing the rrn of a locked record

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

  • Capturing the rrn of a locked record

    I have a program that reads through FILEA for update and when it finds a record in FILEA that is locked by another program, I want it to display the RRN of the locked record along with an error message. Problem is the RR# in the INFDS for FILEA only updates the RR# in the DS of the last record that was successfully read. How can I capture the RRN of the record in FILEA that the program is trying to retrieve but is locked.

  • #2
    Why not reading twice:
    1. Read in Display Mode
    2. Chain in Update Mode

    Then you can determine the RRN from the row read in Display Mode and can display it.

    Comment


    • #3
      I would modify Birgitta's suggestion to test for the lock condition and if encountered try a chain(n) or read(n) to get the record.

      That said I'm frankly not sure why you want the RRN because it is pretty meaningless in most cases - why not just display the key of the record and (more usefully) interrogate the lock and find out what program/user is holding it.

      Once you establish which program fix it so that it never holds locks while a record is displayed to the user - which situation probably accounts for about 90+% of all record lock scenarios.

      Comment


      • #4
        Originally posted by JonBoy View Post
        I would modify Birgitta's suggestion to test for the lock condition and if encountered try a chain(n) or read(n) to get the record.
        ... be aware (N) will only work if you are not working under commitment control!

        Comment


        • #5
          The error message in the PSDS has the RRN of the locked record.

          Try this program, changing "myfile" to some file that has at least two records.

          Code:
          dcl-f myfile usage(*update) infds(infds);
          dcl-ds infds;
             msgid char(7) pos(46);
          end-ds;
          dcl-ds sds psds;
             exception_data char(80) pos(91);
          end-ds;
          read(e) myfile; // read one record
          read(e) myfile; // read another record
          if %error();
             dsply 'Error. Check joblog for msg about infds, psds';
             snd-msg msgid + ' "' + exception_data + '"';
          endif;
          dsply 'wait, type 1' '' *in10;
          *inlr = '1';​
          • Submit a call to the program to batch to lock the second record
          • OVRDBF myfile waitrcd(1)
          • Call it from your interactive job
          • If the DSPLY says an error occurred, dspjoblog to see the SND-MSG output
          • WRKSBMJOB and use option 7 to reply to the DSPLY for the submitted call
          The SND-MSG output in my joblog shows this:
          Code:
          CPF5027 "Record 2 in use by job or transaction 873132/BMORRIS/BMORRIS.
          If the first-level text of the message in the PSDS doesn't have all the information you need (such as the actual file), you could receive the message from the joblog.

          Comment

          Working...
          X