In the InterfacingWithStdCOBOL.sln solution, 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:
Lines 21-31
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:
Line 12:
PROGRAM-ID. StdCbl01. *> PROGRAM-ID is used both as class name *> and as the only INSTANCE method available
PROGRAM-ID. StdCbl01 AS “StdCbl01”
Line 37:
STDCBL01 stdCbl01 = (STDCBL01)Interop.CobLoad("StdCbl01"); COBOLrc = stdcbl01.STDCBL01(ref CSsbyte, ref CSshort, ref CSint, ref CSlong, ref CSfloat, ref CSdouble);