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

Help with IF THEN and GROUP


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

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Thu Feb 20, 2020 7:22 pm
Reply with quote

Hi,

I have a requirement to split a file based on the record counts.
This is a VB file (222 LRECL) with multiple header and trailer records.
I will have to split this file into two files - one with each group of records having more than 30,000 detail records and other file with each group of records less than equal to 30,000 detail records.

Each group has identical HDR/TRL (start pos-1) records.
For example,

XXXHDR
AAAAA
BBBBB
XXXTRL
XXXHDR
CCCCC
DDDDD
XXXTRL
XXXHDR
EEEEEE
XXXTRL

I did try using IF THEN and GROUP, but i am not sure of how to count the records within each header/trailer and write to a file based on this.

Please post your suggestions. Appreciate your support!!
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Thu Feb 20, 2020 7:41 pm
Reply with quote

Post what you have tried please. Use Code tags when doing so.
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Thu Feb 20, 2020 9:29 pm
Reply with quote

Code:
OPTION COPY                                               
INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,8X,5)),                 
IFTHEN=((WHEN=GROUP,BEGIN=(13,5,CH,EQ,C'XXXHD'),           
  IFTHEN=(WHEN=(13,3,CH,EQ,C'XXX'),                       
        END=(13,4,CH,EQ,C'XXXT'),PUSH=(5:ID=8))           
                                                           
OUTFIL FNAMES=OUT1,INCLUDE=(5,8,ZD,LE,30000),BUILD=(1,4,13)
OUTFIL FNAMES=OUT2,SAVE,BUILD=(1,4,13)                     
END

Coded for you - this time. Next time do it yourself.
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Thu Feb 20, 2020 10:06 pm
Reply with quote

Coded for you - this time. Next time do it yourself. I am not sure if someone posted this message. This wasn't part of my response.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Feb 21, 2020 2:31 am
Reply with quote

Quote:
I am not sure if someone posted this message. This wasn't part of my response.

No it was not part of your response - you had been asked to explicitly use the code tags to present your data but you did not.The message indicates to others that you ignored a request. The code tags are there for a reason - use them.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Fri Feb 21, 2020 4:20 am
Reply with quote

@prynks91: Use the Code button above the input box when you start a code section and hit that again when finished to post code. Before you push the Submit button use preview to check what's about to be posted. Works like a charm. icon_wink.gif

If I have understood the request correctly you want to separate the data by distinguishing how many detail records are found. The split data however shall be with XXXHDR and XXXTRL records.

You may try the following sample (F1 and F2 must be identical):
Code:
//WHATEVER EXEC PGM=SORT,PARM='MSG=AP'   
//SYSOUT   DD SYSOUT=*                     
//F1       DD *                           
XXXHDR                                     
AAAAA                                     
BBBBB                                     
XXXTRL                                     
XXXHDR                                     
CCCCC                                     
DDDDD                                     
XXXTRL                                     
XXXHDR                                     
EEEEEE                                     
XXXTRL                                     
/*                                         
//F2       DD *                           
XXXHDR                                           
AAAAA                                           
BBBBB                                           
XXXTRL                                           
XXXHDR                                           
CCCCC                                           
DDDDD                                           
XXXTRL                                           
XXXHDR                                           
EEEEEE                                           
XXXTRL                                           
/*                                               
//LESS     DD SYSOUT=*                           
//MORE     DD SYSOUT=*                           
//SYSIN    DD *                                 
  JOINKEYS F1=F1,FIELDS=(10,10,A),TYPE=F         
  JOINKEYS F2=F2,FIELDS=(10,10,A),TYPE=F         
  REFORMAT FIELDS=(F2:1,9,F1:20,4)               
  SORT FIELDS=(COPY)                             
  OUTFIL FNAMES=(LESS),                         
    INCLUDE=(10,4,PD,LT,+2),                     
    BUILD=(1,9)                                 
  OUTFIL FNAMES=(MORE),                         
    SAVE,BUILD=(1,9)                             
/*                                               
//JNF1CNTL DD *                                                   
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(20:+0,PD,LENGTH=4)),           
    IFTHEN=(WHEN=GROUP,BEGIN=(1,6,CH,EQ,C'XXXHDR'),               
      END=(1,6,CH,EQ,C'XXXTRL'),PUSH=(10:ID=10)),                 
    IFTHEN=(WHEN=(1,3,CH,NE,C'XXX'),OVERLAY=(20:+1,PD,LENGTH=4)) 
  SUM FIELDS=(20,4,PD)                                           
  END                                                             
/*                                                               
//JNF2CNTL DD *                                                   
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,6,CH,EQ,C'XXXHDR'),           
    END=(1,6,CH,EQ,C'XXXTRL'),PUSH=(10:ID=10))                   
  END                                                             
/*                                                               


DD:LESS - Less than two data records
Code:
XXXHDR
EEEEEE
XXXTRL

DD:MORE - Greater or equal two data records
Code:
XXXHDR
AAAAA 
BBBBB 
XXXTRL
XXXHDR
CCCCC 
DDDDD 
XXXTRL
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Fri Feb 21, 2020 4:40 am
Reply with quote

Thanks for the response Jeorg!

The input file is a single file in VB format (LRECL is 222)and having multiple HDR/TRL with detail records within each of them. I would need to count the detail records and write them with Header/Trailers in 2 output files.

Output file- 1 ---> with detail records less than equal to 30,000
Output file- 2 ---> with detail records more than 30,000
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Fri Feb 21, 2020 5:31 am
Reply with quote

The sample has the functionality you are looking for. If the logic is understood you can modify the snippet for your VB;222 dataset as input for DD:F1 and DD:F2 and adjust the fields/positions and HDR/TRL strings etc. accordingly.
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Fri Feb 21, 2020 5:33 am
Reply with quote

Thank you so much Joerg!!
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Fri Feb 21, 2020 5:42 am
Reply with quote

My input file is a single file and i cannot use the Join keys function.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Fri Feb 21, 2020 7:54 am
Reply with quote

Please write a program if this is difficult to understand.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Feb 21, 2020 3:16 pm
Reply with quote

If you care to look closely you will see that Joerg's solution is using one dataset - it is being joined to itself.
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Fri Feb 21, 2020 6:55 pm
Reply with quote

Sure, Thank you!
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Fri Feb 21, 2020 10:32 pm
Reply with quote

Tried the below code after converting the file to FB format.
Having issues with incompatible LRECL in OUT1/OUT2

Code:

//SYSIN    DD *                                                 
  JOINKEYS F1=F1,FIELDS=(10,10,A),TYPE=F                       
  JOINKEYS F2=F2,FIELDS=(10,10,A),TYPE=F                       
  REFORMAT FIELDS=(F2:1,9,F1:20,4)                             
  SORT FIELDS=(COPY)                                           
  OUTFIL FNAMES=(OUT1),                                         
    INCLUDE=(10,4,PD,LT,+2),                                   
    BUILD=(1,9)                                                 
  OUTFIL FNAMES=(OUT2),                                         
    SAVE,BUILD=(1,9)                                           
//JNF1CNTL DD *                                                 
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(20:+0,PD,LENGTH=4)),         
    IFTHEN=(WHEN=GROUP,BEGIN=(1,5,CH,EQ,C'820HD'),             
      END=(1,4,CH,EQ,C'820T'),PUSH=(10:ID=10)),                 
    IFTHEN=(WHEN=(1,3,CH,NE,C'820'),OVERLAY=(20:+1,PD,LENGTH=4))
  SUM FIELDS=(20,4,PD)                                         
  END                                                           
//JNF2CNTL DD *                                                 
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,5,CH,EQ,C'820HD'),         
    END=(1,4,CH,EQ,C'820T'),PUSH=(10:ID=10))                   
  END                                                           
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Fri Feb 21, 2020 10:46 pm
Reply with quote

This topic should be locked .. it is simple to fix the issue reported above as well as just providing the sysin won’t help is to get you any help.

You must post back complete JCL and sysouts details.
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Fri Feb 21, 2020 11:13 pm
Reply with quote

Code:

//STEP0100 EXEC PGM=SORT                           
//SYSOUT   DD SYSOUT=*                             
//F1       DD DISP=SHR,DSN=XXXX.TST.G5615V         
//F2       DD DISP=SHR,DSN=XXXX.TST.G5615V         
//OUT1     DD DSN=XXX.TST.FILE1,                   
//            DISP=(,CATLG,CATLG),                 
//            DCB=(LRECL=218,RECFM=FB,BLKSIZE=0),   
//            SPACE=(TRK,(800,800),RLSE)           
//OUT2     DD DSN=XXX.TST.FILE2,                   
//            DISP=(,CATLG,CATLG),                 
//            DCB=(LRECL=218,RECFM=FB,BLKSIZE=0),   
//            SPACE=(TRK,(800,800),RLSE)           
//SYSIN    DD *                                     
  JOINKEYS F1=F1,FIELDS=(10,10,A),TYPE=F                         
  JOINKEYS F2=F2,FIELDS=(10,10,A),TYPE=F                         
  REFORMAT FIELDS=(F2:1,9,F1:20,4)                               
  SORT FIELDS=(COPY)                                             
  OUTFIL FNAMES=(OUT1),                                         
    INCLUDE=(10,4,PD,LT,+2),                                     
    BUILD=(1,9)                                                 
  OUTFIL FNAMES=(OUT2),                                         
    SAVE,BUILD=(1,9)                                             
//JNF1CNTL DD *                                                 
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(20:+0,PD,LENGTH=4)),         
    IFTHEN=(WHEN=GROUP,BEGIN=(1,5,CH,EQ,C'820HD'),               
      END=(1,4,CH,EQ,C'820T'),PUSH=(10:ID=10)),                 
    IFTHEN=(WHEN=(1,3,CH,NE,C'820'),OVERLAY=(20:+1,PD,LENGTH=4))
  SUM FIELDS=(20,4,PD)                                           
  END                                                           
//JNF2CNTL DD *                                                 
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,5,CH,EQ,C'820HD'),           
    END=(1,4,CH,EQ,C'820T'),PUSH=(10:ID=10))                     
  END                                                           


Sysout is listed below

Code:

-JOINKEYS REFORMAT RECORD LENGTH=   13, TYPE = F     
-OUT1     : RECFM=FB   ; LRECL=   218; BLKSIZE= 32700
-OUT2     : RECFM=FB   ; LRECL=   218; BLKSIZE= 32700
-OUT1     : DSNAME=XXX.TST.FILE1               
-OUT2     : DSNAME=XXX.TST.FILE2               
-OUT1     HAS INCOMPATIBLE LRECL                     
-OUT2     HAS INCOMPATIBLE LRECL         
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Fri Feb 21, 2020 11:24 pm
Reply with quote

Don't give any LRECL in DCB. Let syncsort allocates that and rerun after that.
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Sat Feb 22, 2020 12:10 am
Reply with quote

Thank you Rohit! the issue with LRECL got resolved.
But the output is not as expected. I am trying to get detail records less than equal to 25 into first output file. All the records are getting written into the second file instead.

Below is the code from SYSIN
Code:

  JOINKEYS F1=F1,FIELDS=(10,10,A),TYPE=F                   
  JOINKEYS F2=F2,FIELDS=(10,10,A),TYPE=F                   
  REFORMAT FIELDS=(F2:1,218,F1:1,218)                     
  SORT FIELDS=(COPY)                                       
  OUTFIL FNAMES=(OUT1),                                   
    INCLUDE=(10,4,PD,LT,+0025),                           
    BUILD=(1,9)                                           
  OUTFIL FNAMES=(OUT2),                                   
    SAVE,BUILD=(1,9)                                       
//JNF1CNTL DD *                                           
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(20:+0,PD,LENGTH=4)),   
    IFTHEN=(WHEN=GROUP,BEGIN=(1,5,CH,EQ,C'820HD'),         
      END=(1,4,CH,EQ,C'820T'),PUSH=(10:ID=10)),           
    IFTHEN=(WHEN=(1,5,CH,NE,C'820HD',OR,1,4,CH,NE,C'820T'),
            OVERLAY=(20:+1,PD,LENGTH=4))                   
  SUM FIELDS=(20,4,PD)                                     
  END                                                     
//JNF2CNTL DD *                                           
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,5,CH,EQ,C'820HD'),     
    END=(1,4,CH,EQ,C'820T'),PUSH=(10:ID=10))               
  END                                                     
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Sat Feb 22, 2020 2:51 am
Reply with quote

Just tried with the below code and I am getting the desired results. The only issue i have here is the output is not with the complete LRECL(218). It is written with LRECL of 9 bytes.

Code:

  JOINKEYS F1=F1,FIELDS=(10,10,A),TYPE=F                   
  JOINKEYS F2=F2,FIELDS=(10,10,A),TYPE=F                   
  REFORMAT FIELDS=(F2:1,9,F1:20,4)                         
  SORT FIELDS=(COPY)                                       
  OUTFIL FNAMES=(OUT1),                                   
    INCLUDE=(10,4,PD,LT,+0100),                           
    BUILD=(1,9)                                           
  OUTFIL FNAMES=(OUT2),                                   
    SAVE,BUILD=(1,9)                                       
//JNF1CNTL DD *                                           
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(20:+0,PD,LENGTH=4)),   
    IFTHEN=(WHEN=GROUP,BEGIN=(1,5,CH,EQ,C'820HD'),         
      END=(1,4,CH,EQ,C'820T'),PUSH=(10:ID=10)),           
    IFTHEN=(WHEN=(1,5,CH,NE,C'820HD',OR,1,4,CH,NE,C'820T'),
            OVERLAY=(20:+1,PD,LENGTH=4))                   
  SUM FIELDS=(20,4,PD)                                     
  END                                                     
//JNF2CNTL DD *                                           
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,5,CH,EQ,C'820HD'),     
    END=(1,4,CH,EQ,C'820T'),PUSH=(10:ID=10))               
  END                                                     


Having issues with BUILD when i change it from 9 to 218.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Sat Feb 22, 2020 3:03 am
Reply with quote

If you want LRECL 218 then change your BUILD to
Code:
BUILD=(1,9,209X)

for both OUTFILEs.
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Sat Feb 22, 2020 3:07 am
Reply with quote

Thanks Rohit! But I would need the 209 bytes data from the input record itself
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Sat Feb 22, 2020 3:14 am
Reply with quote

Thanks Rohit! But i would like to retain the 209 bytes data from Input.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Sat Feb 22, 2020 5:50 pm
Reply with quote

Code:
//DATASPLT EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTOUT  DD SYSOUT=*                                             
//F1       DD DISP=OLD,DSN=&SYSUID..VB222                         
//F2       DD DISP=OLD,DSN=&SYSUID..VB222                         
//LESS     DD DISP=OLD,DSN=&SYSUID..VB222.LESS                     
//MORE     DD DISP=OLD,DSN=&SYSUID..VB222.MORE                     
//SYSIN    DD *                                                   
  JOINKEYS F1=F1,FIELDS=(223,10,A),TYPE=V                         
  JOINKEYS F2=F2,FIELDS=(223,10,A),TYPE=V                         
  REFORMAT FIELDS=(F2:5,218,F1:233,4)                             
  SORT FIELDS=(COPY)                                               
  OUTFIL FNAMES=(LESS),                                           
    INCLUDE=(219,4,PD,LE,+30000),                                 
    REMOVECC,FTOV,BUILD=(1,218)                                   
  OUTFIL FNAMES=(MORE),                                           
    SAVE,REMOVECC,FTOV,BUILD=(1,218)                               
/*                                                                 
//JNF1CNTL DD *                                                   
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(233:+0,PD,LENGTH=4)),           
    IFTHEN=(WHEN=GROUP,BEGIN=(5,5,CH,EQ,C'820HD'),                 
      END=(5,4,CH,EQ,C'820T'),PUSH=(223:ID=10)),                   
    IFTHEN=(WHEN=(5,3,CH,NE,C'820'),OVERLAY=(233:+1,PD,LENGTH=4)) 
  SUM FIELDS=(233,4,PD)                                           
  END                                                             
/*                                                                 
//JNF2CNTL DD *                                         
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(5,5,CH,EQ,C'820HD'), 
    END=(5,4,CH,EQ,C'820T'),PUSH=(223:ID=10))           
  END                                                   
/*
Back to top
View user's profile Send private message
prynks91

New User


Joined: 20 Feb 2020
Posts: 14
Location: USA

PostPosted: Tue Feb 25, 2020 9:11 pm
Reply with quote

Thank you Jeorge. This worked fine!
Thank you all for the suggestions!!
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 -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
No new posts Splitting group records based on deta... DFSORT/ICETOOL 8
No new posts SORT HELP - SORT A COLUMN and GROUP B... DFSORT/ICETOOL 9
No new posts INCLUDE COND with WHEN=GROUP SYNCSORT 12
Search our Forums:

Back to Top