Pass array to Java program



Support for Java SE, EE & ME, JVM, JNI, JDBC, EJB, JFC, JPDA, JAAS,JCE, JAXP, XML and Java API.

Pass array to Java program

Postby gogolfing » Tue Feb 10, 2009 9:18 pm

Using Enterprise COBOL I've successfully passed strings to Java and received strings from Java. The Java class resides in Unix System Services and the COBOL program is submitted to a job queue. Now I'm trying to figure out how to pass an array to Java. Initially I want to pass an array of integers then an array of strings. I've searched Redbooks, forums, etc. for some help but without any success. The web sites typically use C or C++ which is completely foreign to me. Can anyone help me out? Thanks.
gogolfing
 
Posts: 2
Joined: Tue Aug 28, 2007 6:35 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Pass array to Java program

Postby dick scherrer » Wed Feb 11, 2009 3:24 am

Hello,

In the cobol code, could you not redefine the array and pass the redefinition to java as a string? Using reference modification, you might control the length if not all of the array was filled? The array might be built with the last character of each iteration as a delimiter then java could deal with the delimited string.

I don't speak java. . . (yet?) :)
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Pass array to Java program

Postby gogolfing » Wed Feb 11, 2009 3:59 am

I understand what you're suggesting. I've already sent a "csv" string to a Java program which substrings out the individual fields. Works, of course. But Java has built in support of arrays and lists that I'd like to use. It should require less ugly more straight forward code.

Refering to chapter 31 beginning on page 600 in the Enterprise COBOL Programming Guide v4r1 a discussion of "interoperable data types" makes it clear which kinds of data can be passed "as is". For example, integers (pic comp s9(5)) do not require any special conversion. Character strings, however, must be converted to Java strings using special functions found in the Java Native Interface (JNI).

The section of this manual that discusses arrays only does so from the perspective of the COBOL program receiving an array. I want to send one.

I hoped that someone on this forum had blazed this trail so that I wouldn't be the one that's face down with arrows in my back. :)

Thanks for the quick response.
gogolfing
 
Posts: 2
Joined: Tue Aug 28, 2007 6:35 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Pass array to Java program

Postby dick scherrer » Wed Feb 11, 2009 9:43 am

You're welcome :)

I hoped that someone on this forum had blazed this trail so that I wouldn't be the one that's face down with arrows in my back.
Not that i'm aware of . . . but there's a lot that i'm not aware of ;)

d
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Pass array to Java program

Postby achieve1 » Sat Jun 16, 2012 11:24 pm

Hi, I was wondering if somebody can help out with a similar problem I'm having with arrays using JNI.

I am also able to use NewStringPlatform and create a string and pass it along to Java...

but now I am having problems with creating arrays. I am trying to create a Java object array of Strings which I will populate and then pass along to a Java program for processing.

In the Repository section, I defined:

Class stringArray is "jobjectArray:java.lang.String"
Class jstring is "java.lang.String"


In my working storage section:
strArray object reference stringArray
strOne object reference jstring
strInitial object reference jstring
strRtn object reference stringArray

ARRAY-LENGTH PIC S9(9) COMP-5 VALUE 25.
ARRAY-INDEX PIC S9(9) COMP-5 VALUE 1.
ARRAY-ELEMENT-LEN PIC S

strBuf PIC X VALUE 'A'.

In my procedure division:


Call "NewStringPlatform" <--- This is so that I can populate the StrInitial with the letter 'A' so that it can be used to initialize all the elements to it in the step below
using by value JNIEnvPtr
address of strBuf
address of strInitial
0
returning rc (and then I check return code)

Call NewObjectArray
using by value JNIEnvPtr
ARRAY-LENGTH <--- length of the array (25)
strOne <-- the IBM manual says this parameter is for an object reference of the element class for this array, in this case a jstring...
strInitial <-- Initialize all the elements with value 'A'.
returning strArray
***At this point I do a routine that checks if an Exception is thrown****, if no exception is thrown then continue into next step

Call GetObjectArrayElement
using by value JNIEnvPtr
strArray <---The array created in previous step
ARRAY-INDEX <---the index for which I want the value (in this case, 1st element)
returning strRtn <---- IBM manual says to return an object reference, in this case strRtn references stringArray (jobjectArray:java.lang.String)...i'm not sure should this be jstring instead??


Currently, I believe I am able to create the array because I am not getting any exceptions. Earlier I was getting a Java.lang.outofmemory error...but I think I managed to fix that. The problem is when I get to GetObjectArrayElement, thats when java just puts out a dump....I'm not really sure what might be wrong. Anybody have any ideas?
achieve1
 
Posts: 2
Joined: Sat Jun 16, 2012 8:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Pass array to Java program

Postby achieve1 » Sun Jun 17, 2012 3:39 am

just to clarify, i get a index not within range message....
achieve1
 
Posts: 2
Joined: Sat Jun 16, 2012 8:31 pm
Has thanked: 0 time
Been thanked: 0 time


Return to Mainframe Java

 


  • Related topics
    Replies
    Views
    Last post