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 properties of the class. For example:
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:
In summary, to expose group items:
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 Java, you can access the data in BookLegacy program in JVM 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-bdetails . . . myDetails.setStockno("6666"); myDetails.setTitle("Managed COBOL"); myDetails.setAuthor("Mike Focus"); myDetails.setType("Reference"); myDetails.setRetail(new ScaledInteger(155, 5)); myDetails.setOnhand(20);