Highlighted
Absent Member.
Absent Member.
2008 views

Errors with Standard OO Program

Jump to solution

I've been trying to run the COBOL standard's sample OO application (Section C.18.10 in the 2009 draft) but I've been unable to. I can compile it as is successfully but when I run it, it instantly fails with error 114: 'Attempt to access item beyond bounds of memory (Signal 11)'.

If I compile with the directive REPOSITORY "CHECKING ON", the compilation then fails with the errors 'COBCH1404 : OO: Repository information for externalised class name 'ACCOUNT' not found.' and 'COBCH1404 : OO: Repository information for externalised class name 'ACCOUNT' not found.'

Is there anything I can do to make it compile and run?

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Errors with Standard OO Program

Jump to solution

Change the account class so that it uses just the UPDATE ON option of the repository directive and add the as "base" to the CLASS phrase as shown below:

     $set repository "UPDATE ON"
      CLASS-ID. Account INHERITS Base.
      ENVIRONMENT DIVISION.
      CONFIGURATION SECTION.
      REPOSITORY.
          CLASS Base as "base".

Do not use the repository directive for the bankmain.cbl at all.

This worked fine for me...

Thanks.          

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Errors with Standard OO Program

Jump to solution

Can you please post the source of the program that you are trying to compile?

If you are using the REPOSITORY directive with CHECKING ON then you should also have this set to use REPOSITORY with UPDATE ON in the class that you are referencing.

The UPDATE ON is what adds the class to the repository so that it can then be referenced by other programs or classes.

$SET REPOSITORY "UPDATE ON CHECKING ON"

BTW, none of this is required when using the OO syntax supported in managed code as the repository has been made obsolete by the addition of the TYPE keyword.

Thanks.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Errors with Standard OO Program

Jump to solution

[quote user="Chris Glazier"]Can you please post the source of the program that you are trying to compile?[/quote]

BankMain.cbl:

       PROGRAM-ID. BANKMAIN.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS Account.
           
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 an-object USAGE OBJECT REFERENCE Account.
       
       PROCEDURE DIVISION.
       go-now.
           DISPLAY "Start"
           INVOKE Account "newAccount" RETURNING an-object.
           INVOKE an-object "displayUI".
           SET an-object to NULL.
           GOBACK.
       END PROGRAM BANKMAIN.

Account.cbl:

       CLASS-ID. Account INHERITS Base.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS Base.
           
       FACTORY.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 number-of-accounts PIC 9(5) VALUE ZERO.
       
       PROCEDURE DIVISION.
       METHOD-ID. newAccount.
       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       LINKAGE SECTION.
       01 an-object USAGE IS OBJECT REFERENCE ACTIVE-CLASS.
       PROCEDURE DIVISION RETURNING an-object.
       begin-here.
           INVOKE SELF "new" RETURNING an-object.
           INVOKE an-object "initializeAccount" USING BY CONTENT
               number-of-accounts.
           EXIT METHOD.
       END METHOD newAccount.
       
       METHOD-ID. addAccount.
       PROCEDURE DIVISION.
       method-start.
           ADD 1 TO number-of-accounts.
           EXIT METHOD.
       END METHOD addAccount.
       
       METHOD-ID. removeAccount.
       PROCEDURE DIVISION.
       main-entry.
           SUBTRACT 1 FROM number-of-accounts.
           EXIT METHOD.
       END METHOD removeAccount.
       END FACTORY.
       
       OBJECT.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 account-balance PIC S9(9)V99.
       01 account-number PIC X(9).
       01 the-date PIC 9(8).
       
       PROCEDURE DIVISION.
       METHOD-ID. displayUI.
       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01 in-data.
           03 action-type PIC X.
           03 in-amount PIC S9(9)V99.
           03 in-wrk  PIC X(12).
       PROCEDURE DIVISION.
       method-start.
           DISPLAY "Enter D for Deposit, B for Balance or W for "
               "Withdrawal"
           ACCEPT in-data
           EVALUATE action-type
               WHEN "D"
                   PERFORM get-amount
                   INVOKE SELF "deposit" USING in-amount
               WHEN "W"
                   PERFORM get-amount
                   INVOKE SELF "withdraw" USING in-amount
               WHEN "B"
                   INVOKE SELF "balance"
               WHEN OTHER
                   DISPLAY "Enter valid transaction type."
                   EXIT METHOD
           END-EVALUATE
           EXIT METHOD
           .
       get-amount.
           DISPLAY "Enter amount 9(9).99"
           ACCEPT in-wrk
           COMPUTE in-amount = FUNCTION NUMVAL (in-wrk)
           .
       END METHOD displayUI.
       
       METHOD-ID. balance.
       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01 display-balance PIC $ZZZ,ZZZ,ZZ9.99B-.
       PROCEDURE DIVISION.
       disp-balance.
           MOVE account-balance to display-balance
           DISPLAY "Your Account Balance is:" display-balance
           EXIT METHOD.
       END METHOD balance.
       
       METHOD-ID. deposit.
       DATA DIVISION.
       LINKAGE SECTION.
       01 in-deposit PIC S9(9)V99.
       PROCEDURE DIVISION USING in-deposit.
       make-deposit.
           ADD in-deposit TO account-balance
           EXIT METHOD.
       END METHOD deposit.
       
       METHOD-ID. withdraw.
       DATA DIVISION.
       LINKAGE SECTION.
       01 in-withdraw PIC S9(9)V99.
       PROCEDURE DIVISION USING in-withdraw.
       withdraw-start.
           IF account-balance >= in-withdraw
               SUBTRACT in-withdraw FROM account-balance
           ELSE
               DISPLAY "Your Balance is Inadequate"
           END-IF
           EXIT METHOD.
       END METHOD withdraw.
       
       METHOD-ID. initializeAccount.
       DATA DIVISION.
       LINKAGE SECTION.
       01 new-account-number PIC 9(5).
       PROCEDURE DIVISION USING new-account-number.
       Begin-initialization.
           MOVE ZERO TO account-balance
           MOVE new-account-number TO account-number
           MOVE FUNCTION CURRENT-DATE (1: 😎 TO the-date
           EXIT METHOD.
       END METHOD initializeAccount.
       END OBJECT.
       END CLASS Account.

[quote user="Chris Glazier"]... you should also have this set to use REPOSITORY with UPDATE ON[/quote]

Even with this, the compilation still fails with the two errors I had in my previous post.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Errors with Standard OO Program

Jump to solution

Change the account class so that it uses just the UPDATE ON option of the repository directive and add the as "base" to the CLASS phrase as shown below:

     $set repository "UPDATE ON"
      CLASS-ID. Account INHERITS Base.
      ENVIRONMENT DIVISION.
      CONFIGURATION SECTION.
      REPOSITORY.
          CLASS Base as "base".

Do not use the repository directive for the bankmain.cbl at all.

This worked fine for me...

Thanks.          

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Errors with Standard OO Program

Jump to solution

Thanks for the help!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.