Sort file by groups, keeping only the last group

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
TamiAZ
Member
Posts: 4
Joined: Thu Oct 01, 2009 12:31 pm

Sort file by groups, keeping only the last group

Post by TamiAZ » Thu Oct 01, 2009 12:44 pm

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

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Thu Oct 01, 2009 9:45 pm

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

TamiAZ
Member
Posts: 4
Joined: Thu Oct 01, 2009 12:31 pm

Post by TamiAZ » Thu Oct 01, 2009 10:39 pm

Unknown. It can range from 1 to several thousands.

skolusu
Member
Posts: 43
Joined: Sat Jul 26, 2008 12:38 am

Post by skolusu » Thu Oct 01, 2009 10:57 pm

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

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)         
/* 
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Thu Oct 01, 2009 11:02 pm

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:

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
But if the DTL record doesn't have to be present, then we could have:

Code: Select all

 PRMMBRA    
 PMMMBRA  
 SUPMBRA   
so how would we know which MBRA records belonged to which group? Please clarify the "rules" for determining where a group starts.
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

TamiAZ
Member
Posts: 4
Joined: Thu Oct 01, 2009 12:31 pm

Post by TamiAZ » Thu Oct 01, 2009 11:20 pm

Frank - for you questions:
1. The record format is FB and not FBA, sorry.
2. The DTL record is the rule for determining a droup. If there is no DTL record at
the begining of the file, one wil be added prior to running this job. Sorry for the confusion.. Thanks

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Fri Oct 02, 2009 12:51 am

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

TamiAZ
Member
Posts: 4
Joined: Thu Oct 01, 2009 12:31 pm

Post by TamiAZ » Fri Oct 02, 2009 11:24 am

Thank you all!

Post Reply

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



Other References
Mainframe Tools and others