IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Selecting record based on the previous record value


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
senjay

Active User


Joined: 10 May 2007
Posts: 147
Location: India

PostPosted: Tue Aug 12, 2008 11:26 am
Reply with quote

Hi,

Could you please clarify how can the below requirement be solved in DFSORT?

Input:
A1
B2
C3
A4
C5
C6
B7
C8
C9
.
.
.
.

Output:

C3
C8

Only the record C (and only one) which is after B record should be selected.
I know this can be easily done through PL/1 or COBOL programs. But still curious to know how to handle in DFSORT?
Back to top
View user's profile Send private message
karthikr44

Active User


Joined: 25 Aug 2007
Posts: 235
Location: Chennai

PostPosted: Tue Aug 12, 2008 11:57 am
Reply with quote

Hi senjay,

The follwoing JCL will give u the solution.

Code:

//S1 EXEC PGM=ICETOOL                                           
//TOOLMSG  DD SYSOUT=*                                           
//DFSMSG   DD SYSOUT=*                                           
//IN1 DD DSN=DEV2.RK.TEST.REC80,DISP=SHR                         
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5,)),DISP=(MOD,PASS)   
//OUT  DD DSN=DEV2.RK.TEST.REC80.OUT,DISP=SHR                   
//TOOLIN   DD *                                                 
 COPY FROM(IN1) TO(T1) USING(CTL1)                               
 SELECT FROM(T1) TO(OUT) ON(81,8,CH) LASTDUP USING(CTL2)         
