|
I have had to write several RPG to JAVA programs for our group, and wanted to minimize the programming impact for the RPG programmers would have when using the Java programs. Many of them don't like change and keeping the interfaces simple made it more likely that they would use them. :) I often have to pass strings back and forth between RPG and JAVA. What I found that worked best for us was to use the same old strings within RPG but declare them as varying. eg (sample Dspec for string server): D server S 255 varying Then when I need to pass strings to the Java program, I would receive them within the Java method as a byte array. I would then convert them within the Java method to a string. eg (sample Java method which accepts a string from RPG): public void IBMsetOracleServer(byte[] sserver) { String str = new String(sserver); server = str; } When I needed to return a string from Java back to RPG, i would return it as a byte array. eg(sample Java method returning a string to RPG) public byte[] IBMgetOracleServer() { // needed for IBM iseries return server.getBytes(); //getBytes() is a String object method } (Note: The Java String object has overloaded constructors, and one of the constructors accepts byte arrays when creating the String object. Since RPG passes byte arrays, this makes it easy for Java to automatically convert the byte arrays to strings.) RPG code which passes a string to Java was: // initialize the Oracle Server name setServer(objOraCon:server); (objOraCon was the object that pointed to the Java class that contained the methods) RPG code accepting a string from Java was: //get the Oracle server name server=getServer(objOraCon); By using byte arrays in JAVA, you don't have to worry about strings in RPG. Calls to and from the Java methods are converted automatically within the Java method(s), without having to deal with converting the Java strings back to RPG strings everytime you need to call the Java method. The JVM automatically takes care of converting the character set between the AS400 and Java as the data is being passed into and from the Java application. When declaring your prototypes, ensure that the string paramaters your passing to and from JAVA are also declared as varying eg: D getServer PR 255A EXTPROC(*JAVA: D 'as400Orcle': D 'IBMgetOracleServer') VARYING D setServer PR EXTPROC(*JAVA: D 'as400Orcle': D 'IBMsetOracleServer') D parm 255A CONST VARYING ...Paul (pekrzyz@xxxxxxxxxxxxxxx)
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.