Restriction: |
---|
MicroFocus.COBOL.RuntimeServices are supported for .NET managed code only. |
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
The RunUnit type exposes the following members.
Name | Description | |
---|---|---|
RunUnit |
This constructor initializes a new COBOL Run Unit
| |
RunUnit(String) |
This constructor initializes a new named COBOL Run Unit
| |
RunUnit(String, RunUnitStartupOptions) |
This constructor initializes a new named COBOL Run Unit with a set of specified startup options.
|
Name | Description | |
---|---|---|
Active |
Gets a bool to show if the rununit is active or not.
| |
CommandLine |
Sets the command line for the programs executing in the RunUnit
| |
DefaultRunUnit | Gets the default run unit | |
DiagnosticStatus |
Returns a Diagnostic message about the status of this rununit
| |
GUID |
Gets the GUID for this rununit
| |
RunUnitID |
Gets a unique long to identify this rununit
| |
Switches |
Sets the switches for the programs executing in the RunUnit
|
Name | Description | |
---|---|---|
Add |
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 | |
Call(String) |
Executes a program in the new run-unit with no parameters
| |
Call(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 | |
CallObject |
Executes a program in the new run-unit with a set of parameters
The parameters are currently restricted to objects or native IL types | |
Cancel |
CANCEL's a program
| |
ContainsUserData | Checks if a name is bound to this rununit | |
Dispose |
Dispose method for IDisposable interface which invokes StopRun
| |
Enter |
Associate the current thread with a RunUnit
| |
GetBytes |
Gets the byte[] for a string in the charset of program
| |
GetBytesCount |
Gets the length/size of a byte[] for a string in the charset of program
| |
GetEnvironmentVariable |
Gets the contents of the specified environment variable
| |
GetInstance(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.
| |
GetInstance(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.
| |
GetString(Object, Byte) |
Gets a string that matches the charset of the program
| |
GetString(Object, Byte, Int32, Int32) |
Gets a string that matches the charset of the program using an index/count
| |
GetUserData | Returns the object bound with the specific name to the rununit | |
IsCOBOLProgram |
Given a Class object return true if the Class contains anything that is CALLable.
| |
SetEnvironmentVariable |
Sets the contents of specified environment variable to the value given.
| |
SetUserData | Binds an object to this rununit using the name specified | |
StopRun |
Terminates the Run Unit
| |
StopRun(Int32) |
Terminates the Run Unit using the supplied return code value
| |
ToString |
Returns a text summary of the status of the rununit.
(Overrides ObjectToString.) |
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. |
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:
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
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.
program-id. Program2. working-storage section. procedure division. display "Hello from COBOL". goback. end program Program2.