View Full Version : Java for beginners
Guest.Visitor
01-01-1995, 02:00 AM
I am trying to determine what I need to do to set up JAVA. What I am trying to do is send an AS/400 flat file to the internet from a PC. I do not want to have to FTP the file down each time. I believe the best way to do this is with JAVA. I know I have JAVA running on my AS/400. I believe I need to get JDBC and the Java Development Kit set up on the PC. If this is the best approach to handle what I am trying to accomplish, how do I install JDBC & the JDK on the PC. I searched the internet but could not find any downloads. Any advise would be greatly appreciated. Thanks. Ron
Guest.Visitor
04-07-2000, 08:27 PM
Ron: please keep us posted; severarl respondents are interested in this as well...
Guest.Visitor
04-08-2000, 03:11 PM
Sure will.
J.Pluta
04-08-2000, 09:07 PM
I am trying to determine what I need to do to set up JAVA. What I am trying to do is send an AS/400 flat file to the internet from a PC. I do not want to have to FTP the file down each time. I believe the best way to do this is with JAVA. I know I have JAVA running on my AS/400. I believe I need to get JDBC and the Java Development Kit set up on the PC. If this is the best approach to handle what I am trying to accomplish, how do I install JDBC & the JDK on the PC. I searched the internet but could not find any downloads. Any advise would be greatly appreciated. Thanks. Actually, short of FTP or Client Access, the easiest way to download a file is using the IBM Java Toolbox for the AS/400. I have a web page that shows all the steps needed to download and install the JDK and the toolkit; in fact, Bob just got done using it. You can find it at the following URL: http://www.zappie.net/java/javatorium/installi.htm In fact, the last step is to install a program that reads a single record from a file. You could use that as a starting point for retrieving your flat file from the AS/400. If you decide to give it a try, let me know if you need any help. <a href="//www.java400.net?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJ vkG9"><img > src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net</a> - where the AS/400 speaks Java with an RPG accent Home of PBD2.0 (//www.zappie.net/revitalization?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJv kG9), the <font > color=red>FREE</font> Java/400 Client/Server <font > color=blue>Revitalization</font> Toolkit
Guest.Visitor
04-09-2000, 01:21 PM
Hi Ron, Let me say first that, if you just need to grab the file with no edits or modifications, FTP may be a superior solution to java ( or any other language. ) As always, depends on your situation and exactly what you want to do. As to java: Whenever you need java development software and runtimes, the first place you should go to is http://www.javasoft.com This is java's home and there are also many other resources and links there. Although Joe's directions should be adequate to get you started on 1.1, the download and instructions are at: http://www.javasoft.com/products/jdk/1.1/index.html http://www.javasoft.com/products/jdk/1.1/installation-win32-x86.html For whatever reason, the installation instructions are not included in the download. IBM also has a well received version of 1.1.8, available at: http://www.ibm.com/java/jdk/118/index.html http://www.ibm.com/java/jdk/118/installation.html Java 1.2 has been out for over a year and a half now and includes Swing and many improvements. You may prefer to get that at: http://www.javasoft.com/products/jdk/1.2/index.html http://www.javasoft.com/products/jdk/1.2/install-windows.html With 1.2 you no longer need to have java/jre.exe in your path, nor do you need the core java classes in your CLASSPATH. You'll still need CLASSPATH ( or sent as an argument ) for third party classes or your own when they reside in other directories, although you can use the extension mechanism ( carefully ) to obviate CLASSPATH entries. 1.3 is still early access, but is at Release Candidate 2 a/o this date. You do not need java on the 400 to access data, although you're often better off doing it that way. However, if java is loaded ( and current, ) you can get the Toolbox from your own 400. It resides in the /QIBM/ProdData/HTTP/Public/jt400/lib directory. Look for jt400.zip or jt400.jar. The latest versions and documentation are always on-line at: http://www.as400.ibm.com/toolbox/downloads.htm and portions of the Toolbox have gone open source. Best, Joe Sam Joe Sam Shirah Autumn Software Consulting/Development/Outsourcing Please Note New Email: jshirah@attglobal.net Visit our User Group at: http://www.jax400.com
J.Pluta
04-09-2000, 02:02 PM
Java 1.2 has been out for over a year and a half now and includes Swing and many improvements. You may prefer to get that at: My only caveat with using Java 2 (Sun's name for JDK release 1.2) is that it might not be compatible with your AS/400 release. V4R3 is at version 1.1.7 of the JVM; this is binary compatible with 1.1.8, so I use 1.1.8 whenever I teach. Visual Age for Java version 2 doesn't support Java 2, either. So, you might want to think things through before leaping into Java 2. Do you plan to run your classes on a pre-V4R4 AS/400? Are you going to use Visual Age for Java 2.0? If either of those are "yes", stick with JDK1.1.8 and Swing for now, since the syntax is 100% upward compatible with Java 2. The only thing you really lose is the collections classes, and for beginning Java they're not that essential. And once V4R4 and VAJ3.0 become prevalent, I'll switch to Java 2, or maybe even release 1.3 (1.3 is first and foremost a performance release, so compatibility should be pretty high). <a href="//www.java400.net?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJ vkG9"><img > src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net</a> - where the AS/400 speaks Java with an RPG accent Home of PBD2.0 (//www.zappie.net/revitalization?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJv kG9), the <font > color=red>FREE</font> Java/400 Client/Server <font > color=blue>Revitalization</font> Toolkit
Guest.Visitor
04-10-2000, 07:51 AM
Joe and Joe, Thanks for the response. I believe I do want to use Java instead of FTP, unless you know of a reason not to. Basically, I want to send raw EDI data (flat file, via the internet. Propably as an E-mail for now. I have downloaded the JDK-1_1_8_003 and the IBM Toolbox file. The zappiw web site mentions Swing 1.1. Do I need to download that as well? Ron
Guest.Visitor
04-10-2000, 08:31 AM
Hi Ron, You might as well download it, although whether you'll need it or not depends on what you plan to do for a user interface. Swing is another name for the Java Foundation Classes ( JFC, ) which is a pure java, 99+% lightweight GUI toolkit. "Lightweight" here means that the vast majority of the code has no dependency on the native windowing kit. The AWT, which was/is the original GUI mapped directly to native widgets/components ( termed "heavyweight." ) Incidentally, assuming that an SMTP server is available on the 400 or locally off the LAN, which sounds like it is this case, you could actually do everything programmatically off the 400, using JavaMail or other SMTP client tools around. Oh, and my friends call me: Joe Sam
J.Pluta
04-10-2000, 08:51 AM
Joe Sam told you everything you need to know about Swing: it's a lightweight graphical user interface framework. It's not needed for your particular project, but you'll need it if you ever do any UI programming, or if you use any of my packages. <a href="//www.java400.net?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJ vkG9"><img > src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net</a> - where the AS/400 speaks Java with an RPG accent Home of PBD2.0 (//www.zappie.net/revitalization?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJv kG9), the <font > color=red>FREE</font> Java/400 Client/Server <font > color=blue>Revitalization</font> Toolkit
S.Mildenberger
04-10-2000, 12:23 PM
We are using the SMTP server on the 400 to do exactly this. The 400 SMTP server forwards the mail to our Exchange server. A physical file containing the edi data is copy to a folder with CPYTOPCD and then sent as e-mail with SNDDST. For easy directions in setting up the SMTP server go here, they also have a sample program which works just like I described. http://www.bytware.com/freestuff.htm Scott Mildenberger
Guest.Visitor
04-10-2000, 05:15 PM
Scott, I see how Bytware gives instructions how to send an E-mail from a spool file. I assume it can be done with a physical file as well. Are there instructions on how to retrieve an E-mail and load it back to a physical file on the AS/400? I addition to sending as an E-mail, I would like to be able to receive and process this data as well. Thanks. Ron
Guest.Visitor
04-10-2000, 11:52 PM
Hi Ron, Sending and receiving email involves different protocols. Outgoing mail is generally done using SMTP; Incoming mail typically uses IMAP or POP3. Bytware's code ( which, incidentally uses CPYSPLF, so it is actually, as one might expect, sending a file attachment ) is apparently only set up to send mail. The AS/400 has a POP3 server and no doubt by going through the AnyMail manual, one could do accomplish the task in a classic 400 manner, as do the examples using SNDDST. To go back to java, though, the javamail API can handle SMTP, IMAP and POP3, with attachments ( known as multipart messages. ) It can also do this without a gateway ( assuming you can ping your mailservers, as is required also in the AS/400 solution, ) and -- I say with ducked head -- is portable, at least from the point of picking up the data. There are also other java SMTP and, I assume, POP3 packages available. I don't claim that this is a project for java beginners. Of course, one might say the same for a 400 version. Last, not to rain on the party, but since you have said this is for EDI purposes, standard mail is not secure and both you and your partners should be aware of the implications. I also had a situation a few weeks ago wherein mail that I sent did not reach the intended recipients. With all the vaguaries and complexities of processing email, I wonder if a couple of socket programs would not be more reliable in transmission and easier to program and maintain. Security issues could be handled at some point by encryption, SSL, digital signing, etc. We've moved a bit from installing the jdk, huh? Good Luck. Best, Joe Sam Joe Sam Shirah Autumn Software Consulting/Development/Outsourcing Please Note New Email: jshirah@attglobal.net Visit our User Group at: http://www.jax400.com
Guest.Visitor
04-11-2000, 06:46 AM
Joe, Am I correct in deterining that the utility from Byteware is not the best approach for sending & receiving EDI data? I will continuw trying to get the JDK running unless you are suggesting an alternate method with socket programming that you mentioned. Ron
S.Mildenberger
04-11-2000, 08:59 AM
Ron, We haven't tried receiving edi this way yet. I envision doing it by having our Exchange server put the messages on a mapped network drive that is in the AS/400 IFS and then having a program grab them from there. Only thought about it but not implemented. Scott
Guest.Visitor
04-11-2000, 11:45 AM
Ron, Joe's advice to try sockets for a secure transmission is a good idea if you are interested in protecting the contents of the data from prying eyes. Certainly you could also guarantee delivery that way as well. If writing socket code is more than you want to tackle, maybe a ftp mailbox will work for you. We are using an ftp mailbox to deliver edi over the internet. We set up directories in the IFS corresponding to in and out mailboxes for all our trading partners. The partners connect to our mailbox server (on an as/400), get their files and deposit any files for us. The whole approach is rather simple. Since we make the trading partner responsible for clearing their mailbox, they can make sure the retrievals are successful before deleting them from the mailbox. There is some sample code for a simplified mailbox in the Dec 1999 MC (shameless plug). Right now we are asking our trading partners to write their own code for connecting to our ftp mailbox and retrieving/depositing files. If I had some spare time, though, it would be easy to write a java application to give to trading partners to make the whole process a "no-brainer." We also send these same IFS files as attachments to email from within our java applications running on the as/400. This is very easy to do in Java with the Java mail api. You dont need any email server running on your as/400 to use this approach, just the ability to specify the ip address of your email server (whether it be exchange or domino or whatever) in your as/400 host table. Send me an email at agarrison@logtech.com if you are interested in some sample java code. I am out of town this week, but I can send it to you Monday.
Guest.Visitor
04-13-2000, 01:52 PM
O.K. Joe, I have downloaded and installed my JDK, Swing 1.1, and IBM Toolbox for AS/400. I completed step 6 (from the Zappie site), Test Record Level Access. I saw my 1st line in my RPG program. But back to my original question, How do I access a Physical file on THe AS/400? Thanks. Ron
Guest.Visitor
04-13-2000, 02:29 PM
Put the name of the physical file in the JAVA command; you might get some goofy looking stuff. I don't know if the JAVA thing converts packed decimal et c.
Guest.Visitor
04-13-2000, 02:33 PM
How do I access a Physical file on THe AS/400? Thanks. Here's a sample program from IBM's website. <PRE> /////////////////////////////////////////////////////////////////////////////// // // Record-Level Access example. This program uses the record-level // access classes to read records by key from an AS/400 file. // The user will be prompted for the AS/400 system name to which to run and // the library in which to create file QCUSTCDTKY. // // Command syntax: // java RLKeyedFileExample // // This program will copy the records from CA/400's sample database file // (qcustcdt in library QIWS) to file QCUSTCDTKY which has // the same format as QIWS/QCUSTCDT but has set the CUSNUM field as the key // for the file. // /////////////////////////////////////////////////////////////////////////////// // // This source is an example of AS/400 Toolbox for Java "Record-level access". // IBM grants you a nonexclusive license to use this as an example // from which you can generate similar function tailored to // your own specific needs. // // This sample code is provided by IBM for illustrative purposes // only. These examples have not been thoroughly tested under all // conditions. IBM, therefore, cannot guarantee or imply // reliability, serviceability, or function of these programs. // // All programs contained herein are provided to you "AS IS" // without any warranties of any kind. The implied warranties of // merchantablility and fitness for a particular purpose are // expressly disclaimed. // // AS/400 Toolbox for Java // (C) Copyright IBM Corp. 1997 // All rights reserved. // US Government Users Restricted Rights - // Use, duplication, or disclosure restricted // by GSA ADP Schedule Contract with IBM Corp. // /////////////////////////////////////////////////////////////////////////////// import java.io.*; import java.util.*; import java.math.*; import com.ibm.as400.access.*; public class RLKeyedFileExample { public static void main(String parameters) { // Created a reader to get input from the user BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in),1); // Declare variables to hold the system name, library, file and member names String systemName = ""; String library = ""; // Get the system name from the user System.out.println(); try { System.out.print("System name: "); systemName = inputStream.readLine(); System.out.print("Library in which to create file QCUSTCDTKY: "); library = inputStream.readLine(); } catch(Exception e) { System.out.println("Error obtaining user input."); e.printStackTrace(); System.exit(0); } // Create AS400 object and connect for the record level access service. AS400 system = new AS400(systemName); try { system.connectService(AS400.RECORDACCESS); } catch(Exception e) { System.out.println("Unable to connect for record level access."); System.out.println("Check the readme file for special instructions regarding record level access"); e.printStackTrace(); System.exit(0); } RecordFormat qcustcdtFormat = null; try { // Create the RecordFormat object for creating the file. The record format for the new // file will be the same as the record format for file QIWS/QCUSTCDT. However we will // make the CUSNUM field a key field. AS400FileRecordDescription recordDescription = new AS400FileRecordDescription(system, "/QSYS.LIB/QIWS.LIB/QCUSTCDT.FILE"); // There is only one record format for the file, so take the first (and only) element // of the RecordFormat array returned as the RecordFormat for the file. System.out.println("Retrieving record format of QIWS/QCUSTCDT..."); qcustcdtFormat = recordDescription.retrieveRecordFormat()0; // Indicate that CUSNUM is a key field qcustcdtFormat.addKeyFieldDescription("CUSNUM"); } catch(Exception e) { System.out.println("Unable to retrieve record format from QIWS/QCUSTCDT"); e.printStackTrace(); System.exit(0); } // Create the keyed file object that represents the // file we will create on the AS/400. We use a QSYSObectPathName object // to get the name of the file into the correct format. QSYSObjectPathName fileName = new QSYSObjectPathName(library, "QCUSTCDTKY", "*FILE", "MBR"); KeyedFile file = new KeyedFile(system, fileName.getPath()); try { System.out.println("Creating file " + library + "/QCUSTCDTKY..."); // Create the file using the qcustcdtFormat object file.create(qcustcdtFormat, "Keyed QCUSTCDT file"); // Populate the file with the records contained in QIWS/QCUSTCDT copyRecords(system, library); // Open the file for read-only access. Because we will be randomly // accessing the file, specify a blocking factor of 1. The // commit lock level parameter will be ignored since commitment // control has not been started. file.open(AS400File.READ_ONLY, 1, AS400File.COMMIT_LOCK_LEVEL_NONE); // Assume that we want to display the information for customers // 192837, 392859 and 938472 // The CUSNUM field is a zoned decimal field of length 6 with // no decimal positions. Therefore, the key field value is // represented with a BigDecimal. BigDecimal keyValues = {new BigDecimal(192837), new BigDecimal(392859), new BigDecimal(938472)}; // Create the key for reading the records. The key for a KeyedFile // is specified with an Object Object key = new Object1; Record data = null; for (int i = 0; i < keyValues.length; i++) { // Setup the key for reading key0 = keyValuesi; // Read the record for customer number keyValuesi data = file.read(key); if (data != null) { // Display the record only if balance due is greater than // zero. In that case display the customer name and // the balance due. The following code pulls fields out // of the record by field name. As the field is retrieved // from the record it is converted from AS/400 format to // Java format. if (((BigDecimal)data.getField("BALDUE")).floatValue() > 0.0) { System.out.print((String) data.getField("INIT") + " "); System.out.print((String) data.getField("LSTNAM") + " "); System.out.println((BigDecimal) data.getField("BALDUE")); } } } // All done with the file file.close(); // Get rid of the file from the user's system file.delete(); } catch(Exception e) { System.out.println("Unable to create/read from QTEMP/QCUSTCDT"); e.printStackTrace(); try { file.close(); // Get rid of the file from the user's system file.delete(); } catch(Exception x) { } } // All done with record level access; disconnect from the // record-level access server. system.disconnectService(AS400.RECORDACCESS); System.exit(0); } public static void copyRecords(AS400 system, String library) { // Use the CommandCall class to run the CPYF command to copy the records // in QIWS/QCUSTCDT to QTEMP/QCUSTCDT CommandCall c = new CommandCall(system, "CPYF FROMFILE(QIWS/QCUSTCDT) TOFILE(" + library + "/QCUSTCDTKY) MBROPT(*REPLACE)"); try { System.out.println("Copying records from QIWS/QCUSTCDT to " + library + "/QCUSTCDTKY..."); c.run(); AS400Message msgs = c.getMessageList(); if (!msgs0.getID().equals("CPC2955")) { System.out.println("Unable to populate " + library + "/QCUSTCDTKY"); for (int i = 0; i < msgs.length; i++) { System.out.println(msgsi); } System.exit(0); } } catch(Exception e) { System.out.println("Unable to populate " + library + "/QCUSTCDTKY"); System.exit(0); } } } </PRE>
J.Pluta
04-13-2000, 05:34 PM
As Bob suggested, simply use the library and name of the physical file. QRPGSRC is a physical file - it's a source physical file, but it's a physical file nonetheless. Change the name to a non-source physical file, and the program will work the same way. If you want to do something specific, why don't you try to spell it out and maybe I can point you in the right direction. <a href="//www.java400.net?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJ vkG9"><img > src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net</a> - where the AS/400 speaks Java with an RPG accent Home of PBD2.0 (//www.zappie.net/revitalization?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJv kG9), the <font > color=red>FREE</font> Java/400 Client/Server <font > color=blue>Revitalization</font> Toolkit
J.Pluta
04-13-2000, 05:38 PM
I know it handles Zoned Decimal just fine, Bob, not as sure about Packed Decimal. <a href="//www.java400.net?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJ vkG9"><img > src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net</a> - where the AS/400 speaks Java with an RPG accent Home of PBD2.0 (//www.zappie.net/revitalization?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJv kG9), the <font > color=red>FREE</font> Java/400 Client/Server <font > color=blue>Revitalization</font> Toolkit
Guest.Visitor
04-13-2000, 06:48 PM
It also handles date data-type; I'm checking on packed decimal...
Guest.Visitor
04-13-2000, 07:24 PM
Packed decimal works.
Guest.Visitor
04-14-2000, 11:41 AM
Joe, what I am trying to do is access ALL of the records in a physical file, not just the first one. This is an EDI flat file. None of the data will be packed, just one 80 byte alpha field. I would like to send this file (as an E-mail) for now). I would like my Trading partner to be able to retrieve the file and process the data. In addition, I would like to be able to receive a file in a similar format so that I can process it on my AS/400. Thanks. Ron
J.Pluta
04-14-2000, 12:35 PM
The following code will read through the file and call the "process" method for every record in the file. Assuming the field named MYFLD exists in a file named MYFILE in library MYLIB, this code will pass the contents of MYFLD as a string to the process method. What you do with it then is up to you. If your goal is to create a text file, you could simply output the string with "System.out.println()", and then redirect the standard output to a text file. You could then send that file as an attachment to an Email, but I'm not that familiar with email APIs in Java. <pre>import com.pbd.pub.jdb400.*; public class ProcessFile { public static void main(String args) { Jdb400SequentialFile file = new Jdb400SequentialFile("MYLIB/MYFILE"); while (file.read()) process(file.getAlpha("MYFLD")) } }</pre> <a href="//www.java400.net?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJ vkG9"><img > src="//www.zappie.net/java/_derived/index.htm_cmp_zero110_vbtn_p.gif" width="140" height="60" border="0" alt="Java400.net - Java/400 Freeware" align="middle"> Java400.Net</a> - where the AS/400 speaks Java with an RPG accent Home of PBD2.0 (//www.zappie.net/revitalization?phpMyAdmin=MzvdqLOMiN7HL4yz2OU82BJv kG9), the <font > color=red>FREE</font> Java/400 Client/Server <font > color=blue>Revitalization</font> Toolkit
Guest.Visitor
04-16-2000, 10:21 AM
Hi Ron, I'm sure I'll get flamed for this, but you/your shop needs some assistance on this, in house if you have it, outside if not -- assuming the project is worth doing for your business. I think you have seen that people here are more than willing to help, but forums are just not always the answer; not all problems are un-complex or un-complicated ( to make up some words ;-), ) or amenable to ( of necessity ) piecemeal answers. In addition, I think that you ( being your company ) and your trading partner(s) need a review, with or without assistance, as to your options and the best way that both of you can carry them out. Again, I'm prepared for flames, but I think all the postings so far bear me out. On another forum a requester blasted me ( and basically everyone else there ) for not providing a "FAST HOW TO" ( quote/unquote, ) but often there is no such creature and "just do it" can actually be much slower and lead to non-professional results. -- Donning fire protection equipment -- Best and good luck, Joe Sam
Guest.Visitor
04-18-2000, 02:32 PM
Alex, I looked through DEC 1999 MC. I didn't happen to see the article for setting up a mailbox. What is the article? Thanks. Ron
Guest.Visitor
04-18-2000, 04:05 PM
Ron, It is in the systems admin section called "Locking Down Your ftp Server". The sample code which can be downloaded from the MC website is for a secure ftp mailbox. Alex Garrison
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.