The java interface from RPG is not set up to call a main() function, though I suppose you could. Setting up an array of Strings might be tricky, though. The java command you run from QSH does some work on it's own to set up the parameters you pass in the command lines that RPG doesn't do.

The prototypes you are trying to set up are for calling a method of a class. Your class should be defined something like this:

Package com.yourpath.yourpackage;
Public class YourClass {
Public String someMethod(String a, String b, String c, String d, String e){
return "Hello There";
}
}

You need to prototype the String constructor that takes a byte array as an argument. RPG character fields are byte arrays. So each character field you are passing to the function needs to be passed through the newString function and the resultant object passed back to your method call. Your method is going to return a String object. You'll need to pass that object through the toByteArray() method of the String class to get an RPG character field you can use.

Be sure to get the full package path in the prototype for your method just as you have done for java.lang.String. The java compiler will generate the com/yourpath/yourpackage/YourClass path from whatever class root you are using. If you jar up your classes, it'll still have that package path.

You can call a static method of the class against the class object itself, or you can use the constuctor prototype keywords to create an instance (object) of the class and call an instance method against the instance object.

You've got the right idea. I think you've set up the String$new properly. Your prototype for calling main() might work, though I've never done it with an array like that. You're passing an array of 5 string objects, but only two are initialized. You might want to try initializing them to null before the call. Your JavaPGM prototype needs to show that the method is returning an array of 10 String objects, you have it showing none as if it was coded "public void main(String[] args)" in java. Your call to the method should be "EVAL resultArray = JavaPGM(args);". Define resultArray as an array of 10 java String objects. The way you have it coded, java won't find the main method as java matches method signatures on the number and type of parameters passed and the type of result returned as well as the method name.

Be sure to free any objects you create in RPG using constructor methods. RPG hasn't done it automatically when they go out of scope, though this feature has been promised and may be in current releases. Look for notes from Barbara Morris in the archives of this and the RPG mailing list archives.

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Steve Fekete
Sent: Thursday, September 27, 2012 1:29 PM
To: java400-l@xxxxxxxxxxxx
Subject: RE: Newbie to RPG calling Java....what's a good reference to start learning!

I am passing in a IP address, a port #, a name and a debug option as four strings.



This is the lines from the Java program to return the parm



public static String[] main(String[] args) throws Exception

{

String [] arrResult = new String[10];



(Other stuff in the middle here)



arrResult[0] = [Value read from scale];



return arrResult;

}





The RPG looks like this..(I don't even know if I'm in the ballpark or not)



H DFTACTGRP(*NO)

D JavaPGM pr STATIC

D EXTPROC(*JAVA:

D 'ScaleTools':

D 'main')

D O CLASS(*JAVA:'java.lang.String')

D DIM(5)



DString$new PR O EXTPROC(

D *JAVA:

D 'java.lang.String':

D *CONSTRUCTOR)

D CLASS(

D *JAVA:

D 'java.lang.String')

D bytes 60A CONST VARYING

D args S O CLASS(

D *JAVA:

D 'java.lang.String')

D DIM(5)





*setting up parameters to use in java call



C Eval args(1) = String$New('XXX.XX.XXX.XX')

C Eval args(2) = String$New('6001')

*call Java program

C Callp JavaPgm(args)



C Eval *InLR = *On





_____

date: Thu, 27 Sep 2012 11:14:00 -0500

from: Dan Kimmel < <mailto:dkimmel@xxxxxxxxxxxxxxx> dkimmel@xxxxxxxxxxxxxxx>

subject: RE: Newbie to RPG calling Java....what's a good reference to

start learning!



The archives of this list and the archives of the RPG list also on midrange.com are a good place to start.



What types are you passing as parameters and what type are you expecting to be returned? What versions of RPG, iOS and Java?



You might show us the interface of the java method you are trying to prototype and what you have tried as a prototype and the errors you receive.







From: Steve Fekete [mailto:fekete1@xxxxxxx]
Sent: Thursday, September 27, 2012 11:23 AM
To: 'java400-l@xxxxxxxxxxxx'
Subject: Newbie to RPG calling Java....what's a good reference to start learning!



I am a newbie to the Java world from RPG. I have an issue where I need to
call a java program passing in parms and then getting a return value back from the java program.



What is a good reference to learn how to do this? Trying to prototype in
RPG to receive the return value back but keep getting errors so I'm in need of more information.



Thanks ahead of time to anyone that can help!



Steve

--
This is the Java Programming on and around the IBM i (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 thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 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.