[Migrated content. Thread originally posted on 19 September 2011]COBOL has one of the most extensive type systems of any programming language.
Other languages only support a subset of the types COBOL has to offer, which has made it difficult to access data in existing COBOL applications, without code changes or writing wrapper classes.
SmartLinkage is a feature that was added in Visual COBOL R4 as a “Technology Preview”, to offer an instant solution.
This makes COBOL linkage data access easy from other managed languages, such as C#, Java, VB, COBOL.
We’d like your feedback to help us define the way forward. What would you like to see in terms of usability and functionality?
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".
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;
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
PIC 9(n) n
PIC 9(n) 2
PIC S9(n) 4
PIC 9(n) 4
PIC S9(n) 9
PIC 9(n) 9
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.
Please download Visual COBOL R4 and let us know if you found SmartLinkage useful and how you’d like to see this feature presented in the next release.