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
 

 

copy matching key3 to next record based on key1 and key2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 03, 2010 10:42 pm    Post subject: copy matching key3 to next record based on key1 and key2
Reply with quote

Sorry about subject.. I was very confused about what to give... icon_sad.gif


Input file
key1:1,8
key2:9,4
key3:26,8
Code:
 
01000101CUS100000007.35GB20100201 
01000101RUS100000007.35GB20100201 
01000108BER100000007.35GB20100201 
01000108BER100000007.40GB20100301 
01000108BER100000007.45GB20100401 
01000108BER100000007.50GB20100501 

If there are multiple rows for key1\key2 combination then it should be sorted by key3(ascending or descending, order doesn't matter)

if key3 is in ascending order, every key3 of nth row of key1\key2 combination should be copied to (n-1) row. Last row should be hard-coded to 99991231.
Expected output will be...
Code:
 
01000101CUS100000007.35GB2010020199991231 
01000101RUS100000007.35GB2010020199991231 
01000108BER100000007.35GB2010020120100301 
01000108BER100000007.40GB2010030120100401 
01000108BER100000007.45GB2010040120100501 
01000108BER100000007.50GB2010050199991231 


or.....
Code:
 
01000101CUS100000007.35GB2010020199991231 
01000101RUS100000007.35GB2010020199991231 
01000108BER100000007.50GB2010050199991231 
01000108BER100000007.45GB2010040120100501 
01000108BER100000007.40GB2010030120100401 
01000108BER100000007.35GB2010020120100301 


I am using DFSORT\ICETOOL.
Back to top
View user's profile Send private message

Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 03, 2010 11:07 pm    Post subject:
Reply with quote

We can assume maximum of 4 combination of key1\key2\key3 will be present....
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 May 04, 2010 1:45 am    Post subject:
Reply with quote

Some questions:

What is the RECFM and LRECL of the input file?

Are the input records already in order by key1 and key2 as shown in your example?

Quote:
if key3 is in ascending order, every key3 of nth row of key1\key2 combination should be copied to (n-1) row. Last row should be hard-coded to 99991231.


What are the rules if key3 is in descending order?
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue May 04, 2010 8:31 am    Post subject:
Reply with quote

Frank wrote:
What is the RECFM and LRECL of the input file?

Input RECFM=FB LRECL=33
Output RECFM=FB LRECL=41
Frank wrote:
Are the input records already in order by key1 and key2 as shown in your example?

Yes. In ascending order of key1\key2.

Frank wrote:
What are the rules if key3 is in descending order?


if key3 is in descending order, every key3 of nth row of key1\key2 combination should be copied to (n+1) row. First row of key1\key2 combination should be hard-coded to 99991231. n starts from 1.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed May 05, 2010 1:15 am    Post subject: Reply to: copy matching key3 to next record based on key1 an
Reply with quote

escapa,

The following DFSORT/ICETOOL JCL will give you the desired results. I have taken the ascending order for the key3

Code:

//STEP0100 EXEC PGM=ICETOOL                                           
//TOOLMSG  DD SYSOUT=*                                               
//DFSMSG   DD SYSOUT=*                                               
//IN       DD DSN=Your input FB 33 byte file,DISP=SHR                                       
//T1       DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)           
//OUT      DD SYSOUT=*                                               
//TOOLIN   DD *                                                       
  SORT FROM(IN) USING(CTL1)                                           
  COPY FROM(T1) USING(CTL2)                                           
//*                                                                   
//CTL1CNTL DD *                                                       
  SORT FIELDS=(1,12,CH,A,26,8,CH,A),EQUALS                           
  OUTREC IFTHEN=(WHEN=INIT,BUILD=(157:C'99991231',                   
                 1,33,X,SEQNUM,1,ZD,RESTART=(1,12))),                 
  IFTHEN=(WHEN=GROUP,BEGIN=(199,1,ZD,EQ,1),PUSH=(001:165,33)),       
  IFTHEN=(WHEN=GROUP,BEGIN=(199,1,ZD,EQ,2),PUSH=(042:165,33)),       
  IFTHEN=(WHEN=GROUP,BEGIN=(199,1,ZD,EQ,3),PUSH=(083:165,33)),       
  IFTHEN=(WHEN=(199,1,ZD,EQ,4),OVERLAY=(124:165,33),HIT=NEXT),       
  IFTHEN=(WHEN=(042,12,CH,NE,165,12,CH),OVERLAY=(042:115X),HIT=NEXT),
  IFTHEN=(WHEN=(083,12,CH,NE,165,12,CH),OVERLAY=(083:066X),HIT=NEXT),
  IFTHEN=(WHEN=(124,12,CH,NE,165,12,CH),OVERLAY=(124:33X),HIT=NEXT), 
  IFTHEN=(WHEN=(067,8,CH,GT,C' '),OVERLAY=(34:67,8),HIT=NEXT),       
  IFTHEN=(WHEN=(108,8,CH,GT,C' '),OVERLAY=(75:108,8),HIT=NEXT),       
  IFTHEN=(WHEN=(149,8,CH,GT,C' '),OVERLAY=(116:149,8))               
                                                                     
  OUTFIL FNAMES=T1,REMOVECC,NODETAIL,BUILD=(165X),                   
  SECTIONS=(165,12,TRAILER3=(1,164,199,1))                           
//*                                                                   
//CTL2CNTL DD *                                                       
  OUTFIL FNAMES=OUT,IFOUTLEN=41,                                     
  IFTHEN=(WHEN=(165,1,ZD,EQ,1),BUILD=(1,33,157,8)),                   
  IFTHEN=(WHEN=(165,1,ZD,EQ,2),BUILD=(1,41,/,42,33,157,8)),           
  IFTHEN=(WHEN=(165,1,ZD,EQ,3),BUILD=(1,41,/,42,41,/,83,33,157,8)),   
  IFTHEN=(WHEN=(165,1,ZD,EQ,4),BUILD=(1,41,/,42,41,/,83,41,124,41))   
//*
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri May 14, 2010 9:24 am    Post subject:
Reply with quote

Thanks Kolusu.
I couldn't use this solution as confirmation about max of 4 dups was little shaky.

I have used selcopy solution, thought of sharing...
Code:

//S1    EXEC  PGM=SELCOPY                               
//SYSOUT    DD  SYSOUT=*                                   
//SYSPRINT DD  SYSOUT=*                                     
//SYSUDUMP DD  SYSOUT=*                                     
//IN DD *                                                   
01000101CUS100000007.35GB20100201                           
01000101RUS100000007.35GB20100201                           
01000108BER100000007.35GB20100501                           
01000108BER100000007.40GB20100401                           
01000108BER100000007.45GB20100301                           
01000108BER100000007.50GB20100201                           
/*                                                         
//OUT1 DD SYSOUT=*                                         
//SYSIN    DD    *                                         
 RD IN  WORKLEN 160             
 IF POS 1 NE POS 81 LEN 12       
   THEN POS 114 = '99991231'     
   THEN MOVE 33 FR 1 TO 81       
   THEN WRITE OUT1 FR 81 L 41   
 ELSE MOVE 8 FROM 106 TO 114     
   THEN MOVE 33 FR 1 TO 81       
   THEN WRITE OUT1 FR 81 L 41   
/*                               
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 Record Not found in AlX but record re... mukun264 COBOL Programming 7 Fri Mar 24, 2017 9:28 am
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am


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