|
If your system is at V5R1 you should be able to do this by usingn the new RPG object data type and defining RPG prototypes for the Java objects and methods you want to use. I've included the source code for a simple working example where the Java class accepts a string from the RPG program and returns a modified string. /** * @author shaler * */ public class TestHello { public String getResponse (String pMessage) { String message = "Hello " + pMessage + "! ...from Java"; return (message); } } Figure 1: The Java TestHello Class h DftActGrp(*NO) ActGrp(*Caller) ********************************************************************* * Prototype for a Java String object ********************************************************************* d crtString PR O EXTPROC(*JAVA: d 'java.lang.String': d *CONSTRUCTOR) d RPGBytes 30A Const Varying ********************************************************************* * Prototype for TestHello object creation (instantiation) ********************************************************************* d crtTestHello PR O EXTPROC(*JAVA: d 'TestHello': d *CONSTRUCTOR) ********************************************************************* * Prototype for TestHello's getResponse method ********************************************************************* d getResponse PR O EXTPROC(*JAVA: d 'TestHello': d 'getResponse') d Class(*JAVA: d 'java.lang.String') d String O Class(*JAVA: d 'java.lang.String') d Const ********************************************************************* * Prototype for Java String's getBytes method ********************************************************************* d cvtToBytes PR 30A EXTPROC(*JAVA: d 'java.lang.String': d 'getBytes') d Varying * Create TestHello object field d TestHelloObj S O Class(*Java: d 'TestHello') * Create message String object field to contain RPG message d sendMsg S O Class(*Java: d 'java.lang.String') * Create message String object field to contain Java message d rcvMsg S O Class(*Java: d 'java.lang.String') * Create constant to load into sendMsg String object d msg C CONST('RPG') d DisplayMsg S 30A Varying ********************************************************************* * Create Java String object to contain sending message ********************************************************************* c eval sendMsg = crtString(msg) ********************************************************************* * Create TestHello object to access its getResponse method ********************************************************************* c eval TestHelloObj = crtTestHello() ********************************************************************* * Call the getResponse method of the TestHello object ********************************************************************* c eval rcvMsg = getResponse(TestHelloObj:sendMsg) ********************************************************************* * Convert the Java rcvMsg String to RPG bytes (Varying alpha field) ********************************************************************* c eval DisplayMsg = cvtToBytes(rcvMsg) c DisplayMsg Dsply c EVAL *INLR = *ON Figure 2: The CALLJAVA RPG Program For more information in Chapter 11 "RPG and the eBusiness World" of the ILE RPG Programmers Guide (V5R1 or greater) or see see an article I wrote "Hello RPG!... from Java" at: http://www.lab400.com/newsletter.html#HelloRPG Yildiray Ozen <yildirayo@xxxxxxxxxxxxxxxxxxx> wrote: Hi, I have a Java program on 400 and it takes some parameters and returns a value. It should be called from some RPG programs. Has anybody tried something similar? Yildiray Ozen _______________________________________________ This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/java400-l or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/java400-l.
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.