Skip to main content

How do I create a Static Constructor for a COBOL class under .NET?

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

How do I create a Static Constructor for a COBOL class under .NET?

You should NOT use the "new" method in the static paragraph as a static constructor. The "new" method would act as a type of instance constructor and is better used in the object paragraph. Instead, you can code a procedure division directly in the STATIC area (following the declaration of any static data), and you should find the code will get excecuted as a class constructor.

Very simple example:

       class-id. MyClass as "MyClass".

       environment division.

       configuration section.

       repository.

       static.

       working-storage section.

       procedure division.

           display "Hello from class constructor"

       method-id. main.

           display "Hello from main method"

       end method main.

       end static.

       object.

       end object.

       end class MyClass.

Resolution:

You should NOT use the "new" method in the static paragraph as a static constructor. The "new" method would act as a type of instance constructor and is better used in the object paragraph. Instead, you can code a procedure division directly in the STATIC area (following the declaration of any static data), and you should find the code will get excecuted as a class constructor.

Very simple example:

       class-id. MyClass as "MyClass".

       environment division.

       configuration section.

       repository.

       static.

       working-storage section.

       procedure division.

           display "Hello from class constructor"

       method-id. main.

           display "Hello from main method"

       end method main.

       end static.

       object.

       end object.

       end class MyClass.

Old KB# 5182

0 replies

Be the first to reply!