Exposing COBOL Linkage Data as Managed Types

You can expose the COBOL linkage section and entry points to other managed languages by compiling with the ILSMARTLINKAGE directive.

Some items in the COBOL linkage section and in particular group items are not directly accessible from other languages. In the past, to access these items from other managed languages you had to create intermediate wrapper code, or modify the original COBOL code. You can now expose the linkage section and entry points to other managed languages by compiling with the ILSMARTLINKAGE directive.

For example, a COBOL group item can be defined as:

    linkage section.
        01 lnk-b-details.
            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.

The ILSMARTLINKAGE directive creates a class for each group item and exposes the lower level data items as members of the class. It exposes the data items with hyphens removed and an upper case letter following each removed hyphen. It also exposes COBOL native types as managed types. You can then access the data items in the group as members of the class. For example:

    lnkBDetails.lnkBStockno

The group item is exposed as a string property. 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.

You can remove the prefixes from group item names, by compiling with the ILCUTPREFIX directive. For example, when you compile with ILCUTPREFIX(lnk-b), lnk-b-details is exposed as Details, and you can access the data items, like this:

    Details.Stockno

In summary, to expose group items:

Example:

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

       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 Enterprise Developer samples for more.