Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

C#/Java COBOL interop made easy with SmartLinkage

C#/Java COBOL interop made easy with SmartLinkage

SmartLinkage – what does it do?

Prior to R4, if you wanted to call a COBOL program from another language, you had to create wrapper functions to convert the COBOL data items to managed types. SmartLinkage does that for you, so you can access COBOL linkage data from other managed languages transparently.

– No hand-written wrapper classes needed

– No changes required to the original code

– COBOL data shown in C#/Java/COBOL intellisense 

Easy configuration steps

Project1 (COBOL)

– Create a managed project and add COBOL code

– Compile with the ilsmartlinkage directive

Project2 (eg C#)

– Create a C# project in the same solution

– Add a project reference to Project1

– Add a reference to MicroFocus.COBOL.Runtime (unless Project2 is COBOL)

– Now you can access Project1’s linkage data directly 



– hyphens are removed from COBOL data names and the following letter upper-cased

   eg lnk-details is accessed from C# as lnkDetails 

ilcutprefix(x) directive

– Allows you to configure data item names

– Strips the text x from the front of the COBOL name

  eg ilcutprefix(lnk)
  lnk-details is accessed from C# as Details 


Each 01 group linkage item is exposed as a class with subordinate fields exposed as properties.
For example, in the following COBOL program, compiled with the ilsmartlinkage directive, a class is created for the lnk1 linkage item that contains 2 properties, a string and an int. 

  program-id program1 as "program1".
  linkage section.
  01 lnk1.
     03 sub-lnk1 pic x(20).
     03 sub-lnk2 pic 9(5).
  procedure division using by reference lnk1.

My calling C# program:

  program1 myProg = new program1();
  lnk1 myLinkage = new lnk1();
  myLinkage.subLnk1 = “myString”;
  myLinkage.subLnk2 = 1234;

Type Mapping

Compiling a COBOL program with ilsmartlinkage directive exposes the COBOL data items as the following types on .NET & JVM.

COBOL                    C# types         Java types
PIC X(n)                 string           String
PIC S9(n) n <= 2         sbyte            byte
PIC 9(n) n <= 2          byte             byte
PIC S9(n)2 < n <= 4      short            short
PIC 9(n) 2 < n <= 4      ushort           short
PIC S9(n) 4 < n <= 9     int              int
PIC 9(n) 4 < n <= 9      uint             int
PIC S9(n) 9 < n <= 19    long             long
PIC 9(n) 9 < n <= 19     ulong            long
PIC 9(n)V9(m)            decimal          ScaledInteger
PIC S9(n)V9(m)           decimal          ScaledInteger
COMP-1                   float            float
COMP-2                   double           double
PIC Z9 (any numeric edited) string        String
PIC A(n)                 string           String
Group item               string           String

For more information :

Free download of Visual COBOL R4

• See the “C# WinBook” sample in Visual COBOL for Visual Studio R4
This shows a C# WinForm using SmartLinkage to access COBOL legacy program data directly. 

• You can see a demo of this technology in a recent webinar - “Visual COBOL for Visual Studio R4 – Migrating from Net Express”.
The demo takes a Net Express application, moves it to Visual COBOL for Visual Studio. Then modernizes the front–end with a COBOL WinForm using SmartLinkage.


Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Version history
Revision #:
1 of 1
Last update:
‎2012-06-21 16:58
Updated by:
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.