Skip to main content
Dominique Sacre
Rocketeer
Mar 17, 2012 12:13 AM UTC

reading and writing files using OO COBOL

[Migrated content. Thread originally posted on 16 March 2012]

Has anyone got any pointers as to how OO cobol can read/write to a ISAM file? The documentation for OO just skips over this, and the only 'example' file that I found in the knowledge base no longer exists for download!

There is one passing reference to creating a factory object, but nothing more than that. I don't really want to write procedural call just to facilitate reading/updating a file.

I'm using Server Express 5.1, but any help is much appreciated.

Thanks very much.
Mike.

    1 reply

    Chris Glazier
    Moderator
    Mar 17, 2012 12:23 AM UTC

    [Migrated content. Thread originally posted on 16 March 2012]

    Has anyone got any pointers as to how OO cobol can read/write to a ISAM file? The documentation for OO just skips over this, and the only 'example' file that I found in the knowledge base no longer exists for download!

    There is one passing reference to creating a factory object, but nothing more than that. I don't really want to write procedural call just to facilitate reading/updating a file.

    I'm using Server Express 5.1, but any help is much appreciated.

    Thanks very much.
    Mike.
    There are several syntax options available for OO COBOL.
    Below shows the ISO2002 COBOL syntax.


    $set repository(update on checking on)                           
    *-----------------------------------------------------------------
    class-id. account as "account" inherits from Base.               
    environment division.                                           
    repository.                                                     
         class account as "account".                                 
                                                                     
    input-output section.                                           
         select account-file assign to "c:\\oofiles\\account.dat"       
                             organization is indexed                 
                             access is dynamic                       
                             record key is key1                       
                             file status is file-status.             
    data division.                                                   
    file section.                                                   
    fd account-file.                                                 
    01 account-record.                                               
        05 key1     pic 9(5).                                         
        05 rest     pic x(20).                                       
    working-storage section.                                         
    01 file-status     pic x(2).                                     
                                                                     
    factory.                                                         
    end factory.                                                     
    object.                                                         
                                                                     
    method-id. "CreateAccount".                                     
    linkage section.                                                 
    01 lk-filestatus    pic x(2).                                   
    procedure division returning lk-filestatus.                     
                                                                     
          open output account-file                                   
          close account-file                                         
          open i-o account-file                                       
                                                                     
          move file-status to lk-filestatus                           
          exit method.                                               
                                                                     
    end method "CreateAccount".                                     
                                                                     
    method-id. "WriteAccount".                                       
    linkage section.                                                 
    01 lk-record.                                                   
        05 lk-key1     pic 9(5).                                     
        05 lk-rest     pic x(20).                                     
    01 lk-filestatus    pic x(2).                                   
    procedure division using lk-record returning lk-filestatus.     
                                                                     
         move lk-record to account-record                             
         write account-record                                         
         move file-status to lk-filestatus                           
         exit method.                                                 
                                                                     
    end method "WriteAccount".                                       
                                                                     
    end object.                                                     
                                                                     
    end class account.                                               




    This class can be called as follows:


    $set repository(checking on)                                   
    id division.                                                 
    program-id.    oofiles.                                       
    repository.                                                   
         class account as "account".                               
    working-storage section.                                     
    01 wsAccount              object reference.                   
    01 file-status            pic x(2).                           
    01 ws-record.                                                 
        05 ws-key1             pic 9(5).                           
        05 ws-rest             pic x(20).                         
    procedure division.                                           
                                                                   
        invoke account "new" returning wsAccount                   
        invoke wsAccount "CreateAccount" returning file-status     
        display file-status                                       
        move all "1" to ws-record                                 
        invoke wsAccount "WriteAccount"                           
           using ws-record                                         
           returning file-status                                   
        end-invoke                                                 
                                                                   
        stop run.