IDCAMS REPRO

The IDCAMS REPRO command copies records from one dataset to another. The input and output can be VSAM (KSDS, ESDS, RRDS) or sequential. REPRO is used to back up VSAM files, restore them, load an empty cluster from a sequential or VSAM source, or copy only a range of records (e.g. by key or RBA). You specify the input with INFILE(ddname) or INDATASET(dataset-name) and the output with OUTFILE(ddname) or OUTDATASET(dataset-name). Optional parameters include FROMKEY/TOKEY (for KSDS), FROMADDRESS/TOADDRESS (for ESDS), SKIP/COUNT, and REPLACE/NOREPLACE. This page explains the REPRO syntax, when to use it, how to load a KSDS (including the requirement that input be sorted by key), and how to do partial copies and backups.

What REPRO Does

REPRO reads records from the input dataset and writes them to the output dataset. It does not transform the record content (except possibly for record format mapping when copying between VSAM and sequential). For a KSDS or variable RRDS, REPRO builds or updates the index as it writes. So REPRO is the standard way to copy VSAM data: backup (VSAM to sequential or VSAM to VSAM), restore (sequential or VSAM to VSAM), initial load of an empty cluster, or extract of a key or RBA range. It is not a merge utility in the sense of merging two sorted files into one; it is a straight copy from one source to one target.

General Syntax

REPRO requires an input and an output. You can use DD names (INFILE, OUTFILE) or dataset names (INDATASET, OUTDATASET). Basic form:

jcl
1
2
3
4
5
6
7
8
9
REPRO - INFILE(ddname) | INDATASET(dataset-name) - OUTFILE(ddname) | OUTDATASET(dataset-name) - [ FROMKEY(key) | FROMADDRESS(rba) | FROMNUMBER(rrn) | SKIP(n) ] - [ TOKEY(key) | TOADDRESS(rba) | TONUMBER(rrn) | COUNT(n) ] - [ REPLACE | NOREPLACE ] - [ REUSE | NOREUSE ] - [ FILE(ddname) ]

You must specify one of INFILE or INDATASET for input and one of OUTFILE or OUTDATASET for output. The rest are optional. FILE(ddname) is used when the catalog (or other control information) is accessed via a DD name (e.g. for user catalog).

Input and Output: INFILE, OUTFILE, INDATASET, OUTDATASET

