Chapter 2. Introducing File Manager 41
2.1.10 Replace a string in a specific location in a file
If you need to unconditionally replace a string in one location of a file, you can use this utility.
The code to perform this function with File Manager is shown in Example 2-11.
Example 2-11 File Manager string replace batch step
//*
//* FILE MANAGER BATCH: REPLACE A STRING IN A SPECIFIC LOCATION
//*
//STEP01 EXEC PGM=FMNMAIN
//STEPLIB DD DSN=FMN.V4R1M0.SFMNMOD1,DISP=SHR
//* DD DSN=IGY.SIGYCOMP,DISP=SHR
//SYSPRINT DD SYSOUT=*
//FMNTSPRT DD SYSOUT=*
//SYSTERM DD SYSOUT=*
//EDITFILE DD DISP=OLD,DSN=YOUR.FILE.TO.EDIT
//SYSIN DD *
$$FILEM DSU INPUT=EDITFILE,
$$FILEM PROC=*
OUTREC=OVERLAY(‘vaLUE’,INREC,11)
/+
What is happening in this step
The File Manager program keyword DSU invokes the Data Set Update utility, which is only
available in batch.
The utility reads records sequentially from the input file. When File Manager processes them,
it uses two built-in REXX variables, INREC and OUTREC to refer to the input and output records.
In this case, we use a standard REXX function, OVERLAY, to indicate a string should be placed
at a specific location. This is assigned to the output record that is written to the file a portion of
which is shown in Example 2-12.
Example 2-12 Output from string replace batch job
IBM File Manager for z/OS and OS/390
$$FILEM DSU DSNIN=DAVIN6.FILE.TO.EDIT,
$$FILEM PROC=*
13 record(s) read
13 record(s) updated
2.1.11 Copy selected variably blocked records to another file
If you need to copy selected records from a production file to a test file, you can use this
utility. In this case there are multiple criteria and there is only one output file. This example
also demonstrates how File Manager processes new file allocation and variable blocked
records.
The steps necessary to perform this function using REXX with File Manager follow. First you
select option 3.3 from the main FM menu, producing a panel as shown in Figure 2-21.
42 Using IBM Application Development Tools for z/OS and OS/390
Figure 2-21 Option selection from main File Manager panel
By selecting Use proc with the generic ‘*’ and pressing Enter, you can now enter record
selection criteria for the copy. In this example we are selecting only those records with either
a C, G, L, M, or S in column 3, as shown in Figure 2-22.
Figure 2-22 Record selection criteria
By pressing Enter, followed by PF3, you can now enter the name of the file to which the data
is to be copied. In this example, we are dynamically defining a new file (SEQFILEX) with the
same characteristics as the input file. These steps are shown in Figure 2-23, Figure 2-24, and
Figure 2-25.
Chapter 2. Introducing File Manager 43
Figure 2-23 Name of file to be copied to 1 of 3
Figure 2-24 Name of file to be copied to 2 of 3
44 Using IBM Application Development Tools for z/OS and OS/390
Figure 2-25 Name of file to be copied to 2 of 3
Since we selected Batch execution for this Copy job, we are presented with the JCL as
shown in Example 2-13.
Example 2-13 JCL for batch
//FILEMGR EXEC PGM=FMNMAIN
//STEPLIB DD DSN=FMN.V4R1M0.SFMNMOD1,DISP=SHR
//* DD DSN=IGY.SIGYCOMP,DISP=SHR
//SYSPRINT DD SYSOUT=*
//FMNTSPRT DD SYSOUT=*
//SYSTERM DD SYSOUT=*
//SYSIN DD *
$$FILEM DSC DSNIN=REDBK2.TEST.SEQFILE,
$$FILEM POSITION=0,
$$FILEM DISP=MOD,
$$FILEM DSNOUT=REDBK2.TEST.SEQFILEX,
$$FILEM PROC=*
*FASTPROC
INCLUDE COND=(3,1,SS,EQ,C'C,G,L,M,S')
/+
Submitting this job, we see the successful execution report as shown in Example 2-14.
Example 2-14 Successful completion
IBM File Manager for z/OS
$$FILEM DSC DSNIN=REDBK2.TEST.SEQFILE,
$$FILEM POSITION=0,
$$FILEM DISP=MOD,
$$FILEM DSNOUT=REDBK2.TEST.SEQFILEX,
$$FILEM PROC=*
67 record(s) read
20 record(s) successfully copied
Chapter 2. Introducing File Manager 45
Alternatively, we could have used a REXX procedure to obtain the same result. For this
method, we coded the procedure as shown in Figure 2-26. Remember, though, that the
performance when processing large data sets is significantly better if DFSORT can be used.
Figure 2-26 REXX procedure
Following this through, we see JCL created as shown in Example 2-15.
Example 2-15 JCL created
//FILEMGR EXEC PGM=FMNMAIN
//STEPLIB DD DSN=FMN.V4R1M0.SFMNMOD1,DISP=SHR
//* DD DSN=IGY.SIGYCOMP,DISP=SHR
//SYSPRINT DD SYSOUT=*
//FMNTSPRT DD SYSOUT=*
//SYSTERM DD SYSOUT=*
//SYSIN DD *
$$FILEM DSC DSNIN=REDBK2.TEST.SEQFILE,
$$FILEM POSITION=0,
$$FILEM DISP=MOD,
$$FILEM DSNOUT=REDBK2.TEST.SEQFILEX,
$$FILEM PROC=*
IF CO(FLD(3,1),C,G,L,M,S) THEN
RETURN
ELSE
RETURN 'DROP'
/+
Successful completion of the job is shown in Example 2-16, with identical results. Note that
for a job such as this, particularly when working with a large file, DFSORT performance will be
significantly better than that of REXX.
Example 2-16 Successful completion
IBM File Manager for z/OS
$$FILEM DSC DSNIN=REDBK2.TEST.SEQFILE,
$$FILEM POSITION=0,
$$FILEM DISP=MOD,
$$FILEM DSNOUT=REDBK2.TEST.SEQFILEX,
Get Using IBM Application Development Tools for z/OS and OS/390 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.