OUTREC: Reformatting records with FINDREP
OUTREC: Reformatting records with FINDREP
Summary
- The reformat output records by specifying items that start at a specific position can be done with the BUILD, FIELDS or OVERLAY parameter of the OUTREC statement.
- But if to replace or remove data anywhere in records, the FINDREP parameter of the OUTREC statement needs to use instead.
- FINDREP indicates that doing a find and replace operation.
- IN identifies the constant (the "find" constant) and OUT identifies the constant (the "replace" constant).
Syntax -
OPTION COPY
OUTREC FINDREP=(IN=String/charset,OUT=String/charset)
IN=String/charset | Specifies string/charset that needs to find in the file. |
OUT=String/charset | Specifies new string/charset that used to replace in the file. |
Example -
Scenario - Reformatting dept with DEPT using FINDREP.
Input File - MTHUSER.SORT.INPUT01 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00001 student1 dept1 560
00003 student3 dept2 520
00004 student4 dept1 540
00005 student5 dept2 500
00002 student2 dept3 510
******************************** Bottom of Data ********************************
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card
//*
//**********************************************************************
//*
//* SORT FOR OUTREC STATEMENT
//*
//**********************************************************************
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTREC FINDREP=(IN=C'dept',OUT=C'DEPT')
/*
**************************** Bottom of Data ****************************
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
00001 student1 DEPT1 560
00003 student3 DEPT2 520
00004 student4 DEPT1 540
00005 student5 DEPT2 500
00002 student2 DEPT3 510
******************************** BOTTOM OF DATA ********************************
Explaining Example -
OUTREC FINDREP=(IN=C'dept',OUT=C'DEPT') - finds the text "dept" in the entire input file with the "DEPT" and writes to the output.