Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Selecting record based on the previous record value

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Selecting record based on the previous record value
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    Post subject: Reply to: Selecting record based on the previous record valu
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    Post subject: Reply to: Selecting record based on the previous record valu
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: 1288
Location: Chennai, India

PostPosted: Tue Aug 12, 2008 3:10 pm    Post subject: Reply to: Selecting record based on the previous record valu
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    Post subject: Reply to: Selecting record based on the previous record valu
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    Post subject: Reply to: Selecting record based on the previous record valu
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: 1288
Location: Chennai, India

PostPosted: Tue Aug 12, 2008 3:45 pm    Post subject: Reply to: Selecting record based on the previous record valu
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    Post subject: Reply to: Selecting record based on the previous record valu
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: 1288
Location: Chennai, India

PostPosted: Tue Aug 12, 2008 4:03 pm    Post subject: Reply to: Selecting record based on the previous record valu
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    Post subject: Reply to: Selecting record based on the previous record valu
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 Moderator


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

PostPosted: Tue Aug 12, 2008 9:49 pm    Post subject:
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:

www.ibm.com/systems/support/storage/software/sort/mvs/ugpf/
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Split file based on comparsion to 2 f... Div Grad DFSORT/ICETOOL 3 Thu Jul 27, 2017 9:16 pm
No new posts Read two inputs and write into output... murali.andaluri DFSORT/ICETOOL 6 Wed Jul 26, 2017 7:35 pm
No new posts Need to write record of PS File in ex... Chandan1993 JCL & VSAM 1 Wed Jun 07, 2017 1:35 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us