Page 1 of 1

Comparing Two Records in the same file & Replacing Value

Posted: Thu Jul 28, 2011 9:34 am
by raulravi
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

Posted: Fri Jul 29, 2011 2:05 am
by Frank Yaeger
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))
/*