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



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                
                                                     

Java:
import java.sql.*;
import java.util.*;
import com.ibm.as400.access.*;
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 );
                try
                {
                        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,
"/qsys.lib/prodlib.lib/FULFILLIN.dtaq");
                        dqout= new DataQueue(a4,
"/qsys.lib/prodlib.lib/FULFILLOUT.dtaq");
        
sqlurl="jdbc:microsoft:sqlserver://YOURSERVERIP:1433;DatabaseName=SCHEMA
NAME;";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
                                //in
mssqlserver.jar;msbase.jar;msutil.jar
                        System.out.println(" SQL Server URL is:\n\t" +
sqlurl);
                        String sqluser="YOURSQLUSER";
                        String sqlpassword="YOURSQLPASSWORD";
                        //get sqlserver connection
                        sqlcon =
DriverManager.getConnection(sqlurl,sqluser,sqlpassword);
                        cont=copytesttbl();
            try
            {
                        sqlcon.close();
                }
                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;
        if(out==null)
                out="";
        int length=out.length();
        while(length < numchar)
        {
                if (leftalign)
                        out=out+chartopad;
                else
                        out=chartopad+out;
                    length=out.length();
        }
        return out;
}
//**********************************************************************
********************
public static boolean copytesttbl ()
{//open copytesttbl
        String sql="";
        try
        {
                boolean jobIsActive = true;
                Statement si = sqlcon.createStatement();
                System.out.println("Waiting for entry");
           while (jobIsActive)
           {
                        DataQueueEntry dqEntry = null;
                        if (dqKey.equals(""))
                        {
                        dqEntry = dqout.read(-1);
                        dqKey = dqEntry.getString().trim();
                    }
                        if (dqKey.equals("*EXIT"))
                        {
                                jobIsActive=false;
                                System.out.println("Program Exiting
Normally");
                                return false;
                        }
                        else
                        {
                                sql="select * from TABLENAME where
KEYFLD=" + qKey;
                                ResultSet rs=si.executeQuery(sql);
                                String data="";
                                System.out.println("key is" + dqKey);
                                while( rs.next())
                                {
                                        data=
        
fieldpad(rs.getString("FLD1NUMERIC"),20,"0",false)+
        
fieldpad(rs.getString("FLD2CHAR"),20," ",true);
                                }
                                dqin.write(fieldpad(dqKey.trim(),26,"
",true),data);
                                retrycount=0;
                                dqKey="";
                        }
                }
                si.close();
        }
        catch(Exception e)
        {
                System.out.println("Fatal Error
"+e.getLocalizedMessage());
                System.out.println("\t data: " +dqKey);
                retrycount++;
                if (retrycount<3)
                        return true;
                        else
                        return false;
        }
        return false;
        }//close copytesttbl
}//close class 

-----Original Message-----
From: java400-l-bounces+jehimes=liberty.edu@xxxxxxxxxxxx
[mailto:java400-l-bounces+jehimes=liberty.edu@xxxxxxxxxxxx] 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

Jay,

I would love to see this too :)

Terry

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

Follow-Ups:

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.