Using RPGLE Service Pogram from Java - IBM AS400

This is a discussion on Using RPGLE Service Pogram from Java - IBM AS400 ; All, Our aim is to use a RPG procedure on an AS400. This to prevent that business code must be written in both RPG and Java. Because our company has already a lot of code written in RPG we like ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Using RPGLE Service Pogram from Java

  1. Using RPGLE Service Pogram from Java

    All,

    Our aim is to use a RPG procedure on an AS400. This to prevent that
    business code must be written in both RPG and Java.
    Because our company has already a lot of code written in RPG we like
    to use some of this code in our front-office application.

    We have already documentation about the way both RPG and Java should
    be coded to achieve above situation

    To test above situation I have written a simple Java and a simple RPG
    procedure. (See below)
    The problem we face is that when we run the Java application Java is
    not able to find the RPG procedure.
    To Java we use RAD on a local PC.

    Our problem is that once we run the Java application the program fails
    on the loadLibary with the message that he cannot find the library.


    Java code Main line

    package pagecode;
    /*
    * Created on Jun 4, 2007
    *
    * TODO To change the template for this generated file go to
    * Window - Preferences - Java - Code Style - Code Templates
    */

    /**
    * @author boogaard
    *
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    public class TestSrvpgm {

    public static void main(String[] args) {
    Prices price = new Prices();

    String custcd = "12345";
    int salesPrice = price.getSalesPrice(custcd);

    }
    }


    Java code to retrieve price from the RPG service program pPri01J.
    package pagecode;
    /*
    * Created on Jun 4, 2007
    *
    * TODO To change the template for this generated file go to
    * Window - Preferences - Java - Code Style - Code Templates
    */

    /**
    * @author boogaard
    *
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    public class Prices {

    static {
    //System.loadLibrary("//KME18/QSYS.lib/BVB2.lib/PPRI01J.srvpgm");
    // System.loadLibrary("QSYS.lib/BVB2.lib/
    PPRI01J.srvpgm");
    System.loadLibrary("PPRI01J");

    }
    native public int GetpSlsPriJNI (String CustCd);


    public Prices()
    {

    }


    public int getSalesPrice(String Custcd)
    {
    int salesPrice = 0;
    salesPrice = GetpSlsPriJNI(Custcd);
    return salesPrice ;
    }


    }


    As you can see I have changed the path in the loadLibrary a few
    times. KME18 is the name of the AS400 system.


    RPG Code JNI-Service program. The procedures within this service
    program is used by the Java method

    C************************************************* **********************
    **P General usage procedures.
    S ***
    C************************************************* ***********************
    F************************************************* *******************
    F* APPLICATION DESCRIPTION :
    *
    F* -------------------------
    *
    F* This module contains general price procedures.
    *
    F*
    *
    F************************************************* *******************
    F* BVB 01-06-07 Test JNI!!
    *
    F************************************************* *******************
    H
    NOMAIN
    H
    Thread(*Serialize)
    D************************************************* ****************
    D* Copy Member For Field reference
    datastructure
    D************************************************* ****************
    D/COPY
    QCPYLESRC,ESPREF
    D************************************************* ****************
    D* Copy Member for this Prototype
    D************************************************* ****************
    D/COPY
    QPROLESRC,PPRI01J
    D/COPY
    QPROLESRC,PPRI01S
    P*================================================ ================
    P* Procedure :
    GetpSlsPri
    P* Purpose : Returns the net price for dealer/
    distributor
    P*================================================ ================
    P GetpSlsPriJNI B
    EXPORT
    P*
    D GetpSlsPriJNI PI 10I
    0
    D pCustcd
    Like(@@Custcd)
    D*----
    D*
    /
    Free
    Return
    GetPSlsPri(pCustcd) ;

    /End-
    Free

    *
    P E


    The RPG service program which just returns the price.

    C************************************************* *******************
    **P General usage procedures.
    S ***
    C************************************************* *********************
    F************************************************* *******************
    F* APPLICATION DESCRIPTION :
    *
    F* -------------------------
    *
    F* This module contains general price procedures.
    *
    F*
    *
    F************************************************* *******************
    F* BVB 01-06-07 Test JNI!!
    *
    F************************************************* *******************
    H
    NOMAIN
    D************************************************* ****************
    D* Copy Member For Field reference
    datastructure
    D************************************************* ****************
    D/COPY
    QCPYLESRC,ESPREF
    D************************************************* ****************
    D* Copy Member for this
    Prototype
    D************************************************* ****************
    D/COPY
    QPROLESRC,PPRI01S
    P*================================================ ================
    P* Procedure :
    GetpSlsPri
    P* Purpose : Returns the net price for dealer/
    distributor
    P*================================================ ================
    P GetpSlsPri B
    EXPORT
    P*
    D GetpSlsPri PI
    Like(@@Slspri)
    D pCustcd Like(@@Custcd)
    Value
    D*----
    D pCstPri S
    Like(@@CstPri)
    D*
    /
    Free
    pCstPri =
    12,34 ;
    Return
    pCstPri ;

    /End-
    Free

    *
    P GetpSlsPri
    E

    The two copy members used in above service programs.

    P************************************************* ****************
    P* This is a COPY
    member
    D************************************************* ****************
    D* Exported Prototypes for module
    PPRI01S
    D************************************************* ****************
    D*--------------------------------------------------------------------
    D GetpSlsPriJNI PR 10I
    0
    D EXTPROC(*Java:
    'pagecode'
    D :
    'GetSalesPrice')
    D pCustcd
    Like(@@Custcd)



    P************************************************* ****************
    P* This is a COPY
    member
    D************************************************* ****************
    D* Exported Prototypes for module
    PPRI01S
    D************************************************* ****************
    D*--------------------------------------------------------------------
    D GetpSlsPri PR
    Like(@@Slspri)
    D pCustcd Like(@@Custcd)
    Value



    Full text of console
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't find
    library PPRI01J
    (PPRI01J.dll) in sun.boot.library.path or java.library.path
    sun.boot.library.path=C:\Program Files\IBM\Rational\SDP\6.0\runtimes
    \base_v6\java
    \jre\bin
    java.library.path=C:\Program Files\IBM\Rational\SDP\6.0\runtimes
    \base_v6\java
    \jre\bin;.;C:\WINDOWS\system32;
    C:\WINDOWS;C:\Program Files\IBM\Rational\SDP\6.0\eclipse\jre\bin;C:
    \WINDOWS\
    system32;C:\WINDOWS;
    C:\WINDOWS\System32\Wbem;C:\WINDOWS\Downloaded Program Files;C:
    \Program Files\
    PC-Doctor for Windows\;C:\IBMTOOLS\Python22;C:\Program Files\lotus
    \notes;C:\PROGRA~1\IBM\CLIENT~1;C:\PROGRA~1\IBM\CL IENT~1\Shared;C:\
    PROGRA~1\IBM\CLIENT~1\Emulator;C:\Program Files\Rational\common;C:
    \Program Files\Rational\ClearCase\bin
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java :2020)
    at java.lang.Runtime.loadLibrary0(Runtime.java:824)
    at java.lang.System.loadLibrary(System.java:908)
    at pagecode.Prices.(Prices.java:19)
    at pagecode.TestSrvpgm.main(TestSrvpgm.java:19)


    He cannot find pPri01J in the path.


    Summarize
    The Java program cannot find the service program. The error is that
    the library cannot be found in the paths.
    We are developing with Rational Application Developer. (See below)
    against a AS400 database. Later on the application is deployed to the
    same AS400. On AS400 side we are on release 5.4 on the developer
    machine (5.3 on production)

    Questions :
    1. How can I add an entry to which path so that the system can find
    the AS400 service program?
    2. What path do I have to enter? The path of the service program on
    the AS400, or the path of the toolbox or another?
    3. IS this really the problem? Or should I do complete other things to
    link the Java method to the RPG procedure?
    4. It looks like he tries to find a file called pPri01J.dll. This is
    not correct because .dll is windows and he should try to find
    pPri01J.srvpgm on the AS400. Of course the native machine is windows,
    but on the other hand I hardly can't imagine that testing against an
    AS400 service program is not possible.


  2. Re: Using RPGLE Service Pogram from Java

    Why not take the easy route, and use the ServiceProgramCall class of
    the Java Toolbox? JNI is rarely fun.


  3. Re: Using RPGLE Service Pogram from Java

    Hi,

    you must not call rpg from java via JNI, RPG is not Threadsafe, the work
    around with Thread * serialize, serializes on the module, this will cause
    problems in a multithreaded environment (Deadlocks for instance) and does
    not work on exports of variables. Use SQL functions or jtOpen instead.

    Dieter Bender

    SanderP wrote:

    > All,
    >
    > Our aim is to use a RPG procedure on an AS400. This to prevent that
    > business code must be written in both RPG and Java.
    > Because our company has already a lot of code written in RPG we like
    > to use some of this code in our front-office application.
    >
    > We have already documentation about the way both RPG and Java should
    > be coded to achieve above situation
    >
    > To test above situation I have written a simple Java and a simple RPG
    > procedure. (See below)
    > The problem we face is that when we run the Java application Java is
    > not able to find the RPG procedure.
    > To Java we use RAD on a local PC.
    >
    > Our problem is that once we run the Java application the program fails
    > on the loadLibary with the message that he cannot find the library.
    >
    >
    > Java code Main line
    >
    > package pagecode;
    > /*
    > * Created on Jun 4, 2007
    > *
    > * TODO To change the template for this generated file go to
    > * Window - Preferences - Java - Code Style - Code Templates
    > */
    >
    > /**
    > * @author boogaard
    > *
    > * TODO To change the template for this generated type comment go to
    > * Window - Preferences - Java - Code Style - Code Templates
    > */
    > public class TestSrvpgm {
    >
    > public static void main(String[] args) {
    > Prices price = new Prices();
    >
    > String custcd = "12345";
    > int salesPrice = price.getSalesPrice(custcd);
    >
    > }
    > }
    >
    >
    > Java code to retrieve price from the RPG service program pPri01J.
    > package pagecode;
    > /*
    > * Created on Jun 4, 2007
    > *
    > * TODO To change the template for this generated file go to
    > * Window - Preferences - Java - Code Style - Code Templates
    > */
    >
    > /**
    > * @author boogaard
    > *
    > * TODO To change the template for this generated type comment go to
    > * Window - Preferences - Java - Code Style - Code Templates
    > */
    > public class Prices {
    >
    > static {
    > //System.loadLibrary("//KME18/QSYS.lib/BVB2.lib/PPRI01J.srvpgm");
    > // System.loadLibrary("QSYS.lib/BVB2.lib/
    > PPRI01J.srvpgm");
    > System.loadLibrary("PPRI01J");
    >
    > }
    > native public int GetpSlsPriJNI (String CustCd);
    >
    >
    > public Prices()
    > {
    >
    > }
    >
    >
    > public int getSalesPrice(String Custcd)
    > {
    > int salesPrice = 0;
    > salesPrice = GetpSlsPriJNI(Custcd);
    > return salesPrice ;
    > }
    >
    >
    > }
    >
    >
    > As you can see I have changed the path in the loadLibrary a few
    > times. KME18 is the name of the AS400 system.
    >
    >
    > RPG Code JNI-Service program. The procedures within this service
    > program is used by the Java method
    >
    > C************************************************* **********************
    > **P General usage procedures.
    > S ***
    > C************************************************* ***********************
    > F************************************************* *******************
    > F* APPLICATION DESCRIPTION :
    > *
    > F* -------------------------
    > *
    > F* This module contains general price procedures.
    > *
    > F*
    > *
    > F************************************************* *******************
    > F* BVB 01-06-07 Test JNI!!
    > *
    > F************************************************* *******************
    > H
    > NOMAIN
    > H
    > Thread(*Serialize)
    > D************************************************* ****************
    > D* Copy Member For Field reference
    > datastructure
    > D************************************************* ****************
    > D/COPY
    > QCPYLESRC,ESPREF
    > D************************************************* ****************
    > D* Copy Member for this Prototype
    > D************************************************* ****************
    > D/COPY
    > QPROLESRC,PPRI01J
    > D/COPY
    > QPROLESRC,PPRI01S
    > P*================================================ ================
    > P* Procedure :
    > GetpSlsPri
    > P* Purpose : Returns the net price for dealer/
    > distributor
    > P*================================================ ================
    > P GetpSlsPriJNI B
    > EXPORT
    > P*
    > D GetpSlsPriJNI PI 10I
    > 0
    > D pCustcd
    > Like(@@Custcd)
    > D*----
    > D*
    > /
    > Free
    > Return
    > GetPSlsPri(pCustcd) ;
    >
    > /End-
    > Free
    >
    > *
    > P E
    >
    >
    > The RPG service program which just returns the price.
    >
    > C************************************************* *******************
    > **P General usage procedures.
    > S ***
    > C************************************************* *********************
    > F************************************************* *******************
    > F* APPLICATION DESCRIPTION :
    > *
    > F* -------------------------
    > *
    > F* This module contains general price procedures.
    > *
    > F*
    > *
    > F************************************************* *******************
    > F* BVB 01-06-07 Test JNI!!
    > *
    > F************************************************* *******************
    > H
    > NOMAIN
    > D************************************************* ****************
    > D* Copy Member For Field reference
    > datastructure
    > D************************************************* ****************
    > D/COPY
    > QCPYLESRC,ESPREF
    > D************************************************* ****************
    > D* Copy Member for this
    > Prototype
    > D************************************************* ****************
    > D/COPY
    > QPROLESRC,PPRI01S
    > P*================================================ ================
    > P* Procedure :
    > GetpSlsPri
    > P* Purpose : Returns the net price for dealer/
    > distributor
    > P*================================================ ================
    > P GetpSlsPri B
    > EXPORT
    > P*
    > D GetpSlsPri PI
    > Like(@@Slspri)
    > D pCustcd Like(@@Custcd)
    > Value
    > D*----
    > D pCstPri S
    > Like(@@CstPri)
    > D*
    > /
    > Free
    > pCstPri =
    > 12,34 ;
    > Return
    > pCstPri ;
    >
    > /End-
    > Free
    >
    > *
    > P GetpSlsPri
    > E
    >
    > The two copy members used in above service programs.
    >
    > P************************************************* ****************
    > P* This is a COPY
    > member
    > D************************************************* ****************
    > D* Exported Prototypes for module
    > PPRI01S
    > D************************************************* ****************
    > D*--------------------------------------------------------------------
    > D GetpSlsPriJNI PR 10I
    > 0
    > D EXTPROC(*Java:
    > 'pagecode'
    > D :
    > 'GetSalesPrice')
    > D pCustcd
    > Like(@@Custcd)
    >
    >
    >
    > P************************************************* ****************
    > P* This is a COPY
    > member
    > D************************************************* ****************
    > D* Exported Prototypes for module
    > PPRI01S
    > D************************************************* ****************
    > D*--------------------------------------------------------------------
    > D GetpSlsPri PR
    > Like(@@Slspri)
    > D pCustcd Like(@@Custcd)
    > Value
    >
    >
    >
    > Full text of console
    > Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't find
    > library PPRI01J
    > (PPRI01J.dll) in sun.boot.library.path or java.library.path
    > sun.boot.library.path=C:\Program Files\IBM\Rational\SDP\6.0\runtimes
    > \base_v6\java
    > \jre\bin
    > java.library.path=C:\Program Files\IBM\Rational\SDP\6.0\runtimes
    > \base_v6\java
    > \jre\bin;.;C:\WINDOWS\system32;
    > C:\WINDOWS;C:\Program Files\IBM\Rational\SDP\6.0\eclipse\jre\bin;C:
    > \WINDOWS\
    > system32;C:\WINDOWS;
    > C:\WINDOWS\System32\Wbem;C:\WINDOWS\Downloaded Program Files;C:
    > \Program Files\
    > PC-Doctor for Windows\;C:\IBMTOOLS\Python22;C:\Program Files\lotus
    > \notes;C:\PROGRA~1\IBM\CLIENT~1;C:\PROGRA~1\IBM\CL IENT~1\Shared;C:\
    > PROGRA~1\IBM\CLIENT~1\Emulator;C:\Program Files\Rational\common;C:
    > \Program Files\Rational\ClearCase\bin
    > at java.lang.ClassLoader.loadLibrary(ClassLoader.java :2020)
    > at java.lang.Runtime.loadLibrary0(Runtime.java:824)
    > at java.lang.System.loadLibrary(System.java:908)
    > at pagecode.Prices.(Prices.java:19)
    > at pagecode.TestSrvpgm.main(TestSrvpgm.java:19)
    >
    >
    > He cannot find pPri01J in the path.
    >
    >
    > Summarize
    > The Java program cannot find the service program. The error is that
    > the library cannot be found in the paths.
    > We are developing with Rational Application Developer. (See below)
    > against a AS400 database. Later on the application is deployed to the
    > same AS400. On AS400 side we are on release 5.4 on the developer
    > machine (5.3 on production)
    >
    > Questions :
    > 1. How can I add an entry to which path so that the system can find
    > the AS400 service program?
    > 2. What path do I have to enter? The path of the service program on
    > the AS400, or the path of the toolbox or another?
    > 3. IS this really the problem? Or should I do complete other things to
    > link the Java method to the RPG procedure?
    > 4. It looks like he tries to find a file called pPri01J.dll. This is
    > not correct because .dll is windows and he should try to find
    > pPri01J.srvpgm on the AS400. Of course the native machine is windows,
    > but on the other hand I hardly can't imagine that testing against an
    > AS400 service program is not possible.



  4. Re: Using RPGLE Service Pogram from Java

    Thanx guys, we'll have a look at that!


  5. Re: Using RPGLE Service Pogram from Java

    SanderP wrote:
    >
    > To test above situation I have written a simple Java and a simple RPG
    > procedure. (See below)
    > The problem we face is that when we run the Java application Java is
    > not able to find the RPG procedure.
    > To Java we use RAD on a local PC.
    >


    Java can only call a native method when the Java is running on the same
    system as the native method.

    When you try to call a native method from Java running on your PC, it
    will look for the native method in your PC directories.

  6. Re: Using RPGLE Service Pogram from Java

    il 08/06/2007 11.34, Scrive SanderP 38592120:
    > All,
    >
    > Our aim is to use a RPG procedure on an AS400. This to prevent that
    > business code must be written in both RPG and Java.
    > Because our company has already a lot of code written in RPG we like
    > to use some of this code in our front-office application.

    [...]
    to do load-library you should evoke a JNI program/library-function. JNI
    is the way that Sun proposed to call a native program from java or to
    call a java class-method from a native program. RPG do only the second.
    To do the first (java-to-native) you shold wrap your RPG ILE function in
    a C JNI-program.
    Or better use com.ibm.as400.access.ServiceProgramCall using jt400.jar
    either from your as400 or JtOpen, the open version of the as400 toolbox
    for java.

    --
    Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñe joAlcoolInside
    Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
    Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'

  7. Re: Using RPGLE Service Pogram from Java

    Dr.UgoGagliardelli wrote:
    > [...]
    > to do load-library you should evoke a JNI program/library-function. JNI
    > is the way that Sun proposed to call a native program from java or to
    > call a java class-method from a native program. RPG do only the second.


    RPG can also do the first, java to native.
    http://publib.boulder.ibm.com/infoce...HDRCALLNATMETH

    You create a normal EXTPROC(*JAVA) prototype for the native method, and
    then the RPG subprocedure is coded normally. The only difference is
    that for an instance method, you can use %THIS to get the instance object.

    (But either RPG native or ILE C native will only work if the Java is
    running on the same system as the native method.)


  8. Re: Using RPGLE Service Pogram from Java

    Thanx again all, we're gonna try it with the JT-open and the Toolbox!!


+ Reply to Thread