This is a simple example; a key is written to a dataque and the 1 row
from the table whose primary key matches is retrieved, padded and
written to a dataque so that an RPG program can retrieve it into a data
structure. This is an example of how to do this; it is not very reusable
or flexible nor is it an example of great coding technique.

Hopefully it will end up formatted Ok.

RPG snippit:
dout1             s             10    inz('FULFILLOUT')   
dout2             s             10    inz('PRODLIB')      
dout3             s              5P 0 inz(13)             
dout4             s             13     
din1              s             10    inz('FULFILLIN')      
din2              s             10    inz('PRODLIB')        
din3              s              5P 0                       
din4              s           1000                          
din5              s              5P 0 inz(-1)               
din6              s              2    inz('EQ')             
din7              s              3P 0 inz(26)               
din8              s             26                          
din9              s              3P 0 inz(0)                
din10             s              8 

C* write the key value to the data que

c                   eval      out4='YOURKEYVAL'       
c                   call      'QSNDDTAQ'                      
c                   parm                    out1              
c                   parm                    out2              
c                   parm                    out3              
c                   parm                    out4
C* read the results from the data que
c                   eval      in8='YOURKEYVAL'       
c                   call      'QRCVDTAQ'                     
c                   parm                    in1              
c                   parm                    in2              
c                   parm                    in3              
c                   parm                    in4              
c                   parm                    in5              
c                   parm                    in6              
c                   parm                    in7              
c                   parm                    in8              
c                   parm                    in9              
c                   parm                    in10  

In4 will have the data passed from the sql server it                

import java.sql.*;
import java.util.*;
public class demo
{ //open class
        private static AS400 a4 = null;
        private static KeyedDataQueue dqin = null;
        private static DataQueue dqout = null;
        private static int retrycount=0;
        private static String dqKey= "";
        private static Connection sqlcon = null;
        private static String sqlurl = "jdbc:microsoft:sqlserver://";

        public static void main (String[] params)
        { //open main
                String versionID = System.getProperty("java.version");
                System.out.println("JDK is: " + versionID );
                        boolean cont=true;
                        while (cont)
                        String iseriesname = "localhost";
                        String iuser="ISERIESUSER";
                        String ipw="ISERIESPASSWORD";
                        //get Iseries connection for dataqueues
                        a4 = new AS400(iseriesname, iuser, ipw);
                        dqin= new KeyedDataQueue(a4,
                        dqout= new DataQueue(a4,
                        System.out.println(" SQL Server URL is:\n\t" +
                        String sqluser="YOURSQLUSER";
                        String sqlpassword="YOURSQLPASSWORD";
                        //get sqlserver connection
                        sqlcon =
                catch(Exception e) {}

                catch(SQLException se)
                        System.out.println("Fatal SQL Error in main: " +
se.getErrorCode() + 
                                "\n\t" + se.getLocalizedMessage() );
                catch(Exception e)
                        System.out.println("Fatal Error in main: " +
"\n\t" + e.getLocalizedMessage() );
        }//close main
public static String fieldpad (String in, int numchar, String chartopad,
boolean leftalign)
{//open copytesttbl
        String out=in;
        int length=out.length();
        while(length < numchar)
                if (leftalign)
        return out;
public static boolean copytesttbl ()
{//open copytesttbl
        String sql="";
                boolean jobIsActive = true;
                Statement si = sqlcon.createStatement();
                System.out.println("Waiting for entry");
           while (jobIsActive)
                        DataQueueEntry dqEntry = null;
                        if (dqKey.equals(""))
                        dqEntry =;
                        dqKey = dqEntry.getString().trim();
                        if (dqKey.equals("*EXIT"))
                                System.out.println("Program Exiting
                                return false;
                                sql="select * from TABLENAME where
KEYFLD=" + qKey;
                                ResultSet rs=si.executeQuery(sql);
                                String data="";
                                System.out.println("key is" + dqKey);
fieldpad(rs.getString("FLD2CHAR"),20," ",true);
        catch(Exception e)
                System.out.println("Fatal Error
                System.out.println("\t data: " +dqKey);
                if (retrycount<3)
                        return true;
                        return false;
        return false;
        }//close copytesttbl
}//close class 

-----Original Message-----
[] On Behalf Of
Winchester Terry
Sent: Wednesday, October 26, 2005 1:03 PM
To: Java Programming on and around the iSeries / AS400
Subject: RE: Passing parameters between Java and CL/COBOL/RPG programs


I would love to see this too :)


> -----Original Message-----
> From: java400-l-bounces@xxxxxxxxxxxx
> [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Kelly Cookson
> Sent: Wednesday, October 26, 2005 12:37 PM
> To: Java Programming on and around the iSeries / AS400
> Subject: RE: Passing parameters between Java and CL/COBOL/RPG programs
> An example would be great! Thanks!
> Kelly
> -----Original Message-----
> From: java400-l-bounces@xxxxxxxxxxxx
> [mailto:java400-l-bounces@xxxxxxxxxxxx]On Behalf Of Himes, Jay
> Sent: Wednesday, October 26, 2005 11:03 AM
> To: Java Programming on and around the iSeries / AS400
> Subject: RE: Passing parameters between Java and CL/COBOL/RPG programs
> What I have done for cases like this is to create a java program which

> runs in a separate job. I write the SQL statement to be run to a data 
> que from the program that needs the information; the java program runs

> the sql statement and writes the row (or rows) to a keyed data que the

> original program is reading from (the key is the original program's 
> job indicator so that multiple jobs can use the same que).
> You can avoid the overhead of invoking the program an making a 
> connection for every row you whish to retrieve; which can be 
> significant.
> If you are interested I can dig up an example.
              <snipped for bandwidth>

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,
or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at

Return to Archive home page | Return to MIDRANGE.COM home page