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
 

 

Syncsort 1.4.0.1R - Limit Records When Fields Change

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> SYNCSORT
View previous topic :: :: View next topic  
Author Message
Paresh123

New User


Joined: 02 Jan 2014
Posts: 4
Location: USA

PostPosted: Wed Jan 22, 2014 12:59 am    Post subject: Syncsort 1.4.0.1R - Limit Records When Fields Change
Reply with quote

Using Syncsort 1.4.0.1R, I would like to limit the number of records in the output that have a particular combination of values for FIELD1 and FIELD2 e.g. in the data below, the particular combinations are
1) "MONKEY" and "YES"
2) "MONKEY" and "NO"
3) "SAM" and "YES"
4) "SAM" and "NO"

Code:
FIELD1    FIELD2
MONKEY    YES
MONKEY    YES
MONKEY    YES
MONKEY    YES
MONKEY    YES
MONKEY    NO
SAM       YES
SAM       YES
SAM       NO
SAM       NO
SAM       NO
SAM       NO
SAM       NO


If I wanted to limit of 2records/combination, the output should look like:
Code:
FIELD1    FIELD2
MONKEY    YES
MONKEY    YES
MONKEY    NO
SAM       YES
SAM       YES
SAM       NO
SAM       NO


One approach to this problem, would be to:
1) Sort by FIELD1, then FIELD2
2) Add a Sequence Number, that restarts whenever FIELD2 Changes
3) Include only records that have a Sequence number less than 3.

This approach falls flat if a particular combination is missing - if the "MONKEY NO" record is missing in the input, then then we go from one combination ("MONKEY YES") to another (SAM YES) without the sequence number restarting. Any suggestions? If I need to be more clear about what I am asking, please let me know.
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Wed Jan 22, 2014 1:52 am    Post subject: Reply to: Syncsort 1.4.0.1R - Limit Records When Fields Chan
Reply with quote

If that is what your data looks like, add a sequence number, using RESTART= and specify both fields as a single field on the RESTART.

The OUTFIL INCLUDE= on the sequence number, and BUILD to cut the record back down to size.

Details depend on V vs F and the length of your fields.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Jan 22, 2014 1:52 am    Post subject:
Reply with quote

Hello and welcome to the forum,

What should happen if field1 or field2 does not contain a "control" value (i.e. MONKEY MAYBE or SAM blank)?
Back to top
View user's profile Send private message
Paresh123

New User


Joined: 02 Jan 2014
Posts: 4
Location: USA

PostPosted: Wed Jan 22, 2014 2:15 am    Post subject:
Reply with quote

Hello Dick and thanks for the warm welcome.

The first control field can have 101 different values; the second control field will always be one of two values, but never blank.

Bill,
The actual data differs from what was posted in that the control fields are non-contiguous. The records are fixed length and the Control fields are always in the same position.

I suppose I can reformat the record to make the two control fields contiguous and then use SEQNUM with the RESTART parameter on that combined control field. I think this is the solution. Thank you both for your help! I'll post some sample data and code for future reference in a future post.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Wed Jan 22, 2014 2:38 am    Post subject: Reply to: Syncsort 1.4.0.1R - Limit Records When Fields Chan
Reply with quote

Yes, I think that will do. Your sample data shows that the key fields are contiguous, even if not in sorted order. If they are non-contiguous, you will have to SORT, otherwise I think you have the correct approach.
Back to top
View user's profile Send private message
Paresh123

New User


Joined: 02 Jan 2014
Posts: 4
Location: USA

PostPosted: Wed Feb 05, 2014 1:54 am    Post subject: Reply to: Syncsort 1.4.0.1R - Limit Records When Fields Chan
Reply with quote

Task: Limit unique combinations of non-contiguous control fields (fields 1 and 3) to two records each using Syncsort.

Input Text
Code:
Field1 Field2      Field3
MONKEY NONSENSE    YES
MONKEY NONSENSE    YES
MONKEY NONSENSE    YES
MONKEY NONSENSE    YES
MONKEY NONSENSE    YES
MONKEY MEANINGLESS YES
MONKEY MEANINGLESS YES
MONKEY MEANINGLESS MAYBE
MONKEY MEANINGLESS NO
MONKEY MEANINGLESS NO
MONKEY MEANINGLESS NO
SAM    MEANINGLESS YES
SAM    MEANINGLESS MAYBE
SAM    MEANINGLESS MAYBE
SAM    MEANINGLESS MAYBE
SAM    MEANINGLESS MAYBE
SAM    MEANINGLESS NO
SAM    MEANINGLESS NO
SAM    MEANINGLESS NO
SAM    MEANINGLESS NO
SAM    MEANINGLESS NO


Output:
Code:

MONKEY NONSENSE    YES
MONKEY NONSENSE    YES
MONKEY MEANINGLESS MAYBE
MONKEY MEANINGLESS NO
SAM    MEANINGLESS YES
SAM    MEANINGLESS MAYBE
SAM    MEANINGLESS MAYBE
SAM    MEANINGLESS NO
SAM    MEANINGLESS NO


One Solution:
Code:

//JS01 EXEC PGM=SYNCSORT
//SORTIN  DD DISP=SHR,DSN=TEST.INPUT
//SORTOUT DD DSN=TEST.SEQNUM.ADDED
//        UNIT=TESTCI,SPACE=(TRK,(10)),
//        DCB=RECFM=FB,BLKSIZE=0,LRECL=26),
//        DISP=NEW,CATLG,DELETE)
//SORTWK01 DD UNIT=TEST,SPACE=(TRK,(10))
//SYSOUT DD SYSOUT=*
//SYSIN DD *
  INREC FIELDS=(01:08,12, Field2
                13:01,07, Field1
                20:20,05) Field3
  SORT FIELDS=(13,12,CH,A)
  OUTREC FIELDS=(1,24,25:SEQNUM,2,ZD,RESTART=(13,12))
//JS02  EXEC PGM=SYNCSORT
//SORTIN  DD DISP=SHR,DSN=TEST.SEQNUM.ADDED
//SORTOUT DD DSN=TEST.OUTPUT,
//        UNIT=TESTCI,SPACE=(TRK,(10)),
//        DCB=RECFM=FB,BLKSIZE=0,LRECL=24),
//        DISP=NEW,CATLG,DELETE)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
  INCLUDE COND=(25,2,ZD,LE,3)
  SORT FIELDS=COPY
  OUTREC FIELDS=(01:13,07, Field 1
                 08:01,12, Field 2
                 20:20,05) Field 3
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
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts syncsort: copy lines after the keyword shreya19 SYNCSORT 3 Fri Dec 02, 2016 9:47 am
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts Syncsort - Hard coded Value in output PORYES SYNCSORT 1 Thu Nov 03, 2016 9:23 am
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Access SQLCA fields inside a stored p... gangapd DB2 4 Thu Oct 27, 2016 10:20 am


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