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

Write records with 3 or less rows in a group


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

New User


Joined: 16 May 2005
Posts: 16
Location: Bangalore

PostPosted: Thu Jun 03, 2021 7:37 pm
Reply with quote

I have the records in my file with below data. There are many G2 records inside G1 group records.
Code:

G1
G2 Field1 Field2
G2 Field1 Field2
G1
G2 Field1 Field2
G2 Field1 Field2
G2 Field1 Field2
G2 Field1 Field2
G2 Field1 Field2
G1
G2 Field1 Field2
G2 Field1 Field2
G2 Field1 Field2
G1
G2 Field1 Field2
G2 Field1 Field2
G2 Field1 Field2
G2 Field1 Field2
G2 Field1 Field2


I want to extract the 3 or less G2 records inside the G1 records.
For the above set, it needs to extract only 1st and 3rd set of G2 records.

Output should be as below.
Code:
G1
G2 Field1 Field2
G2 Field1 Field2
G1
G2 Field1 Field2
G2 Field1 Field2
G2 Field1 Field2

Code'd for you
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1255
Location: Bamberg, Germany

PostPosted: Fri Jun 04, 2021 9:32 am
Reply with quote

Use code tags when presenting code/data!

What have you tried so far? There are more than a couple of samples how to do your requirement using JOINKEYS.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Jun 09, 2021 12:55 am
Reply with quote

prasannahcp, Please use code tags since you are here for a long time to know how to use it.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1255
Location: Bamberg, Germany

PostPosted: Wed Jun 09, 2021 1:17 am
Reply with quote

Code:
//WHATEVER EXEC PGM=ICEMAN   
//F1       DD *             
G1                           
G2 Field1 Field2             
G2 Field1 Field2             
G1                           
G2 Field1 Field2             
G2 Field1 Field2             
G2 Field1 Field2             
G2 Field1 Field2             
G2 Field1 Field2             
G1                           
G2 Field1 Field2             
G2 Field1 Field2             
G2 Field1 Field2             
G1                           
G2 Field1 Field2             
G2 Field1 Field2             
G2 Field1 Field2             
G2 Field1 Field2             
G2 Field1 Field2             
/*                           
//F2       DD *             
G1                                   
G2 Field1 Field2                     
G2 Field1 Field2                     
G1                                   
G2 Field1 Field2                     
G2 Field1 Field2                     
G2 Field1 Field2                     
G2 Field1 Field2                     
G2 Field1 Field2                     
G1                                   
G2 Field1 Field2                     
G2 Field1 Field2                     
G2 Field1 Field2                     
G1                                   
G2 Field1 Field2                     
G2 Field1 Field2                     
G2 Field1 Field2                     
G2 Field1 Field2                     
G2 Field1 Field2                     
/*                                   
//SYSOUT   DD SYSOUT=*               
//SORTOUT  DD SYSOUT=*               
//SYSIN    DD *                       
  OPTION COPY                         
  JOINKEYS F1=F1,FIELDS=(20,8,A)     
  JOINKEYS F2=F2,FIELDS=(20,8,A)     
  REFORMAT FIELDS=(F1:1,19,F2:28,4)   
  OUTFIL FNAMES=(SORTOUT),           
    INCLUDE=(20,4,ZD,LE,+3),         
    REMOVECC,                         
    BUILD=(1,19)                     
  END                                 
/*                                   
//JNF1CNTL DD *                                                   
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'G1'),PUSH=(20:ID=8))
  END                                                             
/*                                                                 
//JNF2CNTL DD *                                                   
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(28:+0,ZD,LENGTH=4)),           
    IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'G1'),PUSH=(20:ID=8)),   
      IFTHEN=(WHEN=(1,2,CH,EQ,C'G2'),OVERLAY=(28:+1,ZD,LENGTH=4)) 
  SUM FIELDS=(28,4,ZD)                                             
  END                                                             
/*

Output:
Code:
****** ****************************
000001 G1                         
000002 G2 Field1 Field2           
000003 G2 Field1 Field2           
000004 G1                         
000005 G2 Field1 Field2           
000006 G2 Field1 Field2           
000007 G2 Field1 Field2           
****** ****************************
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top