Interop Class

MicroFocus.COBOL.RuntimeServices
Used for interfacing to managed procedural COBOL programs from other .NET languages
Restriction:
MicroFocus.COBOL.RuntimeServices are supported for .NET managed code only.
Inheritance Hierarchy

SystemObject
  MicroFocus.COBOL.RuntimeServicesInterop

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

public static class Interop

The Interop type exposes the following members.

Methods

  NameDescription
Public methodStatic memberCobCall(String)
Calls the instance of a procedural program" with no parameters
Public methodStatic memberCobCall(String, Object)
Calls the instance of a procedural program" with parameters
Public methodStatic memberCobCallObject
Calls the instance of a procedural program" with parameters
Public methodStatic memberCobCancel
Cancels the instance of a procedural COBOL program
Public methodStatic memberCobLoad
Fetches the instance of a procedural COBOL program
Top
Remarks

A procedural COBOL program is represented by a singleton instance of a COBOL class. This instance is maintained by the run-time system. In order to invoke a COBOL method directly from another .NET language it is necessary to first locate this instance using the CobLoad method so that the entry points in it can then be directly invoked as methods. The COBOL program can also be cancelled using the CobCancel method.

In order to invoke a COBOL method you also need to add a reference to the MicroFocus.COBOL.Runtime assembly to your project.

Note:
You should never explicitly instantiate the class of a procedural COBOL program as this can lead to unpredictable behaviour.
Examples

The following example shows a procedural COBOL program being called and then cancelled from another language.

C#:

C#
using Sum;
using System;
using MicroFocus.COBOL.RuntimeServices;

class MainClass 
{
  public static void Main(string[] args) 
  {
   int n1 =3, n2 = 4, n3 = 0;

   SUM sum = (SUM)Interop.CobLoad("SUM");
   sum.SUM(ref n1, ref n2, ref n3);
   System.Console.WriteLine("Total = " + n3);
   Interop.CobCancel("SUM");
  }
}
COBOL, sum.cbl:
cobol
linkage section.
01 val1 pic s9(8) comp-5.
01 val2 pic s9(8) comp-5.
01 val3 pic s9(8) comp-5.

procedure division using val1 val2 val3.
add val1 to val2 giving val3.
exit program.
See Also

Reference