Object COBOL?


I have a need to use some object oriented facilities. For various reasons I cannot use .NET or JVM. I was looking into ISO2002 Object COBOL.

First, is ISO2002 Object COBOL recommended? Is it deprecated? There is only limited documumentation delivered with VC.

Second, are there any samples available?

Third, I have a have a simple (very simple) set of code that compiles but fails when run.

The code is:

       class CharacterArray.
       01      w-string    object.  
           invoke CharacterArray "new" returning w-string.

The error is "Called program file not found in drive/directory: CHARACTERARRAY" on the invoke. Any insights on this?

Many thanks,


  • Verified Answer

    Visual COBOL still contains support for the previous native OO syntax such as the Micro Focus syntax using the CLASS-CONTROL or the ISO2002 syntax but it has been deprecated and is included for compatibility with older products like Net Express. It is therefore not documented as you have found out. These formats of OO COBOL are extensively documented within the Net Express product and most of the features still apply under Visual COBOL, for native code projects only.

    We highly recommend for any new OO COBOL programming that you take advantage of the new streamlined syntax available in managed code. What is it exactly that is keeping you from using the managed syntax?

    There is documentation on the native class libraries such as base, OLE, and GUI in a separate docs file on disk under

    C:\program files (x86)\micro focus\visual cobol for visual studio nnnn\help\nxrclr.chm.

    If you look up the characterarray class and the new method you will see that it is expecting length parameter to be passed to the method which you are missing. You also need to equate the class name to the physical class name as shown in the following example:i

               class CharacterArray as "chararry".
           working-storage section.
           01 w-string    object reference.  
           01 lnksize     pic 9(9) comp-5  value 20.
           procedure division.
               invoke CharacterArray "new" using lnksize returning w-string
  • Chris,

    This is a lagacy migration environment, not a new development. A relatively small part of that migration involves generating COBOL as a replacement for a scripting language present in the legacy platform. This generates COBOL needs to share resources with the COBOL from the legacy application. In fact, the generated COBOL needs to run in the same run-unit as the legacy COBOL so that it can share files and external data areas. Also, for technical reasons the migrated application will be maintained on Windows as deplayed to Linux. The intention is to use native code projects.

    In this scenario is seems that the previous MF or ISO2002 is the only option.

    Am I right in that assumption?


  • What is the actual requirement that you have to use OO COBOL syntax? Is the Legacy application currently written using OO syntax? If you need to share open files or external data with an existing  procedural COBOL application then I would recommend that you generate the new code as procedural COBOL as well.

    If you are developing an OO COBOL application on Windows but deploying it under Linux then you will have to be careful with which class libraries you are working as some of them are Windows specific.

    Can you provide some more detail on the actual problem that you are trying to solve here?


  • Chris,

    There is no OO in the legacy application.

    The legacy application includes a scripting language that we convert to COBOL (so that it can run in the same run-unit as the COBOL). The scripting language has string variables that are variable in length.

    In the COBOL code that we convert the scripting to the strings are defined as follows:

    01  <name>.

      03  <name>-length pic 9(9) comp.

      03  <name>-data pic x occurs 0 to 256 depending on <name>-length.

    Manipulating these strings then becomes two operations: set the length, set the data.Like so:

        move 4 to <name>-length

        move "ABCD" TO <name>-data.

    Also, for some reason, when these strings are passed to COBOL subroutines the length and data are passed as separate argumements.

    I was looking for some way of making this a little easier to handle.


  • What is it that requires a variable length string? Are you calling a 3rd party API or accessing a database, etc.

    If you are interacting with another language like C you would normally NULL terminate the string using Z"ABCD" or something to that effect.

    The group item that you are defining is not a special construct in COBOL. It does not inherently mean a variable length string. How are you passing this to the subprograms?

  • Chris,

    The strings in the original scripting language are variable length. We have converted this scripting language to COBOL. The authors of the conversion emulated variable length strings in the way that I have described. There are no APIs other than our own.

    There's no C in the solution, only COBOL.

    The 'strings' are currently passed to subroutines as two arguments, one for the length and one for the data. There may be a reason why we don't just pass the group item, but I don't know what it is.

    This all seems rather laborious for a relatively recent design. I was looking for a more advanced (aka interesting) approach. As I said, going managed is probably too risky at the moment. Will the native OO be withdrawn or just deprecated?


  • Verified Answer

    The native OO syntax is still supported for compatibility with existing systems but it is not fully documented in the Visual COBOL documentation. If you wish to use this syntax then you should probably use the Net Express documentation as a reference.