To use the Java and COBOL from within the same project, see COBOL calling Java static method (COBOL/Java Interoperability project).
The Create a Java Project wizard is displayed.
If you are prompted to open the Java perspective, select No. The JStatic project is created. To show both COBOL and Java projects, select the COBOL Explorer view, click (View menu), and then click Filters and Customization. This opens the Filters and Customization dialog box. Click the Pre-set filters tab and uncheck Non-Micro Focus projects, and then click OK.
The program is opened in the editor.
package com.microfocus.java; import java.util.Arrays; public class Demo1 { public static void static1(String[] d) { System.out.println("---Output from Java Demo1.static1 method---"); for (int i = 0; i < d.length; i++) { System.out.println(d[i]); } Arrays.sort(d); } /* select colours from array */ public static String[] static2(int[] s) { System.out.println("---Output from Java Demo1.static2 method---"); for (int i: s) System.out.println(i); String[] rainbow = {"Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"}; String[] ret = {rainbow[s[0]], rainbow[s[1]], rainbow[s[2]], rainbow[s[3]], rainbow[s[4]]}; return ret; } }
If your workspace is set to build automatically, the program is compiled. If the workspace is not set to build automatically, on the Project menu, click Build Project.
The COBOL Project wizard is displayed.
The program is opened in the editor.
$set sourceformat(variable) nsymbol(national) program-id demo1 as "demo1". 78 MAX_OCC value 5. 01 i pic xxxx comp-5. 01 grp2. 03 nat1 pic n(10) national occurs MAX_OCC value n"Red" n"Green" n"Blue" n"Orange" n"Indigo". 01 grp3. 03 utf1 pic u(10) occurs MAX_OCC. 01 grp4. 03 num2 pic xxxx comp-5 occurs MAX_OCC value 1 2 4 5 6. procedure division. *> Sort COBOL array call "java.com.microfocus.java.Demo1.static1" using grp2 display "---Output from COBOL---" perform varying i from 1 by 1 until i > 5 display nat1(i) end-perform *> Select colors of the rainbow from input array *> Careful Java has 0 based array indexes call "java.com.microfocus.java.Demo1.static2" using grp4 returning grp3 display "---Output from COBOL---" perform varying i from 1 by 1 until i > 5 display utf1(i) end-perform. end program demo1.
If your workspace is set to build automatically, the program is compiled. If the workspace is not set to build automatically, on the Project menu, click Build Project.
A new configuration is displayed in the right-hand pane.
Variable | Value |
---|---|
JAVA_HOME | <full-path-to-JRE-used-in-Java-proj> |
CLASSPATH | <fully-qualified-CLASSPATH>:<path-to-Java-proj-output-folder> |
LD_LIBRARY_PATH (or LIBPATH on AIX) | <fully-qualified-LD_LIBRARY_PATH>:<path-to-location-of-libjvm.so> |
---Output from Java Demo1.static1 method--- Red Green Blue Orange Indigo ---Output from COBOL--- Blue Green Indigo Orange Red ---Output from Java Demo1.static2 method--- 1 2 4 5 6 ---Output from COBOL--- Orange Yellow Blue Indigo Violet
The code and the output shows the COBOL code executing the static1 method, processing some COBOL operations, then executing the static2 method, and processing some more COBOL operations.