ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

without using RGZPFM need to use unused space

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

  • without using RGZPFM need to use unused space

    I have a PF1 with 10 records respective RRN numbers are 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10. I have deleted the record which is there in RRN 5. Now how I want to use that space which means I have to insert a record in RRN 5. Is there any possibility and how to do that?

  • #2
    Re: without using RGZPFM need to use unused space

    That's a strange request, similar to homework or an interview question. If the file is defined with appropriate attributes, it will happen automatically. Is there a reason that RRN #5 must be inserted?
    Tom

    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

    Comment


    • #3
      Re: without using RGZPFM need to use unused space

      There is a file option to Reuse Deleted Records. That doesn't guarantee it will be RRN 5, but it will re-use. Or build a "direct " file where RRN is the key.

      Comment


      • #4
        Re: without using RGZPFM need to use unused space

        In 'C' use _Rwrited().

        Chris..

        Comment


        • #5
          Re: without using RGZPFM need to use unused space

          I'd expect it to be unusual to use a 'direct' file in order to "use unused space". They're more commonly used because, for some reason, the physical sequence is important, i.e., the RRN() itself is meaningful. The part specific to "insert a record in RRN 5", that's a good match for 'direct'.

          For perhaps a majority of PFs, a 10-record file will have unused space that won't be re-used even if all of the first 10 relative record slots are used for records. The unused space will remain at the end and won't be used at all until enough records are added to overflow the initial allocation. That's part of why it's a strange question that seems more like homework/interview.
          Tom

          There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

          Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

          Comment


          • #6
            Re: without using RGZPFM need to use unused space

            1. write the data from file-1 to file-2
            2. clear file-1
            3. write the data from file-2 to file-1
            4. clear file-2

            Best of Luck
            GLS
            The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

            Comment


            • #7
              Re: without using RGZPFM need to use unused space

              If you use the RECNO keyword on your F spec, you can specify the RRN where you want to write. It can only be used with the RRN of a deleted record; you can't add new records this way. It's the RPG equivalent of the C function _Rwrited.

              Finding the RRN's of deleted records is another matter ...

              Code:
                 // crtpf qtemp/testfile rcdlen(10)
              
                 ctl-opt dftactgrp(*no);
                 dcl-pr qcmd extpgm end-pr;
                 dcl-c FILE_NAME 'QTEMP/TESTFILE';
                 dcl-s wait char(25) inz('Now DSPPFM QTEMP/TESTFILE');
              
                 writeSome();
                 deleteRec5();
                 rewriteRec5();
                 *inlr = '1';
              
                 dcl-proc writeSome;
                    dcl-f testfile disk(10) usage(*output) extfile(FILE_NAME);
                    dcl-ds ds len(10) end-ds;
                    dcl-s i int(10);
                     for i = 1 to 10;
                        ds = %char(i);
                        write testfile ds;
                     endfor;
                     close testfile;
                     dsply 'after writing 10 records' '' wait;
                     qcmd();
                  end-proc;
              
                  dcl-proc deleteRec5;
                     dcl-f testfile disk(10) usage(*delete) extfile(FILE_NAME);
                     delete 5 testfile;
                     close testfile;
                     dsply 'after deleting record 5' '' wait;
                     qcmd();
                  end-proc;
              
                  dcl-proc rewriteRec5;
                     dcl-f testfile disk(10) usage(*output) extfile(FILE_NAME)
                                    recno(rrn);
                     dcl-s rrn int(10);
                     dcl-ds ds len(10) end-ds;
              
                     rrn = 5;
                     ds = 'new rec 5';
                     write testfile ds;
                     close testfile;
                     dsply 'after re-writing record 5' '' wait;
                     qcmd();
                  end-proc;

              Comment


              • #8
                Re: without using RGZPFM need to use unused space

                Barbara

                To find the deleted records.
                1. Open file and locate first record (RRN 1) using _Rlocate();
                2. Read the same record using _Rreads();
                3. If bytes read <= 0 then the record is deleted.
                4. Increment RRN
                5. _Rlocate() using new RRN.
                6 etc.

                There is a feedback area which has the deleted record flag but i have not experimented with that?

                Chris...

                Comment


                • #9
                  Re: without using RGZPFM need to use unused space

                  Chris, I think you could also just read sequentially and look for gaps in the relative record numbers.

                  Comment


                  • #10
                    Re: without using RGZPFM need to use unused space

                    Why not simply turn on "reuse deleted records"?

                    Comment

                    Working...
                    X