Skip to main content

[archive] Cobol calling Java - return object error

  • December 22, 2008
  • 1 reply
  • 0 views

[Migrated content. Thread originally posted on 22 December 2008]

I solved the problem modifing the signature in the cobol call indicating the esact java object instead of the general Ljava/lang/Object;


CALL "C$JAVA" USING CJAVA-CALL, CONFIG-MODEL,
"xml/ParserConfig", "getVo",
"()Lmodels/Model;",vobject GIVING STATUS-VAL.
-----------------------------------------------------

1 reply

[Migrated content. Thread originally posted on 22 December 2008]

I solved the problem modifing the signature in the cobol call indicating the esact java object instead of the general Ljava/lang/Object;


CALL "C$JAVA" USING CJAVA-CALL, CONFIG-MODEL,
"xml/ParserConfig", "getVo",
"()Lmodels/Model;",vobject GIVING STATUS-VAL.
-----------------------------------------------------
Hi to all,
I have a problem calling method on a java class from cobol.

My java class have some method; one of this return a string:


public String getLastErrorMessage() {
return lastErrorMessage;
}




another method return a java object:

public Model getVo() {
cblLog("Return the vo Object");
return vobject;
}


The signature (javap -s xml/ParserConfig) of the getVo() is:


public models.Model getVo();
Signature: ()Lmodels/Model;




The cobol program look like this:


......
working-storage section.
01 errorMessage-result pic x(255).
01 CONFIG-MODEL USAGE HANDLE.
01 vobject USAGE HANDLE.
01 STATUS-VAL PIC S9(02) VALUE ZERO.
01 boolean-result pic 9.
88 result-false value 0.
88 result-true value 1.

..........
..........
procedure division.
main-logic.
CALL "C$JAVA" USING
CJAVA-NEW, "xml/ParserConfig",
"(Ljava/lang/String;Ljava/lang/String; )V",
fileconfig, nomemodello,
GIVING CONFIG-MODEL.

CALL "C$JAVA" USING CJAVA-CALL, CONFIG-MODEL,
"xml/ParserConfig", "parse", "()Z",
boolean-result GIVING STATUS-VAL.

***** if the parsing return an error show the message
if result-false
CALL "C$JAVA" USING CJAVA-CALL, CONFIG-MODEL,
"xml/ParserConfig", "getLastErrorMessage",
"()Ljava/lang/String;",
errorMessage-result GIVING STATUS-VAL

perform show-err-msg

exit program
stop run
end-if.

CALL "C$JAVA" USING CJAVA-CALL, CONFIG-MODEL,
"xml/ParserConfig", "getVo",
"()Ljava/lang/Object;",vobject GIVING STATUS-VAL.



Calling the last method "getVo" STATUS-VAL return -4 (CJAVA-METHODNOTFOUND) but the method exist.

I think that the problem depends on the object returned from the method, In fact if I replace (only for test) the return object with String like this:

public String getVo() {
cblLog("Return the vo Object");
return vobject.toString();
}

I don't have any problem (status-val=0)

I use the acucobol 7.01 runtime.

Anyone have some solution for this problem?

Thanks in advance.