IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Calling Java method from batch COBOL in 64-bit mode


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
danik56

New User


Joined: 08 Mar 2017
Posts: 52
Location: Israel

PostPosted: Mon Nov 20, 2023 1:29 pm
Reply with quote

The IBM COBOL version 6.3 doc states that a 64-bit COBOL program can only call Java using JNI and not via INVOKE.
Can someone point me at some example for using JNI to call Java from a COBOL batch program compiled with LP(64) option ?
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Mon Nov 20, 2023 9:15 pm
Reply with quote

I searched and found this:
www.ibm.com/docs/en/cobol-zos/6.2?topic=methods-example-invoking-java-from-batch-cobol-program
Back to top
View user's profile Send private message
danik56

New User


Joined: 08 Mar 2017
Posts: 52
Location: Israel

PostPosted: Mon Nov 20, 2023 9:50 pm
Reply with quote

Pedro wrote:
I searched and found this:
www.ibm.com/docs/en/cobol-zos/6.2?topic=methods-example-invoking-java-from-batch-cobol-program


This sample code only works in AMODE 31.
If the COBOL program is AMODE 64, the INVOKE command is not supported for calling a Java method.
Only JNI can be used to call Java in Amode 64.
I was looking for sample code where JNI is used to call Java.
Back to top
View user's profile Send private message
danik56

New User


Joined: 08 Mar 2017
Posts: 52
Location: Israel

PostPosted: Fri Dec 29, 2023 2:31 pm
Reply with quote

We made some progress but still having issues.

Here is the JCL we have used to compile & bind a COBOL program that invokes JNI services:

//RUN EXEC IGYQCB,LIBPRFX=CEE,LIBPRF1=CEE,
// PGMLIB='YOSI.TEST.LIB',GOPGM=HLWRLD64
//COBOL.SYSIN DD DSN=Z2V10.SAMP.LIB(CBLB#JNI),DISP=SHR
//COBOL.SYSLIB DD DSN=Z2V10.SAMP.LIB,DISP=SHR
// DD DSN=DANI.SOURCE.LIB,DISP=SHR
//COBOL.SYSLIN DD DSNAME=&&OBJECT(HLWRLD64),
// DISP=(NEW,PASS),SPACE=(CYL,(1,1,1)),DCB=(LRECL=80,RECFM=FB)
//BIND.OBJMOD DD DSN=&&OBJECT,DISP=(OLD,DELETE)
//BIND.SYSLIN DD *
INCLUDE OBJMOD(HLWRLD64)
INCLUDE '/usr/lpp/java/J8.08.15/J8.0_64/bin/j9vm/libjvm.x'
INCLUDE '/usr/lpp/IBM/cobol/igyv6r3/lib/igzcjava.x'
//

The result:

-STEPNAME PROCSTEP RC
-RUN COBOL 00
-RUN BIND 00

Compiler options used: cbl dll,lp(64),rent,pgmname(longmixed)

First JNI call is successfull:

CALL "JNI_CreateJavaVM"
USING JVM-PTR ENV-PTR VM-INIT-ARGS
RETURNING INTO RC2.
RETURNING RC2.

DISPLAY "rc2 " RC2 " " JVM-PTR " " ENV-PTR
IF RC2 NOT = 0
GOBACK
END-IF


The problem we have is related to the 2ed JNI call:


CALL FindClass USING BY VALUE ENV-PTR
CLASS-NAME-PTR
RETURNING MY-CLASS-REF.
DISPLAY "PNT1B"
DISPLAY "1." MY-CLASS-REF.
IF MY-CLASS-REF = 0
GOBACK
END-IF


This call returns null value although the requested java class exists as a jar file in the folder pointed by env
variable CLASSPATH.

There is nothing in STDOUT & STDERR datasets.

My question is how to turn on some tracing options so we can see why the FindClass JNI call is failing.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1255
Location: Bamberg, Germany

PostPosted: Fri Dec 29, 2023 3:40 pm
Reply with quote

Why have you quoted this routine:

CALL "JNI_CreateJavaVM"

but not:

CALL FindClass USING BY VALUE ENV-PTR
Back to top
View user's profile Send private message
danik56

New User


Joined: 08 Mar 2017
Posts: 52
Location: Israel

PostPosted: Fri Dec 29, 2023 7:04 pm
Reply with quote

The JNI block has this field:

02 FindClass function-pointer.

We thought it gets populated after the create JVM call.
Is that incorrect ?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts HILITE on Browse mode? TSO/ISPF 2
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top