Previous Topic Next topic Print topic


Setting the COBOL Compiler Directives

The ILNAMESPACE Directive

COBOL Compiler directives are statements that determine how the program is compiled and behaves. To ensure that the program in the tutorial executes as expected, you need to set these. To do this, you need to:

  • Alter the program to specify the correct namespace as a qualified program name
  • Alternatively, set a Compiler directive, either globally to the project or in the program using the $SET syntax

For this tutorial you set a global Compiler directive.

You need to specify the ILNAMESPACE directive to ensure that you put the program in the right folder structure, and use the right package. When you import the program into Java, the namespace will then interact correctly with Java packages.

Procedure
  1. Right-click the CobolBook project in COBOL Explorer view, and click Properties.
  2. Expand Micro Focus, and click Build Configuration.
  3. In the Additional directives field, add the line:
    ilnamespace(com.microfocus.book)
  4. Click OK. The project builds.

Checkpoint

This time, the COBOL program is built in the specified namespace. Observe that the file, BookLegacy.class, is now located in the bin/com/microfocus/book folder.

The ILSMARTLINKAGE Directive

In addition, you need to specify the ILSMARTLINKAGE directive to ensure that the linkage between the COBOL program and the Java code is handled correctly. The Micro Focus SmartLinkage tool converts between traditional COBOL group item types and Java types. For example, a field defined as PIC X(99) will be exposed as a Java STRING, and a COMP-5 field will become a Java int. This feature makes calling COBOL programs from Java much easier.

Procedure

  1. Repeat the steps you performed to specify the ILNAMESPACE directive, only this time add the following as another new line in the Additional directives field:
    ilsmartlinkage
  2. Click OK. The project builds.

Checkpoint

You will see additional files in bin/com/microfocus/book. These are LnkBDetails.class, LnkFilename.class, and LnkFileStatus.class. These are classes generated to represent the linkage items in the book.cbl program. The BookLegacy.class file will now have an entry point that takes these wrapper classes rather than just taking a generic reference class that gives direct byte access.

The ILCUTPREFIX Directive

Micro Focus recommends that you specify the ILCUTPREFIX directive. You use this directive to remove any prefixes that may be present in COBOL linkage section data-names. This feature ensures legibility in the generated code.

If you open book.cbl and press F4, you can see the contents of the copybooks in this program. If you navigate down to the linkage section there are group items lnk-filename, lnk-file-status, and lnk-b-details. These map directly onto the generated classes mentioned above.

Procedure

  1. Repeat the steps you performed to specify directives, only this time add the following lines in the Additional directives field:
    ilcutprefix(lnk-b-)
    and
    ilcutprefix(lnk-)
  2. Click OK. The project builds.

Checkpoint

Observe the class files in bin/com/microfocus/book. These files are now called Details.class, Filename.class, and FileStatus.class. Note that the prefixes LnkB and Lnk are no longer present in the class filenames.

The JVMDECIMAL Directive

You need to specify the JVMDECIMAL directive. You use this directive to ensure that COBOL decimal data type is treated as an integer numeric item. The use of this directive is a result of specifying the ILSMARTLINKAGE directive.

Procedure

  1. Repeat the steps you performed to specify the ILNAMESPACE directive, only this time add the following as another new line in the Additional directives field:
    jvmdecimal(scaledinteger)
  2. Click OK. The project builds.
Previous Topic Next topic Print topic