Previous Topic Next topic Print topic


Walkthrough the MultiRunUnits Demonstration

The MultipleRunUnits demonstration shows an instance of a procedural COBOL program being run within its own run unit.

The demonstration Web site contains the procedural COBOL program Sum.cbl with a program-ID of sum. When the program is compiled, it is represented as a class that can be instantiated. When the program is used, an instance of the program is created and a run unit is created. The program instance is then run within its new run unit.

The Web site contains the following references, which you can see in the Solution View:

The Web site contains a calling program in COBOL, service.cbl. This has several lines of interest:

        ...
1       class COBOL-RunUnit as "MicroFocus.COBOL.RuntimeServices.RunUnit"
        ...
2       invoke COBOL-RunUnit::"New" returning MyRunUnit
3       try
4          invoke MyRunUnit::"Call"("AddNumbers", op1, op2) returning res
           ...
5       end-try
        ...
6       invoke MyRunUnit::"StopRun"(0) 

Line 1:

    class COBOL-RunUnit as "MicroFocus.COBOL.RuntimeServices.RunUnit"

Defines the class that is used on line 2. Notice that MicroFocus.COBOL.RuntimeServices is included in the project references.

Line 2:

invoke COBOL-RunUnit::"New" returning MyRunUnit

Creates a run unit using the support in the MicroFocus.COBOL.RuntimeServices assembly.

Lines 3 and 5:

try
...
catch

Ensures that the run unit is destroyed even if the called program fails.

Line 4:

invoke MyRunUnit::"Call"("sum",op1, op2) returning res

Implicitly creates an instance of the AddNumbers() method and then calls it within the new run unit. The parameters are passed by reference and automatically marshalled to match the data types used in the called program.

Line 6:

invoke MyRunUnit::"StopRun"(0)

Destroys the run unit now that it is finished with.

Note: You can use C# or any .NET language to call COBOL in a similar way as the above program calls COBOL. For some examples, see the Help on the MicroFocus.COBOL.RuntimeServices assembly: RunUnit Class.
Previous Topic Next topic Print topic