The Copy To PC Document (CPYTOPCD) and the Copy From PC Document (CPYFRMPCD) commands are real time-savers for copying iSeries physical file members to and from PC text files (i.e., PC documents). These commands provide a two-way data conversion utility between the iSeries and PC via the shared folders system on the iSeries (also called the DLO and DLS systems).
The prompted CPYTOPCD command is shown below. (The CPYFRMPCD command is very similar.)
The translate table parameter
Of particular interest is the Translate Table parameter (TRNTBL keyword). The Translate Table parameter specifies the name of the translation table object (object type *TBL) to use for converting the data. As you are aware, the PC uses ASCII data encoding while the iSeries uses EBCDIC. When you specify the default value of *DFT for the translate table parameter, the CPYTOPCD command will use the system default EBCDIC-to-ASCII table and the CPYFRMPCD will use the system default ASCII-to-EBCDIC table.
The special value *NONE can be used if no data translation is required. This is useful when you need to copy a physical file from one iSeries to another with dissimilar media types (via e-mail or PC media). For example, use the CPYTOPCD command with TRNTBL(*NONE) to copy the data from an iSeries file to a shared folders document. Then attach the document (i.e., file) to an e-mail. Alternatively, copy the document from the "I:" drive to a PC diskette. Load the diskette in a PC connected to another iSeries and reverse the process (e.g., copy the file from the diskette to the I: drive, then use the CPYFRMPCD command with TRNTBL(*NONE) to copy it to a physical file). Note: The to-file on the CPYFRMPCD must already exist.
You can also specify one of the other many standard translation tables loaded on the iSeries. You can even specify your own table to accomplish specialized data conversion.
Format of PC data parameter
Another parameter that plays a part in data conversion is the format of PC data parameter (TRNFMT keyword). This parameter accepts one of two special values, *TEXT or *NOTEXT, and is ignored if *NONE is specified for the translation table parameter.
Use *TEXT to have the data converted to an ASCII text file. ASCII text files on a PC are stored in variable-length records. Trailing blanks are removed from each record and the records are delimited at the end by a sequence of special characters -- a carriage-return character followed by a line-feed character. PC programs know they have reached the end of a record when this sequence of characters is encountered. You can use just about any popular word processor to edit an ASCII text file.
Using the *NOTEXT special value will result in fixed length records being created in the PC file. Trailing blanks are not removed and no special end-of-record characters are added to the end of the records. The length of the records is equal to the record length of the physical file being copied. Use *NOTEXT when copying data into a PC database.
Three other handy uses of the CPYTOPCD and CPYFRMPCD commands
Once you become familiar with these commands you will find other uses for them. Here are three of my favorites.
- Edit iSeries source code in your favorite PC editor. Editing programs written in free-format languages in a Windows-based editor is a real treat after using the text-based SEU. The CPYTOPCD and CPYFRMPCD command can be used to copy to and from iSeries source files. When a source file is copied to a PC file, the sequence numbers and source dates are removed; when a PC text file is copied to an iSeries source file, sequence numbers are added and source dates are set to zeros, which is the major drawback. (If that is a problem, you can always use WebSphere.) Specify TRNFMT(*TEXT) when copying to or from source files for editing purposes.
- Find corrupted data faster. Sometimes corrupted data can hide like the proverbial needle in a haystack. The search facilities in SEU are very limited, and sometimes you just can't get the job done with the available query products. That's when we like to use the power of the search facilities found in many of today's most popular PC word processors. Simply copy the data to a PC file and load it into your favorite word processor.
- Transfer PC files via the iSeries. SNA Distribution Services (SNADS) is a convenient way to transfer files between two iSeries servers linked by modem. SNADS can also be used to transfer PC files, any type of PC files, even executable files (.EXE's). Use the CPYFRMPCD to copy the PC file to a physical file. Make sure to specify TRNTBL(*NONE) so the data is not translated. The iSeries file can be of any record length. Of course, if FTP is available on both the originating system and the destination system (one as a server and the other as a client), you can just do a binary transfer. It is easier and quicker.
About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.