Working storage variables persisting after class finalized in native code

A class had a method that used WORKING-STORAGE instead of LOCAL-STORAGE.  I created in instance of the class and set a variable in WORKING-STORAGE to a value, then finalized the instance.  I then created a new instance of the class and called the method.  The value from the last instance carried over into the new instance.  Is this expected behavior ?  It behaves the same way in Visual COBOL and Net Express 5.1.

I fixed this by using LOCAL-STORAGE instead of WORKING-STORAGE.

Parents
  • Verified Answer

    Morning,

    The working-storage section is static and shared between all instances, so if you want the field to part of the object-storage and exist in each instance move the field into the "object-storage section".  For example:...

     $SET MFOO LINKCOUNT"1024" ooctrl" p-f"
    
           CLASS-ID. Class1
                     INHERITS FROM AGROBASE
                     WITH DATA.
    
           OBJECT SECTION.
           CLASS-CONTROL.
    
               Class1      IS CLASS "Class1"
               AGROBASE    IS CLASS "AGROBASE"
               .
    
           WORKING-STORAGE SECTION.
    
           CLASS-OBJECT.                           *> Definition of the Class data and method
           OBJECT-STORAGE SECTION.
           END CLASS-OBJECT.
    
          ********************************************************************
           OBJECT.    *> Definition of instance data and methods
          ********************************************************************
    
           OBJECT-STORAGE SECTION.
           01  WS-NEXT-CRIT-CODE         PIC 99999 VALUE ZERO.
    
    
          ********************************************************
           METHOD-ID. "GetNextCritCode".
          ********************************************************
    
           PROCEDURE DIVISION.
    
           010-MAIN.
    
               ADD 1 TO WS-NEXT-CRIT-CODE.
    
               exhibit named WS-NEXT-CRIT-CODE.
               EXIT METHOD.
    
           END METHOD "GetNextCritCode".
    
    
           END OBJECT.
    
           END CLASS Class1.
    
    
Reply
  • Verified Answer

    Morning,

    The working-storage section is static and shared between all instances, so if you want the field to part of the object-storage and exist in each instance move the field into the "object-storage section".  For example:...

     $SET MFOO LINKCOUNT"1024" ooctrl" p-f"
    
           CLASS-ID. Class1
                     INHERITS FROM AGROBASE
                     WITH DATA.
    
           OBJECT SECTION.
           CLASS-CONTROL.
    
               Class1      IS CLASS "Class1"
               AGROBASE    IS CLASS "AGROBASE"
               .
    
           WORKING-STORAGE SECTION.
    
           CLASS-OBJECT.                           *> Definition of the Class data and method
           OBJECT-STORAGE SECTION.
           END CLASS-OBJECT.
    
          ********************************************************************
           OBJECT.    *> Definition of instance data and methods
          ********************************************************************
    
           OBJECT-STORAGE SECTION.
           01  WS-NEXT-CRIT-CODE         PIC 99999 VALUE ZERO.
    
    
          ********************************************************
           METHOD-ID. "GetNextCritCode".
          ********************************************************
    
           PROCEDURE DIVISION.
    
           010-MAIN.
    
               ADD 1 TO WS-NEXT-CRIT-CODE.
    
               exhibit named WS-NEXT-CRIT-CODE.
               EXIT METHOD.
    
           END METHOD "GetNextCritCode".
    
    
           END OBJECT.
    
           END CLASS Class1.
    
    
Children
No Data