× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Calling RPG Programs from JAVA
  • From: "Kalman Shor" <kshor@xxxxxxxxxxxxxxxx>
  • Date: Mon, 21 Aug 2000 18:01:14 -0400
  • Importance: Normal

I posted the following as a reponse to a message on the RPG400 List 2 months
ago. It should be the same used in a Servlet.

----------------------------------------------------------------------------
-------------------------------------------------

The following calls an RPG program that passes back a packed numeric field -
the price.
It actually works reasonably quickly. Most of the code is just to set up the
call and convert the data back and forth.

****************************************************************************
*******
try {
        // create program call
        com.ibm.as400.access.ProgramCall pgm = new
com.ibm.as400.access.ProgramCall();

        // identify the program to run
        String progName = "/QSYS.LIB/YOUR.LIB/MYPRICE.PGM";

        Access.xx2000201.connectService(com.ibm.as400.access.AS400.COMMAND);

        // create parameter list for the program
        com.ibm.as400.access.ProgramParameter[] pList = new
com.ibm.as400.access.ProgramParameter[3];

        // this is for conversion of java String to/from native
        com.ibm.as400.access.AS400Text rtParm = new
com.ibm.as400.access.AS400Text(1);

        // identify fist param
        pList[0] = new com.ibm.as400.access.ProgramParameter(rtParm.toBytes(" 
"),
1);

        // this is used to convert between java(BigDecimal) and Packed floating
point decimal
        com.ibm.as400.access.AS400PackedDecimal cust = new
com.ibm.as400.access.AS400PackedDecimal(6, 0);

        // identify param
        pList[1] = new com.ibm.as400.access.ProgramParameter(cust.toBytes(new
java.math.BigDecimal(custNumber")), 4);

        // this is for conversion of java String to/from native
        com.ibm.as400.access.AS400Text item = new
com.ibm.as400.access.AS400Text(15);

        // identify param
        pList[2] = new com.ibm.as400.access.ProgramParameter(item.toBytes(new
String(skuNumber)), 15);

        // this is used to convert between java(BigDecimal) and Packed floating
point decimal
        com.ibm.as400.access.AS400PackedDecimal pric = new
com.ibm.as400.access.AS400PackedDecimal(7, 2);

        // identify param
        pList[3] = new com.ibm.as400.access.ProgramParameter(pric.toBytes(new
java.math.BigDecimal("0")), 4);

        // set the system to AS/400
        pgm.setSystem(Access.xx2000201);

        // set program and parameters
        pgm.setProgram(progName, pList);

        // run the program
        if (pgm.run() != true) {

                com.ibm.as400.access.AS400Message[] messageList = 
pgm.getMessageList();
                for (int msg = 0; msg < messageList.length; msg++) {

                // this is to print error message to standard out
                System.out.println(messageList[msg]);
                }
        } else {

                if (((String) (rtParm.toObject(pList[0].getOutputData(), 
0))).equals(" "))
                {
                        // get the price
                        intPrice = (((java.math.BigDecimal) (new
com.ibm.as400.access.AS400PackedDecimal(7, 2)).toObject(pList
[3].getOutputData(), 0)).doubleValue());

                        // add to the orderPrice;
                        OrderDetail.orderPrice = OrderDetail.orderPrice + 
intPrice;

                        // create number format for displaying the price
                        java.text.NumberFormat nf = 
java.text.NumberFormat.getCurrencyInstance();

                        // set the text
                        
getJLabelOrderPrice().setText(nf.format(OrderDetail.orderPrice));

                        // set instance variable
                        this.childPrice = intPrice;
                        }
        }
} catch (Exception e) {
        e.printStackTrace();
}
***********************************************************************

Kalman Shor


-----Original Message-----
From: owner-java400-l@midrange.com
[mailto:owner-java400-l@midrange.com]On Behalf Of tmalin@hannasteel.com
Sent: Monday, August 21, 2000 12:25 PM
To: JAVA400-L@midrange.com
Subject: Calling RPG Programs from JAVA


Anyone have an example of calling an RPG program from a JAVA Servlet.
Thanks in advance. Tom




+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

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-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.