COBOL

Expand all | Collapse all

Call Java Pgm on MVS

  • 1.  Call Java Pgm on MVS

    Posted Fri January 06, 2023 10:21 AM
    Hello,
    could you please point me to an example how to call a Java Pgm from COBOL 6.4 and how to compile thie COBOL program. We are especially interested into the example on MVS and not on USS. We already had a look to the USS solution but this is currently of no use for us. Therefore we would highly appreciate an example using the MVS COBOL 6.4 compiler. A JCL would be great.
    Regards
    Guido

    ------------------------------
    Guido THelen
    ------------------------------


  • 2.  RE: Call Java Pgm on MVS

    Posted Mon January 09, 2023 09:24 AM

    Hi Guido,

     

    An official sample showing how to use JCL to build Java interoperability components will be available shortly via PH51752, currently scheduled for the January month-end PTF.

     

    However, the userid doing the building will still need to have an OMVS segment, there's no escaping that, as Java needs USS facilities to run.

     

    Bernie

     

    PH51752: NEW SAMPLE JCL TO BUILD/RUN NON-OO COBOL/JAVA INTEROPERABLE APPLICATIONS FROM JCL

    https://www.ibm.com/support/pages/apar/PH51752

    _________________________________________

    Bernie Rataj

    Senior Software Developer

    Enterprise COBOL & PL/I for z/OS Technical Support

     






  • 3.  RE: Call Java Pgm on MVS

    Posted Mon January 09, 2023 09:36 AM
    My apologies, just found out the sample isn't going to be delivered with the January PTF, but some time later, yet to be decided.
    You can get the sample by opening a case and requesting it.

    ------------------------------
    Bernie Rataj
    Senior Software Developer
    IBM Canada Ltd.
    Markham ON Canada
    https://www.ibm.com/marketplace/ibm-compilers
    ------------------------------



  • 4.  RE: Call Java Pgm on MVS

    Posted Wed February 08, 2023 11:52 AM
    Hi Bernie,
    many thanks for your answer. 
    We will give it a try. 
    Just need to figure out how I can find the example. I am not familar yet with IBM's APAR system. I opened the APAR link from above but I do not find an example anywhere. What am I missing?
    Regards
    Guido

    ------------------------------
    Guido THelen
    ------------------------------



  • 5.  RE: Call Java Pgm on MVS

    Posted Thu February 09, 2023 09:42 AM

    Hi Guido,

    The delivery was delayed to the February month-end PTF. The APAR will note:

    New sample JCL demonstrating how a non-OO COBOL/Java
    interoperable application can be built and run entirely using
    JCL is provided.

    The sample JCL is available in the SIGYSAMP data set of the
    compiler (see member IGYCJDMJ) and is also available in the zFS
    install directory as file

    demo/cobol_java_interop_sample/cobprod.jcl

    For more information, please refer to the following sections in
    the Enterprise COBOL for z/OS 6.4 IBM Documentation online:

    Enterprise COBOL for z/OS 6.4
      -> Programming Guide
        -> Compiling and debugging your program
          -> Compiling, linking, and running non-OO COBOL
             applications that interoperate with Java
            -> Sample JCL for building and running the COBPROD
               application

    Bernie

    https://www.ibm.com/support/pages/fix-list-and-new-features-enterprise-cobol-zos



    ------------------------------
    Bernie Rataj
    Senior Software Developer
    IBM Canada Ltd.
    Markham ON Canada
    https://www.ibm.com/products/cobol-compiler-zos
    https://www.ibm.com/products/pli-compiler-zos
    ------------------------------



  • 6.  RE: Call Java Pgm on MVS

    Posted Thu February 09, 2023 10:38 AM
    Edited by Guido THelen Thu February 09, 2023 10:39 AM

    Hi Bernie, thanks for your answer. The example you are referring to is a COBOL program compiled on USS using the cjbuild utility. But we are looking for a JCL compiling the COBOL pgm on MVS. We want to run a COBOL program on MVS which is calling a JAva program.

    Regards

    Guido



    ------------------------------
    Guido THelen
    ------------------------------



  • 7.  RE: Call Java Pgm on MVS

    Posted Thu February 09, 2023 05:19 PM

    Hi Guido,

    The cjbuild utility can be used to generate interface code to go either from COBOL to Java, or Java to COBOL.

    In either case, the Java parts MUST reside in the USS filesystem. What the example does is to let you use cjbuild at arm's length via JCL, rather than requiring you to use the OMVS command or an SSH session to do so, though it will still require the userid doing the building to have an OMVS segment in RACF (or whatever security system you're using).

    Once built, you can run your COBOL program from a regular job step, given the appropriate STEPLIB, libpath, classpath and so forth.

    Bernie



    ------------------------------
    Bernie Rataj
    Senior Software Developer
    IBM Canada Ltd.
    Markham ON Canada
    https://www.ibm.com/products/cobol-compiler-zos
    https://www.ibm.com/products/pli-compiler-zos
    ------------------------------



  • 8.  RE: Call Java Pgm on MVS

    Posted Fri February 24, 2023 05:25 AM

    Hi Bernie,

    thanks. We will give it a try.

    Regards

    Guido



    ------------------------------
    Guido THelen
    ------------------------------



  • 9.  RE: Call Java Pgm on MVS

    Posted Mon February 27, 2023 03:14 AM

    Hi Bernie, after a first look to the JCL I see that the COBOL compiler used to compile the COBOL program resides in USS

    //  SET  IGYHOME='/home/tremain/cobol2/igyv6r4'          

    Is there a possibility to use the MVS COBOL Compiler?

    Why do we need to compile the COBOL program in USS?

    Regards

    Guido



    ------------------------------
    Guido THelen
    ------------------------------



  • 10.  RE: Call Java Pgm on MVS

    Posted Mon February 27, 2023 10:32 AM

    Hi Guido,

    Apologies that it appears that the path we show here is not the more general path we intended (my fault).  I intended it to say '/usr/lpp/cobol/igyv6r4' but ulitmately it should be set to wherever your z/OS UNIX installation directory is located for your Enterprise COBOL compiler.

    The artifact files that the COBOL compiler generates when you use the new Java interoperability feature must be located on the z/OS UNIX file system.  Those files must be compiled into a DLL using the cjbuild utility, which is a Java program and is intended to be  run from z/OS UNIX .  However, as we show in our upcoming sample JCL to be released any day now, you can easily run cjbuild from JCL using the BPXBATCH utility.  I recommend waiting to see that sample JCL.

    The idea for users is that they should be able to build their user programs in the same way they did previously, but they should delay the linking step until cjbuild has built the DLL for the application, as the user programs may need to link against the side deck for that DLL.

    The cjbuild utility takes care of invoking the Enterprise COBOL compiler via cob2, so you don't need to be involved in that, other than to tell the JCL where the z/OS UNIX install directory is.  And you can tell cjbuild to output the DLL it produces to a data set, just like you can continue to output the user COBOL program objects in the application into a data set, so there is nothing on the z/OS UNIX file system that is being used at run time -- unless you want it to (e.g., you can also let the DLL be output to a z/OS UNIX directory, in which case at run time you would need to have the directory that holds that DLL in your LIBPATH environment variable).  It's all up to you.


    Please let me know if you need more info.  I am very interested in helping users make progress with this feature.

    Thank you.

    David



    ------------------------------
    David Tremaine
    Senior Software Developer
    IBM Canada Ltd.
    ------------------------------



  • 11.  RE: Call Java Pgm on MVS

    Posted Fri March 03, 2023 09:31 AM

    Hi David,

    these are great news. We are preparing our USS environment with the new COBOL6.4 compiler and will give your example a try once it will be available

    Regards

    Guido



    ------------------------------
    Guido THelen
    ------------------------------



  • 12.  RE: Call Java Pgm on MVS

    Posted Fri March 17, 2023 04:18 AM

    Hi Bernie, any idea when the sample JCL will be available?

    Regards

    Guido



    ------------------------------
    Guido THelen
    ------------------------------



  • 13.  RE: Call Java Pgm on MVS

    Posted Fri March 17, 2023 04:27 AM

    Hi Bernie,

    sorry, the question should have gone to David. :-)

    Regards

    Guido



    ------------------------------
    Guido THelen
    ------------------------------



  • 14.  RE: Call Java Pgm on MVS

    Posted Fri March 17, 2023 11:41 AM

    OK, finally I found the example JCL here: Sample JCL for building and running the COBPROD application - IBM Documentation

    Sorry for the confusion

    REgards

    Guido



    ------------------------------
    Guido THelen
    ------------------------------



  • 15.  RE: Call Java Pgm on MVS

    Posted Mon March 20, 2023 11:42 AM

    Hi Guido,

    Yes, the sample is now available.  I'm glad you found it.  Please let us know if something is not clear or you have more questions.

    Regards,

    David



    ------------------------------
    David Tremaine
    Senior Software Developer
    IBM Canada Ltd.
    ------------------------------



  • 16.  RE: Call Java Pgm on MVS

    Posted Fri April 21, 2023 11:01 AM

    Hello,

    we are currently trying to get the example to run, but we want to run a Cobol program that calls a Java method. We are getiing the following error:

        IGZ0377S Library module libjvm.so could not be found. Check the STEPLIB DD in the JCL or the environment variable LIBPATH to make sure the module is available.

    How and do we have to add the location of JAVA_HOME to the JCL?

     

    Kind regards,

    Alina



    ------------------------------
    Alina Dehler
    ------------------------------



  • 17.  RE: Call Java Pgm on MVS

    Posted Fri April 21, 2023 01:39 PM

    Hi Alina,

    The missing libjvm.so will be able to be found by including the libjvm.so module's containing directory to the LIBPATH like this

    //STDENV DD *
    _CEE_ENVFILE_COMMENT=#
    _CEE_ENVFILE_CONTINUATION=\
    #
    LIBPATH=/usr/lpp/java/J8.0/bin\
    :/usr/lpp/java/J8.0/bin/j9vm
    /*

    and pointing LE to STDENV via

    //CEEOPTS DD *
    ENVAR(_CEE_ENVFILE_S=DD:STDENV)
    /*

    Do note that LE environment variable files do NOT support symbol substitution the way that shell scripts do. However, you can use JES SYMBOLS= substitution.

    Make sure not to include line numbers if using JES input files.

    Bernie



    ------------------------------
    Bernie Rataj
    Technical Support Professional
    IBM Canada Ltd.
    Markham ON Canada
    https://www.ibm.com/products/cobol-compiler-zos
    https://www.ibm.com/products/pli-compiler-zos
    ------------------------------



  • 18.  RE: Call Java Pgm on MVS

    Posted Fri April 28, 2023 10:16 AM

    Hello Bernie,

     

    your answer definetely helped, we just had to substitute our correct paths. Thank you.  We are now able to run a cobol job and call java within.

    But we have a problem with passing strings to java (it works with integers).

    With this variable definition:

     working-storage section.

    01 input-str pic x(9) value "fixstring".

    01 output-str pic x(9).

     

    And this java call:

     call 'Java.CobProd.changeString' using input-str

    returning output-str

     

    We get this error in cjbuild (cob2):

     # Compiling Java call stub method Java.CobProd.changeString

     /usr/lpp/IBM/cobol/igyv6r4/bin/cob2 -qlist -c /cpxvar/JADH/cob64/jtoc/cobprod/out/Java.CobProd.changeString.cbl -I /usr/lpp/IBM/cobol/igyv6r4/include

     # Command return code 8:

     PP 5655-EC6 IBM Enterprise COBOL for z/OS 6.4.0 in progress ...

     LineID Message code Message text

     IGYSC1105-E The "NODBCS" option was in effect but the program

     contained national data. Execution results are unpredictable.

     Messages Total Informational Warning Error Severe Terminating

     Printed: 1 1

     End of compilation 1, program Java_CobProd_changeString, highest severity 8.

     Return code 8

     

    How can we pass strings or jsons to the java method?

    When we use national data in our own cobol programs, we can set the compile option manually for this one program (either at the top of the program or in the SCLM Archdef). How can we pass compile options for the stub programs that are generated in cjbuild, without changing the default compile options?

     

    Kind regards,

    Alina



    ------------------------------
    Alina Dehler
    ------------------------------



  • 19.  RE: Call Java Pgm on MVS

    Posted Fri April 28, 2023 04:16 PM

    Hi Alina,

    I think you've hit upon an area that needs improvement for cjbuild, unfortunately.  If NODBCS is set in your installation defaults, then cjbuild compile jobs will pick that up and that could cause problems for our Java String handling.  This happens because Java String objects store data in UTF-16 format so we use NATIONAL items (which are also UTF-16) in the stub programs when we need to directly interact with Java, and we do the conversions to/from EBCDIC where necessary.

    Unfortunately our April PTF for 6.4 has just been published.  The next PTF for 6.4 is in June and we will try to address this issue for then.

    There are several other things you can do:
    1) Open an official Case with IBM and report this and receive a testfix for cjbuild that you can try out.
    2) As a workaround in the meantime, one thing you could try is to create a new IGYCDOPT module for your compiler (that's the module that stores the installation defaults) and have DBCS be the default in this IGYCDOPT.  You could put that IGYCDOPT module in a data set and put that data set at the front of your STEPLIB for your prototyping work with Java/COBOL interoperability (and until cjbuild provides a better way of allowing users to override various defaults).

    Thank you for letting us know about this, and please let me know if you need more information.

    Regards,
    David



    ------------------------------
    David Tremaine
    Senior Software Developer
    IBM Canada Ltd.
    ------------------------------



  • 20.  RE: Call Java Pgm on MVS

    Posted Fri May 05, 2023 11:27 AM

    Hi Alina,

    I have some good news for you.  I was thinking about an easy workaround to your problem and I realized that there already is a way to override compiler options in the environment in which cjbuild runs. The cob2 utility, which cjbuild uses, supports option overrides via an environment variable called COBOPT.

    So if you set the following in your environment before running cjbuild, everything will work fine:

    export COBOPT="dbcs,nsymbol(national)"


    Obviously, if you're putting this in an environment file, you don't include the "export".

    I tested this out in my environment (I set NODBCS and NSYMBOL(DBCS) in my installation defaults first) and it worked great.

    At the very least,  a future release of cjbuild will likely be updated to explicitly specify DBCS and NSYMBOL(NATIONAL)  so that users do not have to do that override.  A new cjbuild option that supports supplying override options directly may be provided as well.  We're working on it!

    Thanks for trying out this feature and giving us your feedback, and thanks for your patience.

    Regards,
    David



    ------------------------------
    David Tremaine
    Senior Software Developer
    IBM Canada Ltd.
    ------------------------------



  • 21.  RE: Call Java Pgm on MVS

    Posted Tue May 30, 2023 11:24 AM

    Hello David,

    we finally got our example to run, we changed the default compiler options. Thank you for the support.
    We're looking forward to the planned improvements. We will be trying out some more use cases in the future (error handling, DB2 connection, debugging).

    Regards,
    Alina



    ------------------------------
    Alina Dehler
    ------------------------------



  • 22.  RE: Call Java Pgm on MVS

    Posted Tue March 12, 2024 10:17 PM

    Hi David,

    I encounter the same problem as Alina, but your workaround does not work for me. Following the JCL I used:

    //STDOUT  DD SYSOUT=*                         
    //STDERR  DD SYSOUT=*                         
    //STDENV DD *                                 
    _CEE_ENVFILE_COMMENT=#                        
    _CEE_ENVFILE_CONTINUATION=\                   
    #                                             
    LIBPATH=/usr/lpp/java/J8.0_64/bin/j9vm\       
    :/usr/lpp/java/J8.0_64/bin:\                  
    :/usr/lpp/java/J8.0_64/lib:${LIBPATH}         
    /*                                            
    //CEEOPTS DD *                                
    POSIX(ON)                                     
    ENVAR(_CEE_ENVFILE_S=DD:STDENV)               
    /*                                            
    // ENDIF                                      

    Any idea, what the reason might be?

    Many thanks and kind regards
    Helmut



    ------------------------------
    Helmut Roese
    ------------------------------



  • 23.  RE: Call Java Pgm on MVS

    Posted Wed March 13, 2024 07:44 AM
    Note there's no symbol substitution in an environment variable file, so ${LIBPATH} will literally add ${LIBPATH} to the end of the LIBPATH.

    _________________________________________

    Bernie Rataj

    Technical Support Professional

    Enterprise COBOL & PL/I for z/OS Technical Support

    905-413-2857  brataj@ca.ibm.com

     

    https://www.ibm.com/products/cobol-compiler-zos

    https://www.ibm.com/products/pli-compiler-zos 

     






  • 24.  RE: Call Java Pgm on MVS

    Posted 29 days ago

    Hi Bernie,

    finally it worked. Problem was, that I had the wrong version of Java8. I need 8.0.6.36, but had only 8.0.6.7. With Java/Semeru 11.0.19.0 and INTMODE='MIX_31_64' it worked.

    Sometimes it helps to read the instructions: https://www.ibm.com/docs/en/cobol-zos/6.4?topic=6-prerequisite-software-level-changes-enterprise-cobol

    Regards and thanks for your help

    Helmut



    ------------------------------
    Helmut Roese
    ------------------------------



  • 25.  RE: Call Java Pgm on MVS

    Posted Tue January 10, 2023 04:27 AM
    Hi Guido,

    I once participated in writing books about mixing COBOL and Java in IMS. There are some samples out there, e.g. JCL in the Supercharge IMS Applications with Java book, for example on page 96. Unfortunately those older samples only work with the 31bit JVM. If you want to use the 64bit JVM, you cannot use the approach with the OO COBOL syntax and the COBOL compiler generating the .java source stub (you would simply use the Java name for the DLL method without any OO COBOL like this:
           PROGRAM-ID.
                  "Java_ibmpgk_coboljavapgk_ClassName_MethodName"
                  is recursive.
    ...
           Procedure Division using by value env-ptr                        
                                    by value obj-ref                        
                                    by value inByteArrayAddr                
                                    by value outByteArrayAddr.              

    the first two items are required per JNI definitions and with the 64bit JVM all of those need to be 8 bytes - PIC 9(18) COMP-5 )
    COBOL 6.4 adds the Java SHAREABLE clause, I have mostly worked with customers on older levels, where that does not exist. If you want to send copybook structures back and forth, I suggest passing byte arrays from and to Java. For the 1:1 binary representation of the copybook in Java, there is the Java Record Generator, that generates a Java record class and allows to work on the copybook in Java (with getter and setter methods for the fields) and pass the bytearray to Java, which requires then the JNI calls GetByteArrayRegion and SetByteArrayRegion to copy the data from and to COBOL working storage.

    ------------------------------
    Denis Gäbler
    ------------------------------



  • 26.  RE: Call Java Pgm on MVS

    Posted Wed February 08, 2023 11:57 AM
    Hi Denis,
    many thanks for your answer. 
    Regards
    Guido

    ------------------------------
    Guido THelen
    ------------------------------