ILSMARTLINKAGE

Exposes the linkage section and entry points in procedural COBOL programs to managed code, by creating types.

Syntax:

Restriction: This directive is supported for managed COBOL only.
>>-.---.-.-------ILSMARTLINKAGE---.-------------.--.--------><
   +-/-+ |                        +-"namespace"-+  |
         +-----NOILSMARTLINKAGE--------------------+

Parameters:

namespace
The namespace in which each generated class is grouped

Properties:

Default: ILSMARTLINKAGE
Phase: Syntax check
$SET: Initial
IDE Equivalent: Check Expose group linkage items to managed code on the COBOL tab in the project's properties.

Comments:

This directive exposes group linkage items to managed code. In addition to the class generated as usual for the COBOL program, this directive effectively generates one class for every 01 level group item in the linkage section. Each data item in the group is exposed as a property of this class, where the property is of a standard managed type.

COBOL group items are exposed as string properties. If the group contains non-DISPLAY data (e.g. numeric COMP items), it will not be possible to use the property associated with the group to populate these non-DISPLAY items. In this case, these non-DISPLAY items must be populated using the individual properties associated with these non-DISPLAY items. Use of the ILSMARTRESTRICT directive suppresses generation of properties for group items, meaning that properties are only generated for elementary items.

Hyphens are removed from data item names and the letter following a removed hyphen is folded to upper case. For example a data item author-name is renamed to AuthorName. You can also use the ILCUTPREFIX directive to remove initial portions of the name.

If the original, untransformed, COBOL names are duplicates (and can be made unique in COBOL by the use of qualification), then the property name generated is prefixed with a minimal set of qualifying names to make the resulting name unique, for example, in the case of:

01 link-rec.
   03 a1.
      05 b pic x.
   03 b1.
      05 b pic x.

The property names generated for the two elementary items b are a1_b' and a2_b.

However, if the original COBOL names differed, but only by the presence or absence of a'-' character, or by the presence of a prefix removed by the ILCUTPREFIX directive, then an error message is displayed during compilation (COBCH0842). If you receive such a message, modify the item names to ensure that they will be unique following transformation. For instance the following record layout will result in an error:

01 link-rec.
   03 a-b pic x.
   03 ab  pic x.

If a namespace is specified, all classes generated as a result of this directive are grouped under that namespace.

Compiling with ILSMARTLINKAGE generates classes and types that includes an extra method or a property called .Reference. If you pass such a class or type as a parameter to a program that receives it “by reference”, you need to use the “by reference” object by specifying the .Reference property. This returns an object that encapsulates the SmartLinkage parameter so it is used with a method that is declared "by reference”.

You also need to use .Reference with the RunUnit:Call() method – for example:

myRunUnit.Call("myprogram", myByRefParam.Reference);

Example:

The following COBOL program is compiled with ILSMARTLINKAGE, ILCUTPREFIX(lnk-b-), ILCUTPREFIX(lnk-), and ILSMARTTRIM:

       program-id. BookLegacy.
						 ...
       linkage section.
       01 lnk-function            pic x.
       01 lnk-b-details.
          03 lnk-b-text-details.
             05 lnk-b-title       pic x(50).
             05 lnk-b-type        pic x(20).
             05 lnk-b-author      pic x(50).
          03 lnk-b-stockno        pic x(4).
          03 lnk-b-retail         pic 99v99.
          03 lnk-b-onhand         pic 9(5).
          03 lnk-b-sold           pic 9(5) comp-3.
       procedure division using by value lnk-function
                                by reference lnk-b-details.

In C#, you can access the data in BookLegacy program in .NET COBOL as follows:

    BookLegacy myBook = new BookLegacy(); 
         //creates an object corresponding to the BookLegacy program
    Details myDetails = new Details(); 
         //creates an instance corresponding to the group lnk-b-details 
    . . .          
       myDetails.Stockno = "6666";
       myDetails.Title = "Managed COBOL";
       myDetails.Author = "Mike Focus";
       myDetails.Type = "Reference";
       myDetails.Retail = 15.50M;
       myDetails.Onhand = 20;
       myDetails.Sold = 5;
       myBook.BookLegacy("2", myDetails);
         // calls the BookLegacy method with myDetails, 
         // which corresponds to the group item lnk-b-details

See the C# WinBook demonstration in the Visual COBOL samples for more.