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

Filter records where condition is in middle of the records


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kris_madras

New User


Joined: 04 Jul 2005
Posts: 50

PostPosted: Thu Sep 11, 2025 10:26 pm
Reply with quote

I have input file with several report details.
Now I want to pull reports from this input file to another output file where REPORTID is 0010. I also need Header-1 thru Header-4 which appears before REPORTID: 0010.
Please suggest me the SYNCSORT features I can use.

Input file: FBA 133
Code:
1Header-1
0Header-2
0Header-3
0Header-4
xxxxxxxxx: REPORTID: 1234
Detail record-1
Detail record -2
Detail record-3
1Header-1a
0Header-2a
0Header-3a
0Header-4a
xxxxxxxxx: REPORTID: 0010
Detail record-1
Detail record -2
Detail record-3

1Header-1
0Header-2
0Header-3
0Header-4
xxxxxxxxx: REPORTID: XYZD
Detail record-1
Detail record -2
Detail record-3

1Header-8a
0Header-9a
0Header-10a
0Header-11a
xxxxxxxxx: REPORTID: 0010
Detail record-8
Detail record -9
Detail record-10


 



Output file expected:
Code:
1Header-1a
0Header-2a
0Header-3a
0Header-4a
xxxxxxxxx: REPORTID: 0010
Detail record-1
Detail record -2
Detail record-3

1Header-8a
0Header-9a
0Header-10a
0Header-11a
xxxxxxxxx: REPORTID: 0010
Detail record-8
Detail record -9
Detail record-10
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Fri Sep 12, 2025 7:49 am
Reply with quote

What have you tried to get the desired result yet?
Back to top
View user's profile Send private message
kris_madras

New User


Joined: 04 Jul 2005
Posts: 50

PostPosted: Fri Sep 12, 2025 9:36 am
Reply with quote

Initial plan is to write COBOL program, checking if this can be done in SORT.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Fri Sep 12, 2025 10:11 am
Reply with quote

Let F1 and F2 point to your input Dataset.

Code:
//WHATEVER EXEC PGM=SORT                         
//F1       DD ..                                 
//F2       DD ..                                 
//SYSOUT   DD SYSOUT=*                           
//SORTOUT  DD SYSOUT=*                           
//SYSIN    DD *                                   
  OPTION COPY
  JOINKEYS F1=F1,FIELDS=(134,8,A),SORTED,NOSEQCK 
  JOINKEYS F2=F2,FIELDS=(134,8,A)                 
  REFORMAT FIELDS=(F1:1,133,F2:142,2)             
  OUTFIL FNAMES=(SORTOUT),                       
    INCLUDE=(134,2,CH,EQ,C'XX'),                 
    BUILD=(1,133)                                 
  END                                             
