Menu

Read indexed file

2024-05-28
2024-05-29
  • Alain Reymond

    Alain Reymond - 2024-05-28

    I notice something strange with an indexed file:

    Here a a small program called testio:

          $set sourceformat"free"
           *> cobc -x -free testio.cbl
           identification division.
           program-id. testio.
           environment division.
           configuration section.
           input-output section.
           file-control.
               select fdmyfile assign to "myfile"
                   organization indexed
                   access dynamic
                   lock mode automatic with lock on record
                   record key fdmyfile-key
                   file status myfile-status.
           data division.
           file section.
           fd fdmyfile.
           1 fdmyfile-key pic 9(8).
           working-storage section.
           1 myfile-status pic xx.
           1 wss-eof pic 9 value 0.
             88 eof value 1 when set to false 0.
           procedure division.
           open output fdmyfile
           move 1 to fdmyfile-key   write fdmyfile-key
           move 2 to fdmyfile-key   write fdmyfile-key
           move 3 to fdmyfile-key   write fdmyfile-key
           move 4 to fdmyfile-key   write fdmyfile-key
           move 5 to fdmyfile-key   write fdmyfile-key
           move 6 to fdmyfile-key   write fdmyfile-key
           move 7 to fdmyfile-key   write fdmyfile-key
           close fdmyfile
           open i-o fdmyfile  
           move 0 to fdmyfile-key
           start fdmyfile key >=  fdmyfile-key end-start
           read  fdmyfile next end-read display  fdmyfile-key *>1
           read  fdmyfile next end-read display  fdmyfile-key *>2
           read  fdmyfile next end-read display  fdmyfile-key *>3
           read  fdmyfile next end-read display  fdmyfile-key *>4
           call "subtestio"
           set eof to false
           perform until eof
             read  fdmyfile next 
             at end 
               set eof to true
             not at end
               display  fdmyfile-key
             end-read
           end-perform
           close fdmyfile
           goback
           .
    
           program-id. subtestio.
           environment division.
           input-output section.
           file-control.
               select fdmyfile assign to "myfile"
                   organization indexed
                   access dynamic
                   lock mode automatic with lock on record
                   record key fdmyfile-key
                   file status myfile-status.
           data division.
           file section.
           fd fdmyfile.
           1 fdmyfile-key pic 9(8).
           working-storage section.
           1 myfile-status pic xx.
           procedure division.
           open i-o fdmyfile
           display "myfile-status in subtestio - open file : " myfile-status
           move 10 to fdmyfile-key   write fdmyfile-key
           display "myfile-status in subtestio - write in file : " myfile-status
           close fdmyfile
           display "myfile-status in subtestio - close file : " myfile-status
           goback
           .
           end program subtestio.
    end program testio.
    

    It reads 4 records in an indexed file, then calls another program writing in this file a record whose key is greater than all keys and continues to read the file.
    Here is the result under MF Cobol:

    00000001
    00000002
    00000003
    00000004
    myfile-status in subtestio - open file : 00
    myfile-status in subtestio - write in file : 00 
    myfile-status in subtestio - close file : 00    
    00000005
    00000006
    00000007
    00000010
    

    and under gnucobol :

    00000001
    00000002
    00000003
    00000004
    myfile-status in subtestio - open file : 00
    myfile-status in subtestio - write in file : 00
    myfile-status in subtestio - close file : 00
    00000005
    00000006
    00000007
    

    Under gnucobol, the added record (key 10) is ignored. To display it, I have to close the file when the program returns from 'subtestio', reopen it and start reading again.

    I add two small programs testio2 and testio3.
    testio2 creates a file, adds records (for simulations), closes, opens again and waits for the operator to press Enter.
    In the meantime, another operator starts testio3 that adds 2 records to the file and quits. Then the first operator decides to press enter to read the complete file. Only records 1 to 7 are displayed.
    Under MF , you see all 10 records.

    The records are not lost. They are stored somewhere and only to be seen when the data file is closed and reopened.

    Is it possible to get under Gnucobol the same behaviour as under MF ?

    Regards.

     
    • Vincent (Bryan) Coen

      Using v3.2 final on a Mageia v9 X64 system AND changing your source in

      read  fdmyfile next end-read display  fdmyfile-key >4
             close fdmyfile   
      > New line
             call "subtestio"

      I get :

      [vince@applewood tmp]$ cobc -x test1.cbl
      [vince@applewood tmp]$ ./test1
      00000001
      00000002
      00000003
      00000004
      myfile-status in subtestio - open file : 00
      myfile-status in subtestio - write in file : 00
      myfile-status in subtestio - close file : 00
      00000001
      00000002
      00000003
      00000004
      00000005
      00000006
      00000007
      00000010

      Correct ?

      On 28/05/2024 17:09, Alain REYMOND wrote:

      I notice something strange with an indexed file:

      Here a a small program called testio:

      |$setsourceformat"free" >cobc-x-freetestio.cbl
      identificationdivision. program-id.testio. environmentdivision.
      configurationsection. input-outputsection. file-control.
      selectfdmyfileassignto"myfile" organizationindexed accessdynamic
      lockmodeautomaticwithlockonrecord recordkeyfdmyfile-key
      filestatusmyfile-status. datadivision. filesection. fdfdmyfile.
      1fdmyfile-keypic9(8). working-storagesection. 1myfile-statuspicxx.
      1wss-eofpic9value0. 88eofvalue1whensettofalse0. proceduredivision.
      openoutputfdmyfile move1tofdmyfile-keywritefdmyfile-key
      move2tofdmyfile-keywritefdmyfile-key
      move3tofdmyfile-keywritefdmyfile-key
      move4tofdmyfile-keywritefdmyfile-key
      move5tofdmyfile-keywritefdmyfile-key
      move6tofdmyfile-keywritefdmyfile-key
      move7tofdmyfile-keywritefdmyfile-key closefdmyfile
      openi-ofdmyfilemove0tofdmyfile-key
      startfdmyfilekey>=fdmyfile-keyend-start
      readfdmyfilenextend-readdisplayfdmyfile-key
      >1
      readfdmyfilenextend-readdisplayfdmyfile-key>2
      readfdmyfilenextend-readdisplayfdmyfile-key
      >3
      readfdmyfilenextend-readdisplayfdmyfile-key*>4 call"subtestio"
      seteoftofalse performuntileof readfdmyfilenextatendseteoftotrue
      notatend displayfdmyfile-key end-read end-perform closefdmyfile goback
      . program-id.subtestio. environmentdivision. input-outputsection.
      file-control. selectfdmyfileassignto"myfile" organizationindexed
      accessdynamic lockmodeautomaticwithlockonrecord recordkeyfdmyfile-key
      filestatusmyfile-status. datadivision. filesection. fdfdmyfile.
      1fdmyfile-keypic9(8). working-storagesection. 1myfile-statuspicxx.
      proceduredivision. openi-ofdmyfile display"myfile-status in subtestio
      - open file : "myfile-status move10tofdmyfile-keywritefdmyfile-key
      display"myfile-status in subtestio - write in file : "myfile-status
      closefdmyfile display"myfile-status in subtestio - close file :
      "myfile-status goback . endprogramsubtestio. endprogramtestio. |

      It reads 4 records in an indexed file, then calls another program
      writing in this file a record whose key is greater than all keys and
      continues to read the file.
      Here is the result under MF Cobol:

      |00000001 00000002 00000003 00000004
      myfile-statusinsubtestio-openfile:00
      myfile-statusinsubtestio-writeinfile:00myfile-statusinsubtestio-closefile:0000000005
      00000006 00000007 00000010 |

      and under gnucobol :

      |00000001 00000002 00000003 00000004
      myfile-statusinsubtestio-openfile:00
      myfile-statusinsubtestio-writeinfile:00
      myfile-statusinsubtestio-closefile:00 00000005 00000006 00000007 |

      Under gnucobol, the added record (key 10) is ignored. To display it, I
      have to close the file when the program returns from 'subtestio',
      reopen it and start reading again.

      I add two small programs testio2 and testio3.
      testio2 creates a file, adds records (for simulations), closes, opens
      again and waits for the operator to press Enter.
      In the meantime, another operator starts testio3 that adds 2 records
      to the file and quits. Then the first operator decides to press enter
      to read the complete file. Only records 1 to 7 are displayed.
      Under MF , you see all 10 records.

      The records are not lost. They are stored somewhere and only to be
      seen when the data file is closed and reopened.

      Is it possible to get under Gnucobol the same behaviour as under MF ?

      Regards.


      Read indexed file
      https://sourceforge.net/p/gnucobol/discussion/help/thread/045e9977aa/?limit=25#84d0


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/gnucobol/discussion/help/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
      • Alain Reymond

        Alain Reymond - 2024-05-28

        That is correct! When you close the file an reopen it, the records are there.

        More astonishing : I added testio4.cbl
        Run testio4 and wait. In another console run testio3 to add records 10, 11, 12.
        Now try to read key 10 from program testio4 : it is not found. Works well when compiled from MF.
        Very strange!

         
  • Alain Reymond

    Alain Reymond - 2024-05-28

    OK, found : DB_HOME has to be set to the directory where the files are positioned. Not very intuitive, but it works.
    Regards

     
    • Vincent (Bryan) Coen

      On 28/05/2024 20:39, Alain REYMOND wrote:

      OK, found : DB_HOME has to be set to the directory where the files are
      positioned. Not very intuitive, but it works.
      Regards

      Sorry, had forgotten that one :(

       
  • Vincent (Bryan) Coen

    No you are missing it, closing the file in prog 1 allows it to be read correctly by prog2.

    This of course does depend on the ISAM lib you are using but I have found from many years of experience to close a file when process is complete and if needed to open it again at the correct point.

    I do not trust any file or record locking as that also varies between ISAM libraries.

     
  • Ralph Linkletter

    MF by default implements an extensive file sharing mechanism.
    I know the ISAM variants used by GnuCOBOL are less robust than those from MF.

    C-Tree-RTG (proprietary from Faircom.com) offers transparent EXTFH compatibility with very sophisticated record level sharing. Faircom has indicated that their ISAM / VSAM sharing mechanism is available for GnuCOBOL.

    Micro Focus wise:
    Fileshare as a compiler option has been deprecated - the invocation of record level sharing is now implemented as below:

    Comments:
    This directive is included for compatibility with earlier file-sharing products. When writing new programs you should use the locking syntax rather than this directive.
    If any ISAM / VSAM record locking / unlocking . . . is used in the COBOL program the MF file sharing facility is initiated.

    Fileshare Guide
    Fileshare is a client/server system designed to provide more efficient processing of data files that are accessed concurrently, across a network, by a large number of users.

    In addition, Fileshare offers features that are not available with the base COBOL file handler including transaction processing and rollforward recovery logging.

     

    Last edit: Ralph Linkletter 2024-05-29

Anonymous
Anonymous

Add attachments
Cancel