The InterfacingWithStdCOBOL.sln solution contains six projects. There are three pairs of projects, where each pair comprises a C# client console project and a COBOL project. Each client C# project makes a reference to its corresponding COBOL project so that it can use the implicit or explicit COBOL methods that are exposed. This solution is available under the Samples folder. See Start menu > All Programs > Micro Focus Visual COBOL 2010 > Visual COBOL Samples.
The first pair of projects, StdCbl01.*, shows a COBOL program using types that are compatible with C# types. Although this works, it is a somewhat fictitious example, as COBOL modules usually use other data types and more complex structures that don't correspond to .NET types.
The StdCbl01 projects include the following programs:
LINKAGE SECTION. ... 01 F-SBYTE-COMP5 PIC S9(02) COMP-5. *> map to C# sbyte 01 F-SHORT-COMP5 PIC S9(04) COMP-5. *> map to C# short 01 F-INT-COMP5 PIC S9(09) COMP-5. *> map to C# int 01 F-LONG-COMP5 PIC S9(18) COMP-5. *> map to C# long 01 F-COMP1 COMP-1. *> map to C# float 01 F-COMP2 COMP-2. *> map to C# double
This program is procedural COBOL. When you compile it to managed code, you create a class and an instance method is implicitly exposed. The Class and method names are derived from the PROGRAM-ID, StdCbl01. In this way, the program is exposed as a method so that any managed code can use it directly. For example:
PROGRAM-ID. StdCbl01. *> PROGRAM-ID is used both as class name *> and as the only INSTANCE method available
STDCBL01 stdCbl01 = (STDCBL01)Interop.CobLoad("StdCbl01"); COBOLrc = stdcbl01.STDCBL01(ref CSsbyte, ref CSshort, ref CSint, ref CSlong, ref CSfloat, ref CSdouble);