Sunday, December 11, 2011

Copy some records from a particular key from a KSDS file using IDCAMS

We can use the FROMKEY and TOKEY parameters of the REPRO command of IDCAMS to copy certain number of records starting from a particular record and stop the copy at the desired record.


FROMKEY(key)

specifies the key of the first record you want copied. If you specify generic keys (a portion of the key followed by *), copying begins at the first record with a key matching the portion of the key you specified. You cannot specify a key longer than that defined for the data set. If you do, the data set is not copied. If the specified key is not found, the next higher key is used as the starting point for copying

TOKEY(key)
specifies the key of the last record you want copied. You can specify generic keys (that is, a portion of the key followed by *). If you specify generic keys, copying stops after the first record encountered that matches your key specifications. You cannot specify a key longer than that defined for the data set. If you do, the data set is not copied. If the specified key is not found, the next lower key is used as the end point for copying. 

Note: A hexadecimal key ending in X'5C' processes as a generic key.


The below example copies 10 records starting from the record having key '2538096230020001' from the input file.


//TEST JOB (1111,TEST),TEST,CLASS=X,MSGCLASS=8,NOTIFY=&SYSUID  
//SEARCH EXEC PGM=IDCAMS
//DD1 DD DISP=SHR,DSN=INPUT.KSDS.FILE 
//DD2 DD DISP=SHR,DSN=output file..
//SYSPRINT DD SYSOUT=(*)
//SYSIN DD *
REPRO INFILE(DD1) -
OUTFILE(DD2) -
FROMKEY(2538096230020001) -
COUNT(10)
/*

The below example copies all the records starting from the record having key '2538096230020001'  to the record having key '2538096230020010'

//TEST JOB (1111,TEST),TEST,CLASS=X,MSGCLASS=8,NOTIFY=&SYSUID  
//SEARCH EXEC PGM=IDCAMS
//DD1 DD DISP=SHR,DSN=INPUT.KSDS.FILE 
//DD2 DD DISP=SHR,DSN=output file..
//SYSPRINT DD SYSOUT=(*)
//SYSIN DD *

REPRO INFILE(DD1) -
OUTFILE(DD2) -
FROMKEY(2538096230020001) -
TOKEY(2538096230020010)
/*

Lets say the primary key in the KSDS file is defined as S9(5) COMP-3. In this case, you will have to specify the key in the hexadecimal format. That is, if you want to copy five records starting from key '12345', then, we will have to code the SYSIN card as shown below.

//SYSIN DD *
REPRO INFILE(DD1) -
OUTFILE(DD2) -
FROMKEY(X'12345C') -
COUNT(5)
/*

As specified in the note, the key in the above example ends with X'5C', so it will acts as generic key. That is key will be interpreted as "1234*".

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.