Pass array to Java program
-
- Posts: 2
- Joined: Tue Aug 28, 2007 6:35 pm
- Skillset: COBOL, JCL, Java
- Referer: Google search
Pass array to Java program
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.
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Pass array to Java program
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?)
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.
d.sch.
-
- Posts: 2
- Joined: Tue Aug 28, 2007 6:35 pm
- Skillset: COBOL, JCL, Java
- Referer: Google search
Re: Pass array to Java program
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.
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.
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Pass array to Java program
You're welcome
d

Not that i'm aware of . . . but there's a lot that i'm not aware ofI 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.

d
Re: Pass array to Java program
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?
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?
Re: Pass array to Java program
just to clarify, i get a index not within range message....
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Error invoking java method (array) IGZ0045S
by JgbCobol » Mon Nov 07, 2022 3:54 pm » in Mainframe Java - 2
- 5547
-
by JgbCobol
View the latest post
Tue Nov 08, 2022 12:32 pm
-
-
-
Calling Java program on UNIX/USS from a COBOL CICS program?
by zbius » Tue Nov 05, 2024 2:37 pm » in IBM Cobol - 2
- 2590
-
by zbius
View the latest post
Wed Nov 06, 2024 6:02 pm
-
-
- 4
- 2883
-
by Pedro
View the latest post
Sat May 15, 2021 3:39 am
-
-
Array processing and Table handling with packed decimal
by rogerstrycova » Tue Oct 26, 2021 3:55 pm » in IBM Cobol - 2
- 1706
-
by Robert Sample
View the latest post
Wed Oct 27, 2021 1:12 am
-
-
- 4
- 5620
-
by NicC
View the latest post
Mon Oct 19, 2020 1:17 am