Configuring the COBOL JVM Project

Create a COBOL JVM Project

To create a new COBOL JVM Project:

  1. Click File > New > COBOL JVM Project.

    This opens the New COBOL JVM Project dialog box.

  2. In the Project name field, type CJVM.
  3. Click Finish.

    The project is displayed in the COBOL Explorer.

Create a New Package

To create a new package:

  1. In the COBOL Explorer, right-click the CJVM project.
  2. Click New > COBOL JVM Package.
    This opens the New COBOL JVM Package dialog box.
    Note: The Source folder field already contains CJVM/src.
  3. In the Name field, type my.pack.
  4. Click Finish.

    This creates my.pack in the src folder.

Create a COBOL Program

Create the following COBOL program in the my.pack package:

  1. In the COBOL Explorer, expand CJVM > src.
  2. Right-click my.pack.
  3. Click New > COBOL Program.

    This opens the New COBOL Program dialog box. The Source folder field already contains CJVM/src. The Package field already contains my.pack.

  4. In the Name field, type Calculator.cbl.
  5. Click Finish.

    This opens the Calculator.cbl program in a COBOL editor.

  6. Copy and paste the following COBOL code into the editor, overwriting the existing text:
          $set ilnamespace "my.pack"
           program-id. Calculator as "Calculator".
    
           data division.
           working-storage section.
           
           linkage section.
           01 lnk-arg1           pic 9(5) comp-3.
           01 lnk-arg2           pic 9(5) comp-3.
           01 lnk-sum            pic 9(5) comp-3.
    
           procedure division using by value lnk-arg1, 
                                    by value lnk-arg2,
                                    by value lnk-sum.
               add lnk-arg1 to lnk-arg2 giving lnk-sum.
               goback.
    
           end program Calculator.
    

    Setting a namespace using the $SET statement, $set ilnamespace "my.pack", is equivalent to package identification in Java.

    Tip: Doing this creates a package structure of your preference. This is a good practice because files that are compiled into a default package are not accessible from Java due to compiler restrictions.
  7. Press Ctrl+S to save and compile the program.
    Note: If the workspace is not configured to build automatically, on the Project menu, click Build Project.