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:

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

...
1       class-id Service as "Service".
        ...
2      set myRunUnit to type RunUnit::new()
3              try
4                 invoke myRunUnit::Call("sum", op1, op2) returning res
               ...       
5              invoke myRunUnit::StopRun(0)              	          
               ...
6              end-try
		         ...

Line 1:

       class-id Service as "Service".

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

Line 2:

set myRunUnit to type RunUnit::new()

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

Lines 3 and 6:

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 AddTwoNumbers() 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