Creating 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.
    
    Note: The use of $set ilnamespace "my.pack", is equivalent to package identification in Java.
    Tip: It is good practice to create a package structure of your preference.
    Restriction: Files that are compiled into a default package are not accessible from Java due to compiler restrictions.