Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Help with IF THEN and GROUP
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> SYNCSORT
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    Post subject: Help with IF THEN and GROUP
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

Active User


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

PostPosted: Thu Feb 20, 2020 7:41 pm    Post subject:
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    Post subject: Reply to: Help with IF THEN and GROUP
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    Post subject: Reply to: Help with IF THEN and GROUP
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: 2405
Location: Hampshire, UK

PostPosted: Fri Feb 21, 2020 2:31 am    Post subject: Reply to: Help with IF THEN and GROUP
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

Active User


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

PostPosted: Fri Feb 21, 2020 4:20 am    Post subject:
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    Post subject: Reply to: Help with IF THEN and GROUP
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

Active User


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

PostPosted: Fri Feb 21, 2020 5:31 am    Post subject:
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    Post subject: Reply to: Help with IF THEN and GROUP
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    Post subject: Reply to: Help with IF THEN and GROUP
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

Senior Member


Joined: 21 Sep 2010
Posts: 2466
Location: NY,USA

PostPosted: Fri Feb 21, 2020 7:54 am    Post subject:
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: 2405
Location: Hampshire, UK

PostPosted: Fri Feb 21, 2020 3:16 pm    Post subject: Reply to: Help with IF THEN and GROUP
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    Post subject: Reply to: Help with IF THEN and GROUP
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    Post subject: Reply to: Help with IF THEN and GROUP
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

Senior Member


Joined: 21 Sep 2010
Posts: 2466
Location: NY,USA

PostPosted: Fri Feb 21, 2020 10:46 pm    Post subject:
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    Post subject: Reply to: Help with IF THEN and GROUP
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

Senior Member


Joined: 21 Sep 2010
Posts: 2466
Location: NY,USA

PostPosted: Fri Feb 21, 2020 11:24 pm    Post subject:
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    Post subject: Reply to: Help with IF THEN and GROUP
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    Post subject: Reply to: Help with IF THEN and GROUP
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

Senior Member


Joined: 21 Sep 2010
Posts: 2466
Location: NY,USA

PostPosted: Sat Feb 22, 2020 3:03 am    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> SYNCSORT All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Group selective VB records - Trailer ... Premnath_TJ DFSORT/ICETOOL 12 Sun Sep 13, 2020 3:38 am
No new posts Include Group record based on detail ... guptae DFSORT/ICETOOL 11 Thu Mar 12, 2020 1:54 pm
No new posts COBOL -DB2 SQL code to have GROUP BY ... vinu78 DB2 21 Wed Oct 23, 2019 7:00 pm
No new posts Copy Group of Records scorp_rahul23 DFSORT/ICETOOL 1 Sun Jan 13, 2019 9:17 am
No new posts Propagating value from nth record to ... ganasrinivasan DFSORT/ICETOOL 7 Fri Nov 30, 2018 8:31 am

Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us