by sarala » Fri Oct 21, 2011 10:44 am
Hello MRSPOCK,
Substring may not be false proof, because that value may appear anywhere in the record but I want only one particular field
with this value to be selected. But that was a good option. Thanks. I tried that and it worked.
Hello BillyBoyo,
Yours was the idea that I followed. Thanks. But I did not know how to stick the required column to the beginning of each record.
After some research in the forums, the SEQNUM came handy and I got the solution. Thanks again.
Logic followed was:
1. The field on which the filter has to be applied is brought as the first field in the file (with Parse and build options)
2. Sequence number is applied to both input file and the file created in step1(Using the SEQNUM option)
3. Merge the file created in step1 with the input file on the sequence number and bring the first field in the file1 as the first field in file2. (Merge option and Reformat fields)
4. Apply include condition on the first field and using outrec remove the appended first field to get the original file format back.
Here is the working code:
I/p file details (FB with LRECL 408 and pipe delimited file): Same input as said before
//JOBCARD
//*********************************************************************
//* *
//* STEP1: MAKE THE FIELD(S) ON WHICH THE FILTER HAS TO BE APPLIED AS *
//* THE FIRST FIELD(S) - REPEAT THE FIELDS *
//* LRECLS SHOULD BE ORIGINAL LRECL + REPEAT FIELD LENGTH + SEQNUM LEN*
//* *
//*********************************************************************
//PS0100 EXEC PGM=SORT
//SYSUDUMP DD SYSOUT=I
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=INPUT.FILE,DISP=SHR
//SORTOUT DD DSN=INPUT.FILE.SORT1,DISP=(,CATLG,DELETE),
// UNIT=SYSALLDA,SPACE=(CYL,(5,5),RLSE),
// LRECL=421,RECFM=FB
//SYSIN DD *
SORT FIELDS=COPY
INREC PARSE=(%01=(ENDBEFR=C'|',FIXLEN=008),
%02=(ENDBEFR=C'|',FIXLEN=005),
%03=(ENDBEFR=C'|',FIXLEN=015),
%04=(ENDBEFR=C'|',FIXLEN=003),
%05=(ENDBEFR=C'|',FIXLEN=004),
%06=(ENDBEFR=C'|',FIXLEN=005),
%07=(ENDBEFR=C'|',FIXLEN=007)),
BUILD=(01:%06)
OUTREC FIELDS=(1:1,5,403:X)
/*
// IF (PS0100.RC GT 0) THEN
//PS0101 EXEC PGM=ABENDPGM
// ENDIF
//*********************************************************************
//* *
//* STEP2: ADDS SEQUENCE NUMBER TO THE SOURCE FILE *
//* ADD ORIGINAL LRECL + 6 (FOR SEQNUM) *
//* *
//*********************************************************************
//PS0200 EXEC PGM=SORT
//SYSUDUMP DD SYSOUT=I
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=INPUT.FILE,DISP=SHR
//SORTOUT DD DSN=INPUT.FILE.SEQ1,DISP=(,CATLG,DELETE),
// UNIT=SYSALLDA,SPACE=(CYL,(5,5),RLSE),
// LRECL=421,RECFM=FB
//SYSIN DD *
OPTION COPY
OUTREC FIELDS=(1:SEQNUM,6,ZD,7:1,408)
/*
// IF (PS0200.RC GT 0) THEN
//PS0201 EXEC PGM=ABENDPGM
// ENDIF
//*********************************************************************
//* *
//* STEP3: ADDS SEQUENCE NUMBER TO THE REPEATED SORT FILE *
//* ADD ORIGINAL LRECL + 6 (FOR SEQNUM) *
//* *
//*********************************************************************
//PS0300 EXEC PGM=SORT
//SYSUDUMP DD SYSOUT=I
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=INPUT.FILE.SORT1,DISP=SHR
//SORTOUT DD DSN=INPUT.FILE.SEQ2,DISP=(,CATLG,DELETE),
// UNIT=SYSALLDA,SPACE=(CYL,(5,5),RLSE),
// LRECL=421,RECFM=FB
//SYSIN DD *
OPTION COPY
OUTREC FIELDS=(1:SEQNUM,6,ZD,7:1,408)
/*
// IF (PS0300.RC GT 0) THEN
//PS0301 EXEC PGM=ABENDPGM
// ENDIF
//*********************************************************************
//* *
//* STEP4: MERGE FILE2 WITH FILE1 ON THE SEQNUM. *
//* LRECL WILL INCLUDE THE FIRST FIELD + SEQNUM *
//* *
//*********************************************************************
//PS0400 EXEC PGM=SORT
//SORTJNF1 DD DSN=INPUT.FILE.SEQ2,DISP=SHR
//SORTJNF2 DD DSN=INPUT.FILE.SEQ1,DISP=SHR
//SORTOUT DD DSN=INPUT.FILE.MERGE,DISP=(NEW,CATLG,DELETE),
// UNIT=SYSALLDA,SPACE=(CYL,(5,5),RLSE),
// LRECL=428,RECFM=FB
//SYSOUT DD SYSOUT=*
//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(1,6,A)
JOINKEYS FILES=F2,FIELDS=(1,6,A)
REFORMAT FIELDS=(F1:7,5,F2:7,415)
SORT FIELDS=COPY
/*
// IF (PS0400.RC GT 0) THEN
//PS0401 EXEC PGM=ABENDPGM
// ENDIF
//*********************************************************************
//* *
//* STEP5: INCLUDE COND STATEMENT TO FILTER THE REQUIRED VALUES *
//* *
//*********************************************************************
//PS0500 EXEC PGM=SORT
//SYSUDUMP DD SYSOUT=I
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=INPUT.FILE.MERGE,DISP=SHR
//SORTOUT DD DSN=INPUT.FILE.SAMPLE,DISP=(,CATLG,DELETE),
// UNIT=SYSALLDA,SPACE=(CYL,(5,5),RLSE),
// LRECL=408,RECFM=FB
//SYSIN DD *
SORT FIELDS=COPY
INCLUDE COND=(1,5,CH,EQ,C'10002')
OUTREC FIELDS=(1:6,407)
/*
// IF (PS0500.RC GT 0) THEN
//PS0501 EXEC PGM=ABENDPGM
// ENDIF