Like most AS/400 programmers, I have spent a long time in the nice, safe, stable world of OS/400. Oh, I knew there were other operating systems out there, UNIX for instance, but they were used by a strange breed of programmers who did things like grepping. Those programmers used words like Telnet and FTP, and I wasnt sure I wanted to know what was involved in pinging someone. No, best to leave that kind of thing alone and stick to what I knew best.
Suddenly, a few UNIX boxes started to spring up around the office. Eventually, the UNIX programmers actually wanted to interact with the AS/400! Before I knew it, I found myself being dragged, kicking and screaming, into the world of TCP/IP (Transmission Control Protocol/Internet Protocol), the main protocol suite used by UNIX. Actually, it wasnt all that bad. With the latest versions of the OS/400 operating system, IBM has made it easy to configure and use TCP/IP on the AS/400. This article is mainly concerned with FTP (File Transfer Protocol), one of the tools in the TCP/IP protocol suite, and in particular, modifying the mapping tables used by FTP.
What is FTP?
FTP is the tool that lets you transfer files between TCP/IP systems, a lot like the Client Access file download function. With FTP, you can configure your AS/400 as either a host or a client. An FTP client logs into a host to initiate an FTP session. After successful login, the client can then issue some DOS-like commands to access files and directories on the host.
If youre like me, the thought of some stranger logging into your production AS/400 and juggling files around invokes images of your next career, the one where you ask Would you like any fries with that? To be on the safe side, we will discuss using the
AS/400 as an FTP client. As a matter of fact, I will relate my first real-life experience with FTP.
My assignment was to download an AS/400 file to our Novell network on a nightly basis. From there, our UNIX programmer would retrieve the file to display on our World Wide Web home page on the Internet. Being the Client Access expert, I set up a PC to download the file regularly using the Client Access router and commands. This solution ran well for a while, but eventually, two problems arose. Primarily, if we lost the router connection for some reason, the files did not get downloaded (until someone yelled at me, and I rebooted the PC). Secondly, I had to run a PC program to insert tabs as field delimiters in the downloaded file, because that is what the UNIX programs demanded, and Client Access did not offer that download option.
I fretted, I frowned, I scratched my head. There must be a more reliable way to get this file onto our UNIX machine, I thought. It bothered me that our transfer was not reliable. It disturbed me that we had to run an extra program to insert those darn tabs. Most of all, I didnt like the fact that a UNIX programmer (almost a human being, for crying out loud!) had to remember to transfer the file from our network every day. Like all good ideas, the answer finally came to me in the shower one morning as I was rubbing the shampoo out of my eyes: Why not use FTP to transfer the files? I set about constructing a scheduled program to push the file onto the UNIX box.
It was a great solution. The transfer was reliable, and I didnt have to rely on a UNIX programmer to retrieve the file since it went directly to our UNIX station. The only problem that remained was getting those pesky tab delimiters in the file once it was transferred. Thats where mapping tables came to the rescue.
FTP Mapping Tables
A mapping table is an AS/400 object (type *TBL) that is used to translate characters from one character set to another. For example, when a file is transferred from the AS/400 to another TCP/IP system, it is converted from the EBCDIC to the ASCII character set by default. The AS/400 does a look up on the table based on the value of the EBCDIC character and transmits the corresponding ASCII value. Fortunately, these tables can be modified, so you can translate an EBCDIC character to any ASCII character you wish.
Creating Your Own Mapping Tables
FTP uses two mapping tables, TBLASCIN for translating incoming files from ASCII to EBCDIC and TBLASCOUT to translate outgoing files from EBCDIC to ASCII. Figures 1 and 2 show examples of an outgoing table TBLASCOUT and incoming table TBLASCIN. These files can be created using the SEU command:
STRSEU SRCFILE(QGPL/QTBLSRC) +
SRCMBR(TBLASCOUT) +
TYPE(TXT)
Change the SRCMBR parameter to TBLASCIN when working with the incoming mapping table. We will be working with the outgoing mapping table to modify the EBCDIC-to-ASCII character translation.
At first glance, this table might look like a confusing jumble, but on closer inspection you will notice that it is made up of 256 pairs of characters. These pairs of characters are the hexadecimal representation of the EBCDIC character set. (A table showing the hexadecimal value of each EBCDIC character can be found in the back of the RPG/400 Reference SC09-1349-01.)
At my site, I needed to translate an EBCDIC character to an ASCII tab. I decided to use the EBCDIC greater-than sign (>), since that character would probably not be used anywhere else in the file. I then wrote a short RPG program that inserted the greater-than sign between each field. For example, a record that contained the FIRST NAME and LAST NAME fields would appear as:
JOHN>SMITH I then looked up the hexadecimal value of the greater-than sign, which was 6E or 110 in decimal. Beginning at the upper left hand corner of the mapping table, I began counting pairs of characters until I found the 110th pair. By changing this pair to 09 (the hexadecimal representation of an ASCII tab), the greater than sign would be changed to a tab when the file transfer occurred.
After creating the mapping table, it must be compiled using the command:
CRTTBL TBL(TBLASCOUT) +
SRCFILE(QGPL/QTBLSRC)
You must then grant authority to the table object using the command:
GRTOBJAUT OBJ(QGPL/TBLASCOUT) +
OBJTYPE(*TBL) +
USER(QTCP) AUT(*USE)
Using the Table
To use the mapping table, specify the table name when initiating an FTP session with a remote TCP/IP host. (This is assuming you have TCP/IP configured on your AS/400.)
The format of the command for starting the FTP client is:
STRTCPFTP +
RMTSYS(remote system name) +
TBLFTPIN(TBLASCIN) +
TBLFTPOUT(TBLASCOUT)
Notice the table names in the TBLFTPIN and TBLFTPOUT parameters. These are the incoming and outgoing mapping tables to be used when transferring a file.
Once a session has been started with the remote host, you must enter your login name and password to log in to the host. You can then transfer a file to the host using the FTP PUT command. The format for the PUT command is:
PUT localfile [remotefile]
The localfile parameter is the name of your AS/400 file in the format of Library/File Name.Member. The remotefile is the name you wish to give the file on the remote system. If this parameter is left blank, the file will have the same name as the AS/400 file.
If you need an easy, reliable method of transferring files, TCP/IP and FTP might be the answer for you. Although working with mapping tables might seem like a lot of work, once the changes are made, its a quick way of modifying your transferred file on the fly.
References
OS/400 TCP/IP Configuration and Reference V3R1 (SC41-3420, CD-ROM QBKANL00)
RPG/400 Reference (SC09-1349-01)
Figure 1: Outgoing Mapping Table (TBLASCOUT)
Figure 2: Incoming Mapping Table (TBLASCIN)
LATEST COMMENTS
MC Press Online