INFILE(ddname) and OUTFILE(ddname) use the DD names you allocate in JCL. The JCL must have a DD statement for each (e.g. //INPUT DD DSN=..., //OUTPUT DD DSN=...). INDATASET(dataset-name) and OUTDATASET(dataset-name) use the dataset name directly; IDCAMS uses the step or job catalog to find the dataset. Using DD names gives you control over DISP, volumes, and catalog; using dataset names is shorter when the dataset is already cataloged and you do not need special allocation.

Key and Range Parameters

REPRO parameters
ParameterDescription
INFILE(ddname) / INDATASET(dsname)Input: INFILE uses a DD name; INDATASET uses the dataset name directly. Input can be VSAM (KSDS, ESDS, RRDS) or sequential. One of these is required.
OUTFILE(ddname) / OUTDATASET(dsname)Output: OUTFILE uses a DD name; OUTDATASET uses the dataset name. Output can be VSAM or sequential. For a new VSAM cluster, define it first with DEFINE CLUSTER. One of these is required.
FROMKEY(key) / TOKEY(key)Key range for KSDS: only records with key >= FROMKEY and <= TOKEY are copied. Omit for full copy.
FROMADDRESS(rba) / TOADDRESS(rba)RBA range for ESDS: only records in that RBA range are copied. Use when you need a subset by position.
FROMNUMBER(rrn) / TONUMBER(rrn)RRN range for RRDS: only those relative record numbers are copied. Omit for full copy.
SKIP(n) / COUNT(n)SKIP(n): skip the first n input records. COUNT(n): copy at most n records. Useful for sampling or limiting the copy.
REPLACE / NOREPLACEREPLACE: overwrite existing records in the output that have the same key (KSDS) or RRN (RRDS). NOREPLACE: do not overwrite; duplicates may cause error or be skipped.
REUSE / NOREUSEFor output cluster: REUSE allows the cluster to be reused (e.g. emptied and reloaded). NOREUSE means it is not reused after delete. Often used with empty clusters being loaded.

Loading a KSDS: Sort Order Requirement

When the output is a KSDS (key-sequenced data set), REPRO builds the index as it writes records. The input records must be in ascending order by the primary key. If they are not, the index may be wrong, or the load may fail. So before REPRO into an empty KSDS, sort the input (e.g. with SORT or DFSORT) by the key field. For ESDS there is no key and no index; records are copied in the order they are read, and the output order is the entry order. For RRDS, records are typically in RRN order; REPRO fills slots by RRN. If you are copying from one RRDS to another, the RRNs are preserved.

Loading an ESDS

For an ESDS, no sorting is required. Records are appended in the order they are read. You can REPRO from a sequential file, from another ESDS, or from a KSDS (records will be in the order read from the source). The output ESDS must be empty or you use REPLACE only where applicable; ESDS has no key so REPLACE is typically not used in the same way as for KSDS.

REPLACE and NOREPLACE

When the output is a KSDS or RRDS and a record with the same key (KSDS) or RRN (RRDS) already exists, REPLACE means overwrite that record with the input record. NOREPLACE (often the default) means do not overwrite; the copy may skip the duplicate or fail depending on the implementation. Use REPLACE when you are refreshing the output with new data and want to overwrite existing records. Use NOREPLACE when you want to avoid overwriting (e.g. add-only load).

FROMKEY and TOKEY (Key Range)

For a KSDS input, FROMKEY(key) and TOKEY(key) limit the copy to records whose primary key is greater than or equal to FROMKEY and less than or equal to TOKEY. Only that subset of records is copied. Useful for backing up a key range, extracting a segment of the file, or copying one partition of the data. For ESDS you use FROMADDRESS(rba) and TOADDRESS(rba) to specify an RBA range. For RRDS you use FROMNUMBER(rrn) and TONUMBER(rrn) for an RRN range.

SKIP and COUNT

SKIP(n) skips the first n records from the input before copying. COUNT(n) copies at most n records. Use them for sampling (e.g. copy every 10th record by using multiple REPROs with SKIP/COUNT) or for limiting the size of a test copy.

Common Uses of REPRO

Common REPRO use cases
Use caseDescription
BackupREPRO from VSAM cluster to a sequential backup file or to another VSAM cluster. Run periodically or before changes.
RestoreREPRO from backup (sequential or VSAM) to the cluster. The cluster may be empty or you may use REPLACE to overwrite.
Load empty clusterDefine an empty cluster, then REPRO from a sequential file (or another VSAM) to load it. For KSDS, input must be sorted by key.
Partial copy (key range)Use FROMKEY/TOKEY to copy only records in a key range. Useful for extracts or splitting data.

Record Length Limit (VSAM to Sequential)

When copying from a VSAM dataset to a sequential dataset, the record length cannot exceed 32760 bytes on many systems. If your VSAM cluster has a larger maximum record size, REPRO to sequential will fail with an error. In that case use another VSAM cluster as the backup target, or use a utility that supports larger records.

Example: Full Copy (Backup)

jcl
1
2
3
4
5
6
7
8
9
10
//STEP1 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //INPUT DD DSN=MY.FILE.KSDS,DISP=SHR //OUTPUT DD DSN=MY.FILE.BACKUP,DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(5,1)),UNIT=SYSDA, // DCB=(DSORG=PS,RECFM=FB,LRECL=100,BLKSIZE=27920) //SYSIN DD * REPRO INFILE(INPUT) OUTFILE(OUTPUT) /*

Copies all records from the VSAM cluster MY.FILE.KSDS to the sequential backup MY.FILE.BACKUP. The output must be pre-allocated with appropriate LRECL and RECFM. After the job, MY.FILE.BACKUP contains a full backup that can be used with REPRO in reverse to restore.

Example: Key Range Copy

jcl
1
2
3
4
5
6
REPRO - INDATASET(MY.FILE.KSDS) - OUTDATASET(MY.FILE.SUBSET) - FROMKEY(1000) - TOKEY(1999)

Copies only records with key from 1000 to 1999 (inclusive) from MY.FILE.KSDS to MY.FILE.SUBSET. MY.FILE.SUBSET must be an existing empty KSDS with the same key definition and compatible record size. Input is read in key order; the subset is written in key order.

Example: Load Empty KSDS from Sequential

First define the empty cluster, then sort the sequential input by the key (if not already sorted), then REPRO:

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//STEP1 EXEC PGM=SORT //SORTIN DD DSN=MY.SEQ.INPUT,DISP=SHR //SORTOUT DD DSN=MY.SORTED.TEMP,DISP=(NEW,PASS),... //SYSIN DD * SORT FIELDS=(1,10,CH,A) /* //STEP2 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //INPUT DD DSN=MY.SORTED.TEMP,DISP=SHR //OUTPUT DD DSN=MY.NEW.KSDS,DISP=SHR //SYSIN DD * REPRO INFILE(INPUT) OUTFILE(OUTPUT) /*

STEP1 sorts the sequential file by the key (bytes 1–10, character, ascending). STEP2 copies the sorted records into the empty KSDS MY.NEW.KSDS. The cluster must already exist and be empty (or use REPLACE if you are refreshing). REPRO builds the index as it loads.

Key Takeaways

  • REPRO copies records from input to output. Use INFILE/INDATASET and OUTFILE/OUTDATASET. Both can be VSAM or sequential.
  • When loading a KSDS, input must be sorted in ascending order by the primary key. REPRO builds the index as it writes.
  • FROMKEY/TOKEY (KSDS), FROMADDRESS/TOADDRESS (ESDS), FROMNUMBER/TONUMBER (RRDS) limit the copy to a range.
  • REPLACE overwrites existing records in the output with the same key or RRN; NOREPLACE does not.
  • Record length cannot exceed 32760 bytes when copying from VSAM to sequential on many systems.

Explain Like I'm Five

REPRO is like photocopying a pile of papers from one folder to another. You say which folder is the source (INFILE or INDATASET) and which is the destination (OUTFILE or OUTDATASET). You can copy the whole pile or only the pages from page 10 to page 20 (FROMKEY/TOKEY). For a special kind of folder that has an index (KSDS), the papers must be in order by their number before you copy, or the index will be wrong. REPLACE means if the destination already has a page with the same number, you overwrite it with the new one.

Test Your Knowledge

Test Your Knowledge

1. When loading a KSDS with REPRO, how must the input records be ordered?

  • Any order
  • Descending by key
  • Ascending by primary key
  • By RBA

2. What do FROMKEY and TOKEY do in REPRO?

  • Sort the output
  • Limit the copy to a key range
  • Define the cluster
  • Skip the first n records

3. What is REPLACE in REPRO?

  • Replace the input file
  • Overwrite existing records in the output that have the same key or RRN
  • Replace the cluster name
  • Replace the DD name
Published
Updated
Read time4 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: IBM z/OS 2.5 documentationSources: IBM DFSMS Access Method Services, z/OS VSAM documentationApplies to: z/OS 2.5