AS/4. 00 Tool. Box - com. AS4. 00 class. Hello. In a java program I'm trying to create an AS4. Box class's. In my program I have a java. Connection Object to my AS/4. AS4. 00 class will open a socket to my AS/4. Calling AS/400 CL Program using Client Access ODBC, VB, and ADO I am attempting to call a CL program and pass it 9 parameters. I am using VB6, Client Access Express ODBC driver, and ADO. The ServiceProgramCall class allows a user to call an AS/400 service program, passing data via input parameters, then accessing data returned via output parameters. ProgramParameter objects are used to pass data between the Java program and the AS/400 service program. ServiceProgramCall subclasses. I already have a Connection to my AS/4. Q is how can I use my current Conection instance to the AS/4. I'm creating the AS4. I don't want to create one more socket. Calling RPG on the AS4. Java. A practical article on calling RPG on the AS4. Java. RPG is the native language on the IBM as. Series, system i and now just “i”). In a recent project I had to find a way to call a number of RPG programs from a Java application. If you’re in this situation then there are a few options available. C# call AS400 RPG program The IBM System i is IBM's previous generation of midrange computer systems for IBM i users. In 2008, the introduction of V6R1 caused similar problems, although this time IBM preferred to call it a 'refresh'. In 2000 IBM renamed the AS/400 to iSeries, as. JTOpen is the open source version of the IBM Toolbox for Java Licensed Program Product (LPP). Here is just a sampling of the many IBM i resources you can access using JTOpen: Database -- JDBC (SQL) and record-level access (DDM) Integrated File. PCML (the subject of this article)SQL Stored procedure. Integrated web services server (IWS)Stored procedure. One possibility is to write a SQL stored procedure using RPG which could be called from Java using JDBC. This option may not be viable depending on the parameters your program needs. A stored procedure is good for returning result sets of records but you can only return one and you can’t pass one in. Integrated web services server (IWS)If you want to quickly expose an RPG program as a web service then you might want to look at IWS. This is a quick way to get up and running but there are a number of limitations. If you want multiple operations on the same wsdl you have to write them all as procedures in the same service program. If using a service program IWS only supports up to 7 parameters including both inputs and outputs. IWS only supports contract last development. In other words you have to write the code first to get the wsdl. The generated wsdl has a number of duplicated elements which you have to manually remove to tidy the appearance. If you change the parameters or operations you have to go through the whole wizard again on each machine you deploy to. Arrays are fixed size in RPG so IWS always returns all elements, even if some are simply blanks. PCMLThe most flexible method is Program Call Markup Language (PCML). This is an API that IBM provided for just this scenario. PCML is an XML language for defining the parameter list for an RPG program. This can then be used from a Java application. Generating the PCMLYou could write the pcml file by hand but a better way is to get the RPG compiler to generate it for you. First lets write a simple RPG program that we want to call. D CONVTEMP PR Extpgm('CONVTEMP'). D i. Celsius 9 3 Const. D o. Fahrenheit 9 3. D CONVTEMP PI. 5: D i. Celsius 9 3 Const. D o. Fahrenheit 9 3. We could get an API to return whatever we like here. Fahrenheit = ((i. Celsius * 9) / 5) + 3. Return. 1. 1: /end- free. Yes it’s the cliche web service example to convert temperature from Celsius into Fahrenheit. It’s a good one to start with though because it is has both an input and an output but is still fairly simple. Note that the input parameter has been defined as a const, this is significant when we generate the PCML. To generate the PCML from here you need to prompt compile and set the following options. Set PGMINFO to *PCML and INFOSTMF to a path on the ifs where you want your generated file to go e. Doing so gives the following PCML. Notice that the i. Celsius parameter has been set to input but o. Fahrenheit is inputoutput. This is a result of setting i. Celsius to a const parameter. When making a PCML call you must set a value for all input parameters. The default is inputoutput which can go both ways but is inconvenient if you don’t have an input value to set. Unfortunately there’s no language feature in RPG to set a parameter to output only so you have to adjust these manually. You can either use the IBM version that comes bundled with the AS4. JTOpen version. If you use maven then you can simply declare it as a dependency like this. Id> net. sf. jt. Id>. 3: < artifact. Id> jt. 40. 0< /artifact. Id>. 4: < version> 6. This works fine but sadly the JTOpen developers stopped publishing to maven central at version 6. Calling the program. This is everything you need to make the program call. The Java class below is a simple test that opens a connection, calls the program and returns the result. Big. Decimal. 2: import com. AS4. 00. 3: import com. Pcml. Exception. 4: import com. Program. Call. Document. Convert. Temperature. I created a file called CONVTEMP. To keep things simple this is the root classpath folder, the . The PCML API will automatically handle converting Java types to AS4. In this example the packed decimal from the AS4. Big. Decimal in Java. This is obviously a basic example that works as a proof of concept but there are a few additions worth mentioning if you want to use this in a production environment. Adding connection pooling. Each time you create an AS4. AS4. 00. Each new connection creates a new job on the AS4. It’s obviously a bit wasteful to then throw this away and start with a fresh connection on the next call. A much better solution is to create a connection pool. First you need to create the connection pool object. This code should live in it’s own class so the pool can be shared by different parts of the application. You could also load a properties file from the classpath to set the connection pool properties. AS4. 00. Connection. Pool pool = new AS4. Connection. Pool(). Now each time you want a connection you simply ask the pool. If no connections exist then one will be created. AS4. 00 as. 40. 0 = pool. Connection(. This should be done in the finally section of the try/catch block to ensure the connection is returned if an exception is thrown. Connection. To. Pool(as. Setting a library list. The PCML file generated had a fixed path to a specific library. In practice you may find the program exists in different libraries and you want to use the one at the top of the library list. To do this we must first change the PCML file to not hardcode the library. Change this: 1: < program name=. To brush this up a bit for production you only really need a few classes to wrap the connection pool and loading of properties. This would allow you to set the library list on different servers with a simple properties file. I would use spring to load the properties and register a bean that holds the connection pool. If you have to support multiple environments then you could set the library list each time you get a connection. Alternatively it might be more efficient to pass the environment to the RPG program and handle it on the AS4. Ben Thurley,Senior Software Engineer at Coral. Tree Systems Ltd. You can view Ben’s wordpress blog, with more articles, here. Ben has worked for Coral. Tree for over 5 years. In that time, his expertise and knowledge in new coding techniques and methods have helped us develop even better solutions for our customers. The views expressed in this article are not necessarily the views of Coral. Tree Systems Ltd.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2017
Categories |