Receiving Java custom record in procedural cobol


We want to share a Cobol Structure between our Cobol program and a new Java Program.

The Cobol program will call the Java program.

We have succeeded running simple examples exchanging simple data type beteen Cobol and Java. We have failed so far with the CustomRecord data type.

Here is our Java CustomRecord class:

import com.microfocus.cobol.lang.*;

public class TPrestInter implements CustomRecord, {

private static final long serialVersionUID = 827363353239593196L;
private long noEmployeur;

public Object[] getParameters(){
return new ParameterList()

public void setParameters(Object[] params) {
Byte[] byteNumeroEmployeur = (byte[]) params[0]);
setNoEmployeur (Integer.parseInt(new String(byteNumeroEmployeur));

public Long getNoEmployeur() {
return this.noEmployeur;

public void setNoEmployeur(Long noEmployeur) {
this.noEmployeur = noEmployeur;

Here is the Java class That generates custom record objects

public class LireTPrestInt {

public TPrestInter getObject(){
TPrestInter object = new TPrestInter();
return object;

Here is the Cobol program

$set ooctrl( p-f)
identification division.
program-id. Program1.

environment division.
configuration section.

class java-tprestint as "$java$TPrestInter"
class lire-tprestint as "$java$LireTPrestInt".

data division.
working-storage section.

01 obj-lire-tprest-int object reference.
01 tprest-int-struct.
03 numero-employeur pic 9(3).

01 x1 pic s9(18) comp-5.
01 x2 pic s9(18) comp-5.
01 x3 pic s9(18) comp-5.

01 x pic x(80).

procedure division.

display "Test Cobol <-> Java".

invoke java-tprestint "new" returning obj-java-tprestint.

invoke obj-java-tprestint "getNoEmployeur" returning x1.
exhibit named x1.

move 987 to x1.
invoke obj-java-tprestint "setNoEmployeur" using x1.

invoke lire-tprestint "new" returning obj-lire-tprest-int.

invoke obj-lire-tprest-int "getObject" returning tprest-int-struct.

exhibit named numero-employeur.


end program Program1.

The call to method "getObject" fails with the following exception:

Exception 65538 not trapped by the class javaexceptionmanager.

Description: "Java runtime exception"

Method 'getObject' with signature Ljava/lang/String; not found

Thanks in advance for your help.

Guy Fokou

  • What version of Visual COBOL are you using?

    In the more recent versions of Visual COBOL it is not necessary to use the class repository. You could code as follows:

    01 objLireTPrestInt type LireTPrestInt.

    01 objTPrestInter type TPrestInter.

    In your code:

    set objLireTPrestInt to new LireTPrestInt.

    set obj-lire-tprest-int  to new objLireTPrestInt::getObject()

  • Mike, this looks like native OO COBOL rather than COBOL JVM.

    Guy, would compiling to COBOL JVM be an option for you? Integration between COBOL and Java is considerably easier if you can compile you COBOL code directly to Java byte code using Visual COBOL.