Sort and filter a file into multiple files using 1 sort card

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

Moderators: Frank Yaeger, Moderator Group

Post Reply
ChykyMunky
Member
Posts: 12
Joined: Tue May 05, 2015 8:21 pm

Sort and filter a file into multiple files using 1 sort card

Post by ChykyMunky » Tue Jun 09, 2015 8:05 pm

** Please show code in your explanation **

Hi,
If I have an input file I want to be able to split the data into multiple output, and as it splits the data I want it to also sort the data.

So my files would be:

Code: Select all

INPUT.FILE1
OUTPUT.FILE1
OUTPUT.FILE2
Inside my input file is the following data

Code: Select all

REC1 XXX
REC2 TTT
REC1 AAA
REC2 BBB
REC1 SSS
REC2 CCC
Now in my output file not only should it split REC1 and REC2 but it should also sort the remaining letter in alphabetic order. So it looks like this.

Code: Select all

OUTPUT.FILE1
REC1 AAA
REC1 SSS
REC1 XXX

OUTPUT.FILE2
REC2 BBB
REC2 CCC
REC2 TTT
** Please show code in your explanation **

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Tue Jun 09, 2015 9:06 pm

So you SORT the data on the letters.

You use OUTFIL with INCLUDE= for the "REC1", FNAMES for your first output DD.

Use OUTFIL with SAVE for the second output DD.

ChykyMunky
Member
Posts: 12
Joined: Tue May 05, 2015 8:21 pm

Post by ChykyMunky » Wed Jun 10, 2015 2:56 am

Sorry William,
I wrote the example to be simple but in actuality the data I will be working with won't be. I will be working with many different files. They will need to be sorted on more than one criteria. Some will need to be sorted by name, other by date, time, etc. And even in combinations.

I hope I explained that better, or would you like me to provide examples?

ChykyMunky
Member
Posts: 12
Joined: Tue May 05, 2015 8:21 pm

Post by ChykyMunky » Wed Jun 10, 2015 6:17 pm

After talking to a coworker about this topic, what I want to be cant be done.
You can only have one sort field per sort card.
I will have to create a different sort card for each file and work with them separately.
So first I will filter my data into separate files, then sort each file individually.

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Wed Jun 10, 2015 8:57 pm

Well, your co-worker is talking bananas, but if you want extra resource costs for your client, go with your idea.

If you require some more hints, provide better explanations and representative sample data.

ChykyMunky
Member
Posts: 12
Joined: Tue May 05, 2015 8:21 pm

Post by ChykyMunky » Fri Jun 12, 2015 1:23 am

Code: Select all

1310078+INVALID ACCOUNT NUMBER
11CLIENT100760702115922710006110221F6F6F BR42364186732232502210437120000101
12CUSTOMERA0076072211592284000610312 N4N4NBB427537468055001503121141520000101  
1A0527I3I3I0610FBB440897171593261505270322080000101100000CCP
1310061+WRONG MERCHANT NUMBER
1A0527I3I3I0610FBB440897171593241505270414490000101100000CCP
11CLEINT300760702115922710006110305U4U4UBR420423966781231503052129190000101
1310231+MISSING USER ID 
12CUSTOMERA00760722115922840006120604N4N4NBB442456972745221506041402480000101 
11CLIENT400760702115922710006170305U4U4UBR420424366781291503052141300000201 
1A0527I3I3I0610FBB440897471593291505270625500000201100000CCP
1A0527N3I30610FBB440897671593351505270443030000201503100 CCP
12CUSTOMERW00760722115922840006110317P2P2PBB427537468055001503171519310000201      
11CLIENT200760702115922710006160304U3U3UBR420424366781291503042137500000101            
12CUSTOMERW00760722115922840006120424R5N5RBB434930569614871504241246270000101            
So above is the input data that I would need moved into 4 files based on whats in the first 2 columns.
1A to REPORT1A, and so on with 11, 12, and 13. This is the easy part cuz I can accomplish that with INCLUDE command.

Now heres the tricky part... Sorting on different fields
I want REPORT1A to sort on field 15-18
REPORT11 on field 3-9, 17-20, and 24-30
REPORT12 on field 3-12,13-21
REPORT13 on field 3-7

Is that possible?

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Fri Jun 12, 2015 2:58 am

Yes, you temporarily extend the records with INREC, to include enough bytes for the longest key. You put the key in the extension, depending on the type, using IFTHEN=(WHEN=(logical expression). Then you SORT on the extended key, and use four OUTFILs with three INCLUDE= for the different key, with BUILD to reduce the record to the original data, and a final OUTFIL with SAVE and the same BUILD.

ChykyMunky
Member
Posts: 12
Joined: Tue May 05, 2015 8:21 pm

Post by ChykyMunky » Sat Jun 13, 2015 6:58 am

Oh wow. Ive never done any of that before. My experience with JCL is pretty basic.

Can you show the code for that?

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Mon Jun 15, 2015 1:36 pm

Code: Select all

  INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'A'),
          BUILD=(1,10,3,2,2X)),
        IFTHEN=(WHEN=NONE,
          BUILD=(1,10,5,4))

  SORT FIELDS=(11,4,CH,A)
 
  OUTFIL FNAMES=TYPEA,
         INCLUDE=(1,1,CH,EQ,C'A'),
         BUILD=(1,10)

  OUTFIL FNAMES=REST,
         SAVE,
         BUILD=(1,10)
There's an example using two different sort keys, two different output DDs and fixed-length records.

ChykyMunky
Member
Posts: 12
Joined: Tue May 05, 2015 8:21 pm

Post by ChykyMunky » Tue Jun 16, 2015 2:57 am

Can you show me the code with the example I gave. Im just not getting how the fields are getting sorted. Under normal circumstances I could research this, however, I have to present this idea soon.

Like I said though, I'm not all the familiar with SORT, or JCL. Im really confused about the BUILD condition because I thought that was for formating. And I don't know the input or the output of the file being used in the example so I cant even make the connections.

This is what I have so far. I really don't understand the rest.

Code: Select all

OUTFIL FILES=1,             
  INCLUDE=(1,2,CH,EQ,C'1A') 
OUTFIL FILES=2,             
  INCLUDE=(1,2,CH,EQ,C'11') 
OUTFIL FILES=3,             
  INCLUDE=(1,2,CH,EQ,C'12') 
OUTFIL FILES=4,             
  INCLUDE=(1,2,CH,EQ,C'13') 
SORT FIELDS=COPY            

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