Comparing Two Records in the same file & Replacing Value

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
raulravi
Member
Posts: 47
Joined: Mon Apr 18, 2011 9:51 am
Location: India

Comparing Two Records in the same file & Replacing Value

Post by raulravi » Thu Jul 28, 2011 9:34 am

Frank,

I have a input file as below.

Code: Select all

Code:
Input file: 
Date     feild2&3custid   FLD-1   FLD-2   FLD-3    
20110101         111111   london   Real   Fraud    
20101201         111111   Madrid   Real   Fraud    
20101101         111111   london   Real   Fraud    
20101001         111111   london   Ceal   Fraud
20100901         111111   london   Ceal   Secur
20110101         222222   Madrid   Real   Fraud    
20101201         222222   london   Real   Fraud    
20101101         222222   Madrid   Real   Fraud    
20101001         222222   Madrid   FCB    Fraud
20100901         222222   Madrid   FCB    M&F
20101101         333333   Madrid   Real   Fraud    
20101001         333333   Madrid   Ceal   Fraud    
20100901         333333   Madrid   Beal   Fraud    
20100901         444444   Madrid   Real   Fraud    
The output file should be as below:

Code: Select all

Code:
Output file: 
Date     feild2&3custid   FLD-1   FLD-2   FLD-3   Comment 
20110101         111111   london   Real   Fraud   First Record 
20101201         111111   london   Real   Fraud   First Record with date from second record. 
20101101         111111   Madrid   Real   Fraud    Second Record with date from 3rd record.
20101001         111111   london   Real   Fraud    Third Record with date from 4th record.
20100901         111111   london   Ceal   Fraud    Fourth Record with date from 5th record.
20110101         222222   Madrid   Real   Fraud    Six'th Record. (First Record for second customer.)
20101201         222222   Madrid   Real   Fraud    Six'th Record with date from 7th record.
20101101         222222   london   Real   Fraud    Seventh Record with date from 8th record.
20101001         222222   Madrid   Real   Fraud    Eight Record with date from 9th record.
20100901         222222   Madrid   FCB    Fraud    Nineth Record with date from 10th record.
20101101         333333   Madrid   Real   Fraud    Ten'th Record. (First Record for Third customer.)
20101001         333333   Madrid   Real   Fraud    Ten'th Record with date from 11th record.
20100901         333333   Madrid   Ceal   Fraud    Eleventh Record with date from 12th record.
20100901         444444   Madrid   Real   Fraud    Twelve'th Record. (First Record for Fourth customer.)
Rules:
1) Write the first record of every customer Twice. a) First write as it is. b) Second time write the whole record as it is, with date from the below record if the customer is same for both the records.

2) And delete the last record of every customer.

3) But if there is only one record for a customer then write it down to the
output.

Please let me know if i am not clear.

Raul

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Fri Jul 29, 2011 2:05 am

Here's a DFSORT job that will do what you asked for. Notice that the input file is used twice (for IN1 and IN2). I assumed the input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

Code: Select all

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//IN1 DD DSN=...  input file (FB/80)
//IN2 DD DSN=...  input file (FB/80)
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN DD *
  JOINKEYS F1=IN1,FIELDS=(18,6,A,81,8,A),SORTED
  JOINKEYS F2=IN2,FIELDS=(18,6,A,81,8,A),SORTED
  REFORMAT FIELDS=(F1:1,80,F2:1,8)
  OPTION COPY
  OUTREC BUILD=(81,8,9,72)
/*
//JNF1CNTL DD *
  INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(18,6),PUSH=(81:SEQ=8))
/*
//JNF2CNTL DD *
  INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(18,6),PUSH=(81:SEQ=8)),
        IFTHEN=(WHEN=(81,8,ZD,GT,1),
      OVERLAY=(81:81,8,ZD,SUB,+1,TO=ZD,LENGTH=8))
/*
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others