Menu

Berkely Database - ISAM Files

2021-09-10
2024-08-17
1 2 > >> (Page 1 of 2)
  • Steve Millman

    Steve Millman - 2021-09-10

    Hi all,

    Been 30+ years since I built ISAM and have some basic questions..
    Hoping someone familiar with use of ISAM and Alternate Indexes can answer
    Using a simple illustration to pose my question..

    Lets say my data is as follows
    01 Tx-Record.
    05 Tx-Date-Time.
    10 Tx-Date-YYYYMMDD pic x(08).
    10 Tx-Time-HHMMSS pic x(6).
    05 Tx-type-of-purchase Pic (6).
    05 Tx-Pay-Method-Used Pic x(2).
    05 Tx-Customer-Name Pic x(40).

    I want my primary, unique key to be Tx-Date-time, but I want to have an alternate key of Tx-Customer-name in this example.

    Would I code the add Rec Keys (containing copies of the data from the file ) to the front of the file definition as follows?

    01 Tx-Record.
    05 REC-Key.
    10 Date-Time-Key . pic x(14).
    10 filler pic x(26).
    05 ALT-Key redefines Rec-Key.
    10 Cust-name-key pic x(40).
    05 Tx-Date-Time.
    10 Tx-Date-YYYYMMDD pic x(08).
    10 Tx-Time-HHMMSS pic x(6).
    05 Tx-type-of-purchase Pic (6).
    05 Tx-Customer-Name Pic x(40).

    In this example I chose the larger key and used that size for the keyfield, and redefined the actual key with the alternate. Is this how I would code this? Been hunting around on the internet for ISAM examples but not finding any.

    My program compiled and ran; but I could not read the ISAM file with my editor, so was not sure if I am doing this right.

    Oh, that is one more question.. do I have to give the file a particular extention name? I was calling it .dat; but in googling it seems that some folks use .ISAM. Do I need to do that.

    And are there any actual examples of this sort of coding out there that anyone could point me to.

    Thanks a lot. My programs were going fine (reading flat files and building single key indexed files (I think), but once I added the alternate.. it seems to be screwed up.

    Thank you in advance for your help. Once I am done will be happy to share the working code. My goal was to build a file that Loads ISAM file with Alternate Indexes, a Program that Unloads that ISAM file to a flat file, and a Program that does file maintenance on the ISAM file.

    Best Regards,

    Steve

     
    • Brian Tiffin

      Brian Tiffin - 2021-09-11

      GnuCOBOL supports ALTERNATE KEY syntax in a SELECT clause.

      For some real world samples, although the code is embedded in autotest sources, still not too too hard to read through, or copy'n'paste from, take a look at

      https://sourceforge.net/p/gnucobol/code/HEAD/tree/trunk/tests/testsuite.src/run_file.at

      and then 'Find in page' looking for ALTERNATE, and then scroll up and down to the SELECTs, and the STARTs and whatnot, Steve.

      If you download a source tarball, or checkout from SVN, you can also just use an editor, in tests/testsuite.src/run_file.at and look around at the COBOL by searching to the test programs that mention ALTERNATE.

      A lot of our tests are "technical" in nature, with poor naming conventions etc, on way to adding single-feature, focused, compiler tests. For the file related tests, Ron has gone above and beyond, using more practical code, far more fleshed out, and therefore more packed with potential for learning from.

      From what I see from your code sample, you don't need or often want to REDEFINE key name space, That might end up overwriting a primary key, and that can be bad. :)

      The contributions in the GCSORT utility can also help learn about some of the ins. outs and superpowers in GnuCOBOL ISAM.

      https://sourceforge.net/p/gnucobol/contrib/HEAD/tree/trunk/tools/GCSORT/

      As an aside. You might also want to explore ANS COBOL 1972, with the Hercules emulator of a fairly full featured mainframe running MVS 3.8j. If you are curious about that, start at http://wotho.ethz.ch/tk4-/ and drop a note here, and I can spray a bunch more links to running frame emulation and JCL with COBOL. (and PL/I, RPG, S360/370 Assembly, Fortran, ...)

      Have good, have fun, Steve,
      Blue

       

      Last edit: Brian Tiffin 2021-09-11
      • Steve Millman

        Steve Millman - 2021-09-11

        Thanks Brian. I will look into that. Having fun though.. even though I had what appeared to be a working program (pre alternate indexes).. totally collapse. :) Think I have it working again; but am still testing. Look forward to researching the links you posted. Thank you!!

         
    • László Erdős

      László Erdős - 2021-09-12

      but I could not read the ISAM file with my editor

      For Berkeley DB there are Command Line Utilities: db_dump or db_load, etc...

      László

       

      Last edit: László Erdős 2021-09-13
      • Anonymous

        Anonymous - 2021-09-12

        Thanks Laszlo. Those work like a charm.

        On Sun, Sep 12, 2021 at 12:33 PM "László Erdős" laszloerdos@users.sourceforge.net wrote:

        but I could not read the ISAM file with my editor

        For Berkeley DB there Command Line Utilities: db_dump or db_load, etc...

        László

        Berkely Database - ISAM Files
        https://sourceforge.net/p/gnucobol/discussion/help/thread/d693d5c33b/?limit=25#410a/d2b8


        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/

         
      • Steve Millman

        Steve Millman - 2021-09-12

        Thank you Laszlo. That really helps. Got the verify, load, dump to work..

         
  • Steve Millman

    Steve Millman - 2021-09-11

    Solved, i think..
    I think what I changed might be working but need to further test. I removed the redefines of the keys.. It was hosing me over. Instead I built each key with the contents of their separate key only, no filler.. and placed them at the end of the record layout. I loaded the indexed file and then unloaded it, with the load and unload programs. The unloaded file is now readable again, which is a good sign. I have yet to test this with my indexed maintenance program. Hoping it can read and browse thru the file. Am not aware of a ISAM viewer, like we use for PDFs, Office, etc.. so am writing programs to do the heavy lifting. This could turn out okay.. :)

     
    • David Wall

      David Wall - 2021-09-11

      Do you 'have' to use Berkeley ?? - VBIsam although it uses 2 files - the data file is a text file - albeit possibly not in key sequence after some deletions & additions. It's still more readable than a BDB isam file. Get it from Arnold T's website - https://www.arnoldtrembley.com/GnuCOBOL.htm

       
  • Mickey White

    Mickey White - 2021-09-11

    Here is a simple GnuCobol program that will load a sorted (by primary) key input flat file with an alternate key in the record. Note: the VSAM system is Berkeley, suppose it should work for VBIsam, but not sure. .

     
    • Steve Millman

      Steve Millman - 2021-09-12

      Thanks, Mickey.

       
    • Brian Tiffin

      Brian Tiffin - 2021-09-13

      Just a note on that, and if needs be, have someone correct this belief.

      VBISAM fails a few make check tests, but from what I see, it's sparse key store testing. Keys that test empty are being added to indexes, so, not sparse. Things still work (except for logic that expects no duplicates of the empty key while processing), at the expense of index size and disk space. Data is still there, with redundant index entries.

      That leads to a belief that it's not broken, so much as bloated. ?? From what I can tell.

      With the caveat that this opinion is of LOW-VALUE, only using GnuCOBOL indexed data for exploring and tinkering, and not in anger, under pressure on a clock. ;-)

      Cheers,
      Blue

       
  • DaveR

    DaveR - 2021-09-12

    This is how we set keys in our old DOS MF Cobol.

    SELECT NOT OPTIONAL INVOICE-FILE
               ASSIGN TO DISK
               ORGANIZATION IS INDEXED
               ACCESS MODE IS DYNAMIC
               LOCK MODE IS MANUAL WITH LOCK ON MULTIPLE RECORDS
               RECORD KEY IS INVOICE-KEY = INVOICE-NO INVOICE-LINE-NO
               ALTERNATE RECORD KEY IS INVOICE-NO WITH DUPLICATES
               ALTERNATE RECORD KEY IS INVOICE-LINE-STOCK-CODE WITH
                         DUPLICATES
               ALTERNATE RECORD KEY IS INVOICE-CUST-CODE WITH DUPLICATES
               FILE STATUS IS FILE-STATUS.
    

    DaveR

     
    • Steve Millman

      Steve Millman - 2021-09-12

      Thanks Dave.

       
  • Graham Knight

    Graham Knight - 2021-09-12
      Hi Steve,
    
      This is one I have used.
    
          SELECT CMPIndexFile ASSIGN TO CMPIndexFileDisc
                     ORGANIZATION IS INDEXED
                      ACCESS MODE IS DYNAMIC
                      RECORD KEY IS CMP-Company-Number     
                      ALTERNATE RECORD KEY IS CMP-Postcode
                      WITH DUPLICATES
                      FILE STATUS IS CMP-STATUS.
    
     
    • Steve Millman

      Steve Millman - 2021-09-12

      Thanks Graham.

       
  • Mickey White

    Mickey White - 2021-09-12

    Yes these are good. We did the load of the file (A one time shot) with sequential and then the random read programs we used dynamic.

     
    • Steve Millman

      Steve Millman - 2021-09-12

      Thank you.

       
  • Steve Millman

    Steve Millman - 2021-09-12

    New Question.. The ISAM files are built and being accessed in the program. Odd thing though is that they are not 'sorted', which I would have expected in an Indexed file. Am I wrong?

    This file is an accounting file. The Date Time stamp is unique. That is the primary key.
    These alternate keys, such as the one by Name (who the transactions are paid to or receive from ) is an Alternate Key. The key consists of the Name and the Date-Time stamp In that way, I thought that if I looked up a name, I would have it return in date and time order.. Instead I see the records, when reading next by the Alternate Name/Date-Time key, in Primary Key Order.

    Is that what one expects from these Alternate keys?

     
    • Brian Tiffin

      Brian Tiffin - 2021-09-13

      No it is not. Can you post code, Steve?

      Within each index, reads will be in order for the key in question (ascending or descending, as specified in the KEY IS, or when using READ PREVIOUS to go backwards).

      You can take a peek at https://gnucobol.sourceforge.io/faq/index.html#does-gnucobol-support-isam too, Steve. Nerd defense mechanism mode: I don't document much about the bread and butter of COBOL file processing in the FAQ, (yet). There are better, more practical examples floating around.

      Cheers,
      Blue

       
  • Steve Millman

    Steve Millman - 2021-09-13

    Thanks Brian. Knowing it was not normal helped me to find the bug. All good now.
    Now that I have a basic, ISAM with Alternate Index files working.. including the
    BDB tools.. I am fairly golden. Just gotta get my maintenance program working.. and I will have a complete basic set of programs to use against my accounting file (checkbook).

     
    👍
    1
    • Anonymous

      Anonymous - 2024-08-17

      Hi Steve, I am trying to get GNU COBOL work with ISAM using default Berkley DB. I am using GNUCOBOL version 3.2.0 on Mac. Can you please share a sample of your GNU-COBOL ISAM program?

      I am able to take the sample program in section 5.5 Does GnuCOBOL support ISAM at this URL: https://gnucobol.sourceforge.io/faq/gcfaq.html#isam, compile and execute. Only code change I had to make was to change the definition of variable indexing-status to PIC X(2) - to fix the compilation error.

      I have couple of questions
      1. After the execution the program produces 2 physical files: indexed-file.data and indexed-file.dat.1. whereas I was expecting a single .dat file containing both data and index information. Is creation of second file because of the "alternate record key" for the file?
      2. When I issue db_dump command on the indexed-file.data or indexed-file.data.1 I am gettting the error: "unsupported btree version: 10".

      I am not specifying any version of btree anywhere in the code. So I do not understand why and how there can be a mismatch?

      Without a utility to view / dump / edit the ISAM data file, application is pretty much useless.

       
1 2 > >> (Page 1 of 2)

Anonymous
Anonymous

Add attachments
Cancel