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 ...
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.
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.
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.
Destroys the run unit now that it is finished with.