Copy data using CL commands

There are two sets of CL commands that allow you to copy data between stream files and database file members.

CPYTOSTMF and CPYFRMSTMF commands

You can use the Copy from Stream File (CPYFRMSTMF) and Copy to Stream File (CPYTOSTMF) commands to copy data between stream files and database file members. You can create a stream file from a database file member by using the CPYTOSTMF command. You can also create a database file member from a stream file by using the CPYFRMSTMF command. If the file or member that is the target of the copy does not exist, it is created.

There are some limitations, however. The database file must be either a program-described physical file containing only one field or a source physical file containing only one text field. The commands give you a variety of options for converting and reformatting the data that is being copied.

The CPYTOSTMF and CPYFRMSTMF commands can also be used to copy data between a stream file and a save file.

CPYTOIMPF and CPYFRMIMPF commands

You can also use the Copy to Import File (CPYTOIMPF) and Copy from Import File (CPYFRMIMPF) commands to copy data between stream files and database members. The CPYTOSTMF and CPYFRMSTMF commands do not allow you to move data from complex, externally-described (DDS-described) database files. The word import file refers to the stream type file; the term typically refers to a file created for purposes of copying data between heterogeneous databases.

When copying from a stream (or import) file, the CPYFRMIMPF command allows you to specify a field definition file (FDF), which describes the data in the stream file. Or, you can specify that the stream files is delimited, and what characters are used to mark string, field, and record boundaries. Options for converting special data types such as time and date are also provided.

Data conversion is provided on these commands if the target stream file or database member already exists. If the file does not exist, you can use the following two-step method to get the data converted:

  1. Use the CPYTOIMPF and CPYFRMIMPF commands to copy the data between the externally-described file and a source physical file.
  2. Use the CPYTOSTMF and CPYFRMSTMF commands (which provide full data conversion regardless of whether the destination file exists) to copy between the source physical file and the stream file.

Here is an example:

Start of change
CPYTOIMPF 	FROMFILE(DB2FILE) TOFILE(EXPFILE) DTAFMT(*DLM)
    		   FLDDLM(';') RCDDLM(X'07') STRDLM(*DBLQUOTE) DATFMT(*USA) TIMFMT(*USA) 	
End of change

The DTAFMT parameter specifies that the input stream (import) file is delimited; the other choice is DTAFMT(*FIXED), which requires an field definition file to be specified. The FLDDLM, RCDDLM and STRDLM parameters identify the characters that act as the delimiters, or separators for fields, records, and strings.

The DATFMT and TIMFMT parameters indicate the format for any date and time information that is copied to the import file.

The commands are useful because they can be placed into a program, and they run entirely on your server. However, the interfaces are complex.

Related information
Copy to Stream File (CPYTOSTMF) command
Copy from Stream File (CPYFRMSTMF) command
Copy to Import File (CPYTOIMPF) command
Copy from Import File (CPYFRMIMPF) command
Control language (CL)