/*                                               
//JNF1CNTL DD *                                   
  INREC IFTHEN=(WHEN=GROUP,                       
    BEGIN=(1,1,CH,EQ,C'1'),PUSH=(134:ID=8))       
  END                                             
/*                                               
//JNF2CNTL DD *                                   
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(142:2Z)),     
    IFTHEN=(WHEN=GROUP,                           
      BEGIN=(1,1,CH,EQ,C'1'),PUSH=(134:ID=8)),   
    IFTHEN=(WHEN=(1,133,SS,EQ,C'REPORTID: 0010'),
      OVERLAY=(142:2C'X'))                       
  SUM FIELDS=(142,2,BI)                           
  END                                             
/*
Back to top
View user's profile Send private message
kris_madras

New User


Joined: 04 Jul 2005
Posts: 50

PostPosted: Fri Sep 12, 2025 10:31 am
Reply with quote

Great! Thank you. Trying the above solution.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2288
Location: USA

PostPosted: Fri Sep 12, 2025 11:38 pm
Reply with quote

Joerg.Findeisen wrote:
Let F1 and F2 point to your input Dataset.

Code:
//WHATEVER EXEC PGM=SORT                         
//F1       DD ..                                 
//F2       DD ..                                 
//SYSOUT   DD SYSOUT=*                           
//SORTOUT  DD SYSOUT=*                           
//SYSIN    DD *                                   
  OPTION COPY
  JOINKEYS F1=F1,FIELDS=(134,8,A),SORTED,NOSEQCK 
  JOINKEYS F2=F2,FIELDS=(134,8,A)                 
  REFORMAT FIELDS=(F1:1,133,F2:142,2)             
  OUTFIL FNAMES=(SORTOUT),                       
    INCLUDE=(134,2,CH,EQ,C'XX'),                 
    BUILD=(1,133)                                 
  END                                             
/*                                               
//JNF1CNTL DD *                                   
  INREC IFTHEN=(WHEN=GROUP,                       
    BEGIN=(1,1,CH,EQ,C'1'),PUSH=(134:ID=8))       
  END                                             
/*                                               
//JNF2CNTL DD *                                   
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(142:2Z)),     
    IFTHEN=(WHEN=GROUP,                           
      BEGIN=(1,1,CH,EQ,C'1'),PUSH=(134:ID=8)),   
    IFTHEN=(WHEN=(1,133,SS,EQ,C'REPORTID: 0010'),
      OVERLAY=(142:2C'X'))                       
  SUM FIELDS=(142,2,BI)                           
  END                                             
/*

Not good idea to calculate the SUM of C'XX'. Besides misleading logic, it also may cause fixed overflow for huge enough input files.

My recommendation is like this. (I hope it can be used not only to copy-and-paste, but also for understanding of the processing algorithm?)
Code:
//GENFILE  EXEC PGM=SYNCTOOL         
//TOOLMSG  DD  SYSOUT=*               
//SSMSG    DD  SYSOUT=*               
//*                                   
//SORTIN   DD  *
 . . . . . . . . . . . . . . . . . .                       
//*-+----1----+                                                       
//DETAIL@  DD  SYSOUT=*            intermediate debugging listing     
//DETAIL   DD  SPACE=(TRK,(10,100),RLSE)    data selector             
//MASTER   DD  SPACE=(TRK,(10,100),RLSE)    numbered input             
//*                                                                   
//TOOLIN   DD  *                                                       
 COPY FROM(SORTIN)     TO(DETAIL)       USING(GRPS)                   
 COPY JKFROM           TO(SORTOUT)      USING(JOIN)                   
//*                                                                   
//GRPSCNTL DD  *                                                       
 INREC IFTHEN=(WHEN=GROUP,                                             
               BEGIN=(1,1,CH,EQ,C'1'),                                 
               PUSH=(134:ID=8))                                       
                                                                         
 OUTFIL FNAMES=(DETAIL,DETAIL@),                                         
        INCLUDE=(1,30,SS,EQ,C' REPORTID: ',                               
             AND,1,30,SS,EQ,C' 0010 '),                                   
        BUILD=(134,8)            the only required info                   
                                                                         
 OUTFIL FNAMES=(MASTER)          full numbered input file                 
                                                                         
//*                                                                       
//JOINCNTL DD  *                                                         
 JOINKEYS F1=MASTER,FIELDS=(134,8,A)                                     
                                                                         
 JOINKEYS F2=DETAIL,FIELDS=(1,8,A)                                       
                                                                         
 REFORMAT FIELDS=(F1:1,134)                                               
                                                                         
//*                                                                       
//SORTOUT  DD  SYSOUT=*                                                   
//*====================================================================   
Back to top
View user's profile Send private message
kris_madras

New User


Joined: 04 Jul 2005
Posts: 50

PostPosted: Fri Sep 19, 2025 9:35 pm
Reply with quote

Thank You sergeyken, Working on the logic you provided.

COPY JKFROM is new for me. Thanks.
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Sort SMF records? SYNCSORT 6
No new posts To Sort detail records in a file with... SYNCSORT 5
No new posts Identify and write records containing... SYNCSORT 11
No new posts Extract records for a specific condit... DFSORT/ICETOOL 25
No new posts Write record twice based on condition... SYNCSORT 7
Search our Forums:


Back to Top