Moving Data from ASCII to EBCDIC Systems

Overview

There are several ways to transcode ASCII data to EBCDIC:
  • Use FTP to write files (data) directly.
  • Use the dd command.
  • Use the iconv command.

Using FTP to Write Files Directly

Overview of Using FTP to Write Files Directly

FTP automatically performs the conversion when the type of file is specified as text (instead of binary). When you have direct access between the ASCII machine and EBCDIC machine, the best practice is to read the file directly. Direct access is enabled via a peripheral device on the ASCII machine that can read an EBCDIC tape. You can access the file via the FTP access method in a FILENAME statement. There are several advantages to this method of accessing EBCDIC data:
  • No file preprocessing is required.
  • You do not need to copy the source file.
  • The FTP access method works for fixed-length and variable-length records.
  • DATA step processing works as expected.
This method of accessing EBCDIC data applies if you have a 3480 or 3490 cartridge tape reader attached to your ASCII machine. In this case, you do not need to preprocess the file on an EBCDIC machine. You can read it directly from the tape by setting RECFM=S370VB and using the $EBCDICw. and S370Fxxxw.d informats.
In a FILENAME statement, specify the FTP access method and the source filename, and provide values for the HOST=, USER=, and PASS= options. The HOST= option specifies the name of the EBCDIC machine, USER= specifies the user account that you use to log on, and PASS= specifies the password that you use to log on. The FTP access method uses an FTP program on the ASCII machine to open a connection between the ASCII machine and the EBCDIC machine. The SAS system connects to and logs on to the mainframe machine with the specified user account and password. The FTP program transfers the file.

Example: Reading an ASCII File from SAS on z/OS

1 filename unixin '/net/bin/u/leking/sample.txt' encoding=latin1; 
2 data _null_;                                       
3       infile unixin;                                      
4       input;                                                       
5       put _infile_;                                 
6   run;                                                                                                                        
NOTE: The infile UNIXIN is:                             
      File Name=/net/bin/u/leking/sample.txt,   
      Access Permission=-rwxr-xr-x,Number of Links=1,   
      Owner Name=LEKING,Group Name=R@D,File Size=45,  
      Last Modified=Jan 19  2000                                  

This is a test.                                               
Another line.                                                 
End of file.   

Using the dd Command to Convert and Copy a File

About the dd Command

The dd command reads the InFile parameter or standard input, performs the specified conversion, and then copies the converted data to the OutFile parameter or standard output. The input block size and output block size can be specified to take advantage of raw physical I/O.
Use the cbs parameter value if you are specifying the block, unblock, ascii, ebcdic, or ibm conversion value. If an unblock or ascii value is specified, then the dd command performs a fixed-length to variable-length conversion. Otherwise, it performs a variable-length to fixed-length conversion. The cbs parameter value determines the fixed length.
CAUTION:
If the specified cbs parameter value is smaller than the smallest input block, the converted block is truncated.
After it finishes, the dd command reports the number of whole and partial input and output blocks. For more information about the dd command, see the dd manual page on your system.

dd Command Exit Status

The dd command returns the following exit values:
Item
Description
0
The input file was copied successfully.
>0
An error occurred.

Examples: dd Command Conversion

Here are two simple examples:
  • To convert an ASCII text file to EBCDIC, enter the following:
    dd if=text.ascii of=text.ebcdic conv=ebcdic
    This command converts the text.ascii file to EBCDIC representation and stores the EBCDIC version in the text.ebcdic file.
    When you specify the conv=ebcdic parameter, the dd command converts the ASCII ^ (circumflex) character to an unused EBCDIC character (9A hexadecimal) and the ASCII ~ (tilde) character to the EBCDIC ^ character (NOT symbol).
  • To use the dd command as a filter, enter the following:
    ls -l | dd  conv=ucase
    This command displays a long listing of the current directory in uppercase.
    The performance of the dd command and cpio command in the IBM 9348 Magnetic Tape Unit Model 12 can be improved by changing the default block size. To change the block size, use the chdev command as follows:
    chdev -l Device_name -a block_size=32k

Using the iconv Command to Convert a Text File

About the iconv Command

Use the iconv command to convert the encoding of a text file. Use one the following examples of syntax:
iconv –f FromCode –t ToCode FileName
iconv –l
For more information about the syntax and parameters for the iconv command, see the iconv manual page on your system.

iconv Command Exit Status

The iconv command returns the following exit values:
Item
Description
0
Input data was successfully converted.
1
The specified conversions are not supported, the input file cannot be opened or read, or there is a usage-syntax error.
2
An unusable character was encountered in the input stream.

Examples: iconv Command Conversion

Here are two simple examples:
  • To convert the contents of the mail.x400 file from code set IBM-850 and store the results in the mail.local folder, enter the following:
    iconv –f IBM-850 –t ISO8859-1 mail.x400 > mail.local
  • To convert the contents of a local file to the mail interchange format and send mail, enter the following:
    iconv –f IBM-943 –t fold7 mail.local > mail.fxrojas