0

I'm trying to communicate Java and Cobol. I need to call a Java program (with paramaters) from Cobol.

I read some documentation from Microfocus: http://supportline.microfocus.com/documentation/books/nx40/dijafc.htm http://supportline.microfocus.com/documentation/books/nx40/dijaco.htm

But I didn't find a real solution, because I need to call an entire program and not a Java Class.

Thanks in advance.

gcotis
  • 107
  • 2
  • 15

2 Answers2

1

The link you posted explains very well about how we can instantaite a java class. If you are concerned about parameters, then write the Java Class with parameteric constructor and pass the parameters while you instantiate the Class from Cobol.

If you are confused about Java Class and Java Program, then you need to know that Java programs are compiled into .class files at the most you have executable jars containing .class files. But there is nothing like .exe for java.

Smitt
  • 178
  • 7
  • The knowledge of Java it's not the problem. I know how to instantiate the Class from Cobol. But I need to share a Java Object between Java and Cobol, and to do a call from a Java method from Cobol. – gcotis Mar 04 '14 at 12:36
  • Sorry I did not mean much about java there, I edited my answer. Do you mean that there is one Cobol program running and One java program running and you want the refference to the Java object from the running Java program into the Cobol program. – Smitt Mar 04 '14 at 13:40
  • 1
    @gcotis; Take a look at SWIG (Simplified Wrapper and Interface Generator), JNI (Java Native Interface) and JNA (Java Native Access). But I'd say that Micro Focus page has all the details you need. In particular the blurb on com.microfocus.cobol.CobolBean and probably great hints in the array sample. – Brian Tiffin Mar 04 '14 at 16:39
1

Below is a sample program that will launch an EXE from within a COBOL97 application.

Check CallEXE demo in http://www.netcobol.com/support/code-samples/


When it comes to Microfocus...

One can not CALL an EXE from a Micro Focus INT or GNT, but you can CALL a Non-mainframe program (Micro Focus dialect in MFE) and issue a shell to DOS and from there either execute a command line that executes the EXE or execute the EXE file directly passed on the Micro Focus CALL (x'91' function code =35).

Also, you will not get back any passed parameters since once the DOS shell is closed, no parms can be returned. So the best way to get parms back is to write them to a file.

I am including a sample program that shows this x'91' FC=35 call. As you can see, you can execute a batch file or a command or an EXE directly.

Working-Storage Section.

1  Cmd-Line-Str.

 2              Pic X(45)

  *      value 'RUN $IMSDIR\PCIMS RUNIMS BMP,DBUTIL,DEMO001T'.

  *      value 'run lorince'.

     value 'dir c:\ /o > d.d'.

2   N-1         Pic X Value Low-Value.

   1   Call-Func    Pic X Comp-X Value 35.

   1   Result       Pic X Comp-X.

   1   Cmd-Line-Len Pic X Comp-X Value 0.

   Procedure Division.

   P1.

   Display Cmd-Line-Str upon Command-Line

   Call x'91' using Result, Call-Func, Cmd-Line-Len

   If Result = Zeroes

      Display 'Call worked'

   End-If

    Goback.   

I hope the post gives you some more information, I have only mainframe knowledge and haven't tried any of this above.

MrSimpleMind
  • 7,890
  • 3
  • 40
  • 45