CL Command Reference - CPYTOSTMF

CL Command List > CPYTOSTMF Reference

Description:

The Copy To Stream File (CPYTOSTMF) command copies either a database file member or a save file to a stream file. Optional conversion of the data and reformatting is performed when copying a database file member. This command cannot be used to copy to or from a database file member on a remote system. Any overrides in effect for the database file member or the save file are not used by this command.

This command can operate on regular files and on the /dev/null character special file. A regular file is a file that supports the integrated file system input/output (I/O) operations open, read, and write.

Restrictions:

1. The database-member-path-name must be of the form name.object-type. For example, /QSYS.LIB/LIBA.LIB/FILEA.FILE/MBRA.MBR is the form required by the QSYS.LIB file system.

2. The save-file-path-name must be of the form name.object-type. For example, /QSYS.LIB/LIBA.LIB/SAVEFILEA.FILE is the form required by the QSYS.LIB file system.

3. The user must have the following authorities: v Execute (*X) authority to directories in the path name prefix of the database file, save file, stream file or conversion table.
. Read, execute (*RX) authority to the database file or save file.
. Write (*W) authority to the stream file if the stream file already exists.
. Write, execute (*WX) authority to the stream file¡¯s parent directory if the stream file does not already exist.
. If a conversion table was specified, object operational (*OBJOPR) to the conversion table.


Examples:

Example 1: Copying Data from a Database File Member to a Stream File Using Automatic Conversion

CPYTOSTMF FROMMBR(¡¯/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MYMBR.MBR¡¯)
TOSTMF(¡¯STMF.TXT¡¯)

This command copies the data contained in database file member /QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MYMBR.MBR to a stream file named STMF.TXT in the current working directory. Automatic data conversion uses the database file CCSID and the code page equivalent of the database file CCSID. The database file member records are stripped of trailing blanks, and CR and LF characters are inserted at the end of each record since ENDLINFMT(*CRLF) is the default value. If the stream file STMF.TXT already exists in the current working directory, the copy operation is not performed since STMFOPT(*NONE) is the default value.



Example 2: Copying Data from a Database File Member to a Stream File Using a Conversion Table

CPYTOSTMF FROMMBR(¡¯/QSYS.LIB/FINANCE.LIB/STAFF.FILE/MNGR.MBR¡¯)
TOSTMF(¡¯/MYDIR/FINANCE.MNG¡¯) CVTDTA(*TBL)
DBFCCSID(37) STMFCODPAG(437)
TBL(¡¯/QSYS.LIB/QUSRSYS.LIB/TBL1.TBL¡¯)
ENDLINFMT(*CRLF)

This command copies the data contained in database file member /QSYS.LIB/FINANCE.LIB/STAFF.FILE/MNGR.MBR to a stream file named FINANCE.MNG in the user directory /MYDIR. The data is converted using the conversion table TBL1.TBL contained in the directory /QSYS.LIB/QUSRSYS.LIB. The records in the database file member are trimmed of any trailing blanks, appended with CR and LF characters, and written to the stream file. The blank characters in the database file member are recognized from CCSID 37 specified on the DBFCCSID parameter. The inserted line-formatting characters: CR and LF, correspond to those of code page 437 specified on the STMFCODPAG parameter. If the stream file exists, it must have a code page of 437.



Example 3: Copying Data from a Database File Member to a Stream File Without Data Conversion

CPYTOSTMF FROMMBR(¡¯/QSYS.LIB/FINANCE.LIB/STAFF.FILE/MNGR.MBR¡¯)
TOSTMF(¡¯/MYDIR/FINANCE.MNG¡¯) CVTDTA(*NONE)
ENDLINFMT(*FIXED)

This command copies the data contained in database file member /QSYS.LIB/FINANCE.LIB/STAFF.FILE/MNGR.MBR to the stream file FINANCE.MNG in the user directory MYDIR without data conversion. The stream file data is written as fixed-length records of the same length as the database file records. No line-formatting characters are inserted since ENDLINFMT(*FIXED) is specified. If the encoding scheme of the stream file and the database file differ, the copy ends with an error message.



Example 4: Copying Data from a Save File to a Stream File

CPYTOSTMF FROMMBR(¡¯/QSYS.LIB/PACKAGE.LIB/SOFTWARE.FILE¡¯)
TOSTMF(¡¯/MYDIR/SOFTWARE¡¯)

This command copies the data contained in save file /QSYS.LIB/PACKAGE.LIB/SOFTWARE.FILE to the stream file /MYDIR/SOFTWARE. The stream file data is written as fixed-length records of the same length as the save file records. No line-formatting characters are inserted, nor is any data conversion performed.