Copying data

By default, the DSC (Data Set Copy) function simply copies the contents of one data set to another (using DFSORT if available). The following excerpt from a batch job enhances the DSC function to:

  • Include in the input stream only those records whose first two characters are “01” or “02”.
  • Add two lines to SYSPRINT that tally the total values of the “salary” (a 4-byte packed decimal field found at position 27) and “month 1 payment” (a 4-byte binary field found at position 31) fields in the “01”-type records.
  • In each output record, change the first occurrence of “Grant Smith” to “Fred Bloggs”.
  • Write only those records whose first two characters are “02” to the default output data set (DDOUT), adding a sequence field in 1-6 and shifting the rest of the data over.
  • Write to another data set (OUT01) only those records whose first two characters are “01”, unchanged.
  • Print the first ten output records (to SYSPRINT) in hexadecimal format.
⋮
//DDIN     DD DSN=FMNUSER.FMNAFDAT.SAMPMVS,DISP=SHR
//DDOUT    DD DSN=FMNUSER.FMNAFDAT.SAMP02,DISP=SHR
//OUT01    DD DSN=FMNUSER.FMNAFDAT.SAMP01,DISP=SHR
//SYSIN    DD *
$$FILEM DSC INPUT=DDIN,
$$FILEM     PROC=*
*FASTPROC
 INCLUDE COND=(1,2,CH,EQ,C'02',OR,1,2,CH,EQ,C'01')
 OUTFIL FNAMES=DDOUT,INCLUDE=(1,2,CH,EQ,C'02')
 OUTREC=(SEQNUM,6,ZD,1,74)
 OUTFIL FNAMES=OUT01,INCLUDE=(1,2,CH,EQ,C'01')
*REXXPROC
 outrec = change(outrec,'Grant Smith','Fred Bloggs')
 /* Print the first 10 output records in hex */
 if prtcount() < 10 then print(outrec,'hex')
 if fld(1,2) == '01' then do
   tally(27,4,'P','Salary Total')
   tally(31,4,'B','Total Month 1 Payment')
 end
/+
/*
⋮