To create the Java project from which to run your application:
This opens the New Java Project dialog box.
When you are prompted to open the associated perspective, click No (as we have already configured the COBOL perspective to show non-Micro Focus projects).
In order to see the JVM COBOL code during development, update the project's dependencies:
This opens the Properties for Calc dialog box.
This opens the Required Project Selection dialog box.
You now need to create a new class file to contain the main method:
This opens the Select a wizard dialog box.
This opens the New Java Class dialog box.
This opens the MainClass.java in an editor.
package com.calc; import my.pack.Calculator; public class MainClass { public static void main(String[] args) { Calculator calc = new Calculator(); int result = 0; calc.Calculator(1,2,result); System.out.println(result); } }
long my.pack.Calculator.Calculator(int lnk-arg1, int lnk-arg2, int lnk-sum)The result variable will always be equal to 0 because it uses the by value option for the lnk-sum argument in the procedure division of the Calculator.cbl program. To get a return value, set the variable used for result to be passed as by reference. Modify the procedure division in the Calculator.cbl file to:
procedure division using by value lnk-arg1, by value lnk-arg2, by reference lnk-sum.
At this point you get a problem marker in the editor for the java class.
This opens the Add Library dialog box.
This displays the path to the runtime to be used.
At this point, a problem marker is displayed in the editor for the java class.
The method Calculator(int, int, Reference) in the type Calculator is not applicable for the arguments (int, int, int).
With the next steps you will resolve the issue.
$set ILSMARTLINKAGE "my.pack"
Using this directive results in a new class being created, called LnkSum, which is created in the my.pack package. You can see this in the COBOL Explorer by expanding the Calculator.cbl file:
The Problems view still reports one more issue related to the Calculator method.
(int lnk-arg1, int lnk-arg2, LnkSum my.pack.LnkSum)
Modify the main method in the MainClass.java file:
public static void main(String[] args) { Calculator calc = new Calculator(); LnkSum sum = new LnkSum(); calc.Calculator(1,2,sum); System.out.println(sum.getLnkSum()); }Also, ensure that you add the following import:
import my.pack.LnkSum;
Your projects now compile cleanly.