Sort file by groups, keeping only the last group
Moderators: Frank Yaeger, Moderator Group
Sort file by groups, keeping only the last group
I have a file with RECFM=FBA and LRECL=1000 that contains ser of records by mbr-id, which consist of following format:
none to 1 DTL record, none-to-many PRM records, none-to many SUP records. The same mbr-id can have more then one set of these records.
I need to keep only the last set for the mbr.
Sample:
DTLMBRA
PRMMBRA
SUPMBRA
SUPMBRA
DTLMBRB
PRMMBRB
PRMMBRB
DTLMBRA
PRMMBRA
In this sample I will want my output to include only thesde records:
DTLMBRB
PRMMBRB
PRMMBRD
DTLMBRA
PRMMBRA
mbr-id starts in col 4, lenght 12 (CHAR), Record type starts in col 1 lenght 3 (CHAR).
Thank you
none to 1 DTL record, none-to-many PRM records, none-to many SUP records. The same mbr-id can have more then one set of these records.
I need to keep only the last set for the mbr.
Sample:
DTLMBRA
PRMMBRA
SUPMBRA
SUPMBRA
DTLMBRB
PRMMBRB
PRMMBRB
DTLMBRA
PRMMBRA
In this sample I will want my output to include only thesde records:
DTLMBRB
PRMMBRB
PRMMBRD
DTLMBRA
PRMMBRA
mbr-id starts in col 4, lenght 12 (CHAR), Record type starts in col 1 lenght 3 (CHAR).
Thank you
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
What is the approx. maximum number of unique mbr-ids you can have?
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
TamiAZ,
If your file is FBA , the first byte will be ANSI carriage control character and your data actually starts in pos 2.
Assuming that your input is FB and mbr-id starts in col 4, lenght 12 (CHAR), Record type starts in col 1 lenght 3 (CHAR), the following DFSORT JCL will give you the desired results. However the Output is sorted on the MBR-ID
If your file is FBA , the first byte will be ANSI carriage control character and your data actually starts in pos 2.
Assuming that your input is FB and mbr-id starts in col 4, lenght 12 (CHAR), Record type starts in col 1 lenght 3 (CHAR), the following DFSORT JCL will give you the desired results. However the Output is sorted on the MBR-ID
Code: Select all
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=your input FB 1000 Lrecl file,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'DTL'),
PUSH=(1001:4,12,ID=8))
SORT FIELDS=(1001,12,CH,A,1013,8,CH,D),EQUALS
OUTREC IFTHEN=(WHEN=INIT,
OVERLAY=(1021:SEQNUM,8,ZD,RESTART=(1001,12))),
IFTHEN=(WHEN=GROUP,BEGIN=(1021,8,ZD,EQ,1),PUSH=(1029:1013,8))
OUTFIL BUILD=(1,1000),INCLUDE=(1013,8,CH,EQ,1029,8,CH)
/*
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
I was working on a solution for this and ran into some points of confusion that I need you to clarify.
1. You say that the file has RECFM=FBA so wouldn't the record type start in position 2 after the carriage control character in position 1?
2. You say you can have "none to 1 DTL record". So does that mean a "group" can start without a DTL record? If so, how do you tell the groups apart? For example, if you had the following "two" groups each with a 'DTL' record, we could identify the beginning of the group by its 'DTL' record:
But if the DTL record doesn't have to be present, then we could have:
so how would we know which MBRA records belonged to which group? Please clarify the "rules" for determining where a group starts.
1. You say that the file has RECFM=FBA so wouldn't the record type start in position 2 after the carriage control character in position 1?
2. You say you can have "none to 1 DTL record". So does that mean a "group" can start without a DTL record? If so, how do you tell the groups apart? For example, if you had the following "two" groups each with a 'DTL' record, we could identify the beginning of the group by its 'DTL' record:
Code: Select all
DTLMBRA group 1 for MBRA
PRMMBRA group 1 for MBRA
DTLMBRA group 2 for MBRA
PRMMBRA group 2 for MBRA
SUPMBRA group 2 for MBRA
Code: Select all
PRMMBRA
PMMMBRA
SUPMBRA
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
In that case, Kolusu's assumptions were correct and you can use his solution.
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page