RunUnit Class

MicroFocus.COBOL.RuntimeServices
Represents a COBOL run unit in which the programs executed are either procedural COBOL programs that are compiled for use in multiple run units or Micro Focus OO COBOL programs.
Restriction:
MicroFocus.COBOL.RuntimeServices are supported for .NET managed code only.
Inheritance Hierarchy

SystemObject
  MicroFocus.COBOL.RuntimeServicesRunUnit
    MicroFocus.COBOL.RuntimeServices.GenericRunUnitProgramOrClass
    MicroFocus.COBOL.RuntimeServicesSession

Namespace:  MicroFocus.COBOL.RuntimeServices
Assembly:  MicroFocus.COBOL.RuntimeServices (in MicroFocus.COBOL.RuntimeServices.dll) Version: 1.2.3.4
Syntax

public class RunUnit : IRunUnit, IDisposable

The RunUnit type exposes the following members.

Constructors

  NameDescription
Public methodRunUnit
This constructor initializes a new COBOL Run Unit
Public methodCode exampleRunUnit(String)
This constructor initializes a new named COBOL Run Unit
Public methodCode exampleRunUnit(String, RunUnitStartupOptions)
This constructor initializes a new named COBOL Run Unit with a set of specified startup options.
Top
Properties

  NameDescription
Public propertyCode exampleActive
Gets a bool to show if the rununit is active or not.
Public propertyCode exampleCommandLine
Sets the command line for the programs executing in the RunUnit
Public propertyStatic memberDefaultRunUnit
Gets the default run unit
Public propertyCode exampleDiagnosticStatus
Returns a Diagnostic message about the status of this rununit
Public propertyCode exampleGUID
Gets the GUID for this rununit
Public propertyCode exampleRunUnitID
Gets a unique long to identify this rununit
Public propertyCode exampleSwitches
Sets the switches for the programs executing in the RunUnit
Top
Methods

  NameDescription
Public methodCode exampleAdd
Adds a new instance of a Procedural COBOL program or Object COBOL Class to the session.

This method is only required if you need to instantiate the class outside of the session
Public methodCode exampleCall(String)
Executes a program in the new run-unit with no parameters
Public methodCode exampleCall(String, Object)
Executes a program in the new run-unit with a set of parameters
The parameters are currently restricted to objects or native IL types
Public methodCode exampleCallObject
Executes a program in the new run-unit with a set of parameters
The parameters are currently restricted to objects or native IL types
Public methodCode exampleCancel
CANCEL's a program
Public methodContainsUserData
Checks if a name is bound to this rununit
Public methodDispose
Dispose method for IDisposable interface which invokes StopRun
Public methodCode exampleEnter
Associate the current thread with a RunUnit

Public methodCode exampleGetBytes
Gets the byte[] for a string in the charset of program
Public methodCode exampleGetBytesCount
Gets the length/size of a byte[] for a string in the charset of program
Public methodCode exampleGetEnvironmentVariable
Gets the contents of the specified environment variable
Public methodCode exampleGetInstance(Type)
Given a Type object return the programs instance if the RunUnit knows about it. If an instance does not already exist this call will return null.
Public methodCode exampleGetInstance(Type, Boolean)
Given a Type object return the programs instance if the RunUnit knows about it. If create is true then GetInstance will create an instance of programType if it doesn't already have one. Otherwise it will return null should an instance not exist.
Public methodCode exampleGetString(Object, Byte)
Gets a string that matches the charset of the program
Public methodCode exampleGetString(Object, Byte, Int32, Int32)
Gets a string that matches the charset of the program using an index/count
Public methodCode exampleGetUserData
Returns the object bound with the specific name to the rununit
Public methodCode exampleIsCOBOLProgram
Given a Class object return true if the Class contains anything that is CALLable.
Public methodCode exampleSetEnvironmentVariable
Sets the contents of specified environment variable to the value given.
Public methodCode exampleSetUserData
Binds an object to this rununit using the name specified
Public methodStopRun
Terminates the Run Unit
Public methodStopRun(Int32)
Terminates the Run Unit using the supplied return code value
Public methodToString
Returns a text summary of the status of the rununit.
(Overrides ObjectToString.)
Top
Remarks

A RunUnit is a container that can be used to isolate and manage multiple application instances executing within the same .NET application domain. Execution of a RunUnit is thread-safe in relation to any other run unit objects running in other threads.

After you have created a run unit, there are two alternative ways to start execution of the COBOL code within that run unit. You use the Add method to execute OO COBOL programs, and you use either the Add method or the Call method for programs that are compiled for multiple run units.

Note:
If you are using OO COBOL or any other .NET language, be aware that static methods and data are shared with all programs executing in the current run unit. If you use static methods and data, you might need to synchronize access to the data.
Examples

The following examples show a run unit (myRunUnit) being created and the COBOL Program1 being called. When the program is called, it is implicitly instantiated and then run within the new run unit. Next, a second program (Program2) is called without any parameters

Finally the run unit is destroyed.

Create a run unit for the called COBOL program
MicroFocus.COBOL.RuntimeServices.RunUnit myRunUnit = 
      new MicroFocus.COBOL.RuntimeServices.RunUnit();
 try
 {
   // Call the COBOL program
   result = myRunUnit.Call("Program1", "Alice", 21);
   result2 = myRunUnit.Call("Program2");
 }
 finally
 {
   // Destroy the run unit
   myRunUnit.StopRun();
 }

The following COBOL example shows the same as the above example, but in addition it shows an array of parameters being set up to be passed to the called program.

COBOL:

cobol
 environment division.
 configuration section.
 repository.
  class cls-RunUnit as "MicroFocus.COBOL.RuntimeServices.RunUnit" 
   . 
working-storage section.
01 myRunUnit object reference cls-RunUnit.
01 my-params object reference occurs any.
procedure division.
  set size of my-params to 2
  set my-params(1) to "Bob"
  set my-params(2) to 32

  *> Create a run unit for the called COBOL program
  invoke cls-RunUnit "new" returning myRunUnit
  try
        *> Call the COBOL method and implicitly instantiate it
        invoke myRunUnit::"Call"("Program1", my-params)
        invoke myRunUnit::"Call"("Program2")
  finally
        *> Destroy the run unit
        invoke myRunUnit::"StopRun"()
  end-try
cobol
program-id. Program1.
working-storage section.
procedure division using by value lnk-string as string
                         by value lnk-age as binary-double.

  display "Hello " lnk-string::Trim() ", you are " lnk-age " years old"
  goback.
end program Program1.
cobol
program-id. Program2.
working-storage section.
procedure division.
  display "Hello from COBOL".
  goback.
end program Program2.
See Also

Reference