/*                                                               
//CTL1CNTL DD *                                                 
  INCLUDE COND=(1,1,SS,EQ,C'B,C')                               
  OUTREC OVERLAY=(81:SEQNUM,8,ZD)                               
/*                                                               
//CTL2CNTL DD *                                                 
  INREC IFTHEN=(WHEN=INIT,                                       
         OVERLAY=(81:SEQNUM,8,ZD)),                             
          IFTHEN=(WHEN=(1,1,CH,EQ,C'B'),                         
         OVERLAY=(81:+1,ADD,81,8,ZD,M11,LENGTH=8))               
                                                                 
    OUTFIL FNAMES=OUT,BUILD=(01,80)                             
/*                                                               



Sample input:

Code:

A1             
B2             
C3             
A4             
C5             
C6             
B7             
C8             
C9             


Output i got:

Code:

C3
C8



Regards
R KARTHIK
Back to top
View user's profile Send private message
senjay

Active User


Joined: 10 May 2007
Posts: 147
Location: India

PostPosted: Tue Aug 12, 2008 3:03 pm
Reply with quote

Hi karthik,

Thanks for your reply. But I afraid your solution won't work. Please go through the below case.

Input:
A1
B2
C3
A4
C5
C6
B7
C8
C9
B3
B4
A3
C0
.
.
.

Required output:
C3
C8

But your code will give the output as below
C3
C8
C0

C0 should not come as the previous record of C0 is not starting with B.
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Tue Aug 12, 2008 3:10 pm
Reply with quote

Senjay,

Quote:
C0 should not come as the previous record of C0 is not starting with B.


This is happening as Karthik had included only records with either 'B' or 'C' as per the first control card. hence A3 would be removed and it would be like

B4
C0 ( no A3 as it is removed)
Back to top
View user's profile Send private message
karthikr44

Active User


Joined: 25 Aug 2007
Posts: 235
Location: Chennai

PostPosted: Tue Aug 12, 2008 3:19 pm
Reply with quote

Hi senthil,

Then u can use following JCL for the desired results.

Code:

//S1 EXEC PGM=SYNCTOOL                                               
//TOOLMSG  DD SYSOUT=*                                               
//DFSMSG   DD SYSOUT=*                                               
//IN1 DD DSN=DEV2.RK.TEST.REC80,DISP=SHR                             
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5,)),DISP=(MOD,PASS)       
//OUT  DD DSN=DEV2.RK.TEST.REC80.OUT,DISP=SHR                       
//TOOLIN   DD *                                                     
 COPY FROM(IN1) TO(T1) USING(CTL1)                                   
 SELECT FROM(T1) TO(OUT) ON(81,8,CH) LASTDUP USING(CTL2)             
/*                                                                   
//CTL1CNTL DD *                                                     
  INREC OVERLAY=(81:SEQNUM,8,ZD)                                     
/*                                                                   
//CTL2CNTL DD *                                                     
  INREC IFTHEN=(WHEN=INIT,                                           
         OVERLAY=(81:SEQNUM,8,ZD)),                                 
          IFTHEN=(WHEN=(1,1,CH,EQ,C'B'),                             
         OVERLAY=(81:+1,ADD,81,8,ZD,M11,LENGTH=8))                   
                                                                     
    OUTFIL FNAMES=OUT,INCLUDE=(1,1,CH,EQ,C'C'),BUILD=(01,80)         
/*                                                                   
//*                                                                 



Regards
R KARTHIK
Back to top
View user's profile Send private message
senjay

Active User


Joined: 10 May 2007
Posts: 147
Location: India

PostPosted: Tue Aug 12, 2008 3:33 pm
Reply with quote

Aaru wrote:
Quote:
This is happening as Karthik had included only records with either 'B' or 'C' as per the first control card


Yup. I agree.

Hi Karthik,

Thanks. Let me go through the solution and get back to you.
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Tue Aug 12, 2008 3:45 pm
Reply with quote

Karthik,

Quote:
Then u can use following JCL for the desired results.


Perfect and a quick turn around time. Hope it works for all scenarios.

Also i think there is no need of the first control card (CTL1CNTL) as your overlaying the sequence no again in the second control card for all input records.(WHEN=INIT).

I have modified your JCl a bit. Check if this would work.

Code:
//TOOLIN   DD *                                             
  SELECT FROM(IN1) TO(OUT) ON(81,8,CH) LASTDUP USING(CTL1) 
/*                                                         
//CTL1CNTL DD *                                             
  INREC IFTHEN=(WHEN=INIT,                                 
  OVERLAY=(81:SEQNUM,8,ZD)),                               
  IFTHEN=(WHEN=(1,1,CH,EQ,C'B'),                           
  OVERLAY=(81:+1,ADD,81,8,ZD,M11,LENGTH=8))                 
  OUTFIL FNAMES=OUT,INCLUDE=(1,1,CH,EQ,C'C'),BUILD=(01,80) 
/*                                                         
Back to top
View user's profile Send private message
senjay

Active User


Joined: 10 May 2007
Posts: 147
Location: India

PostPosted: Tue Aug 12, 2008 3:47 pm
Reply with quote

Aaru,

Great. i just modified it and thought of posting. But you did it ahead of me.

Karthik,
Thanks for your solution and time.
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Tue Aug 12, 2008 4:03 pm
Reply with quote

senjay,

Quote:
Great. I just modified it and thought of posting. But you did it ahead of me.


Thanks. Fastest finger first icon_smile.gif .
Back to top
View user's profile Send private message
karthikr44

Active User


Joined: 25 Aug 2007
Posts: 235
Location: Chennai

PostPosted: Tue Aug 12, 2008 4:11 pm
Reply with quote

Hi,

Thanks for sharing optimised coding style.

Regards
R KARHTIK
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Aug 12, 2008 9:49 pm
Reply with quote

With z/OS DFSORT V1R5 PTF UK90013 (July, 2008), you can do this much more easily and efficiently with the new WHEN=GROUP function like this:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file (FB/80)
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN    DD    *
  OPTION COPY
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'B'),
    PUSH=(81:SEQ=8))
  OUTFIL INCLUDE=(1,1,CH,EQ,C'C',AND,81,8,ZD,EQ,2),
    BUILD=(1,80)
/*


For complete details on the new WHEN=GROUP function and the other new functions available with PTF UK90013, see:

Use [URL] BBCode for External Links
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
Search our Forums:

Back to Top