0
1234 ABCD  
3991 ABCD
3818 ABCD
1939 PQRS
2838 PQRS
1939 ABCD
2819 PQRS
2102 FILQ
2911 ABCD
3912 FILQ

I want to write all the records with ABCD in a file, all the records PQRS in a file all the records with FILQ in a file and so on. I dont know what these columns are going to be before hand.

user218324
  • 3
  • 1
  • 3

2 Answers2

3

If you want to split into multiple files based on a fixed position with values that you don't know, you are going to need to SORT the data (on the field to split by) and use WHEN=GROUP on OUTREC to have something to be able to INCLUDE on in multiple OUTFILs.

//SYSIN    DD * 
  SORT FIELDS=(6,4,CH,A) 
  OUTREC IFTHEN=(WHEN=GROUP, 
                 KEYBEGIN=(6,4), 
                 PUSH=(81:ID=2)) 

  OUTFIL INCLUDE=(81,2,CH,EQ,C'01'),
         FNAMES=OUT1, 
         BUILD=(1,80) 
  OUTFIL INCLUDE=(81,2,CH,EQ,C'02'),
         FNAMES=OUT2, 
         BUILD=(1,80) 
  OUTFIL SAVE, 
         FNAMES=OUTA, 
         BUILD=(1,80) 
//SORTIN   DD * 
1234 ABCD 
3991 ABCD 
3818 ABCD 
1939 PQRS 
2838 PQRS 
1939 ABCD 
2819 PQRS 
2102 FILQ 
2911 ABCD 
3912 FILQ 

Gives:

OUT1
1234 ABCD
1939 ABCD
2911 ABCD
3991 ABCD
3818 ABCD

OUT2
3912 FILQ
2102 FILQ

OUTA
1939 PQRS
2819 PQRS
2838 PQRS

I've used 80-byte fixed-length records for testing. If your record-length is different, change all the references to 81 to your-record-length-plus-one and all references to 80 to your record-length.

If your data is on variable-length records, you should have mentioned it earlier. The code is different.

WHEN=GROUP defines a group, and allows information from the definition of the group to be applied to all records in the group (using PUSH). There are two special fields available, ID (a sequence number for groups) and SEQ (a sequence number within the group). ID=2 means a-two-digit sequence number for groups. This allows up to 100 groups before things start going wrong with the code.

There will be 10 OUTFILs (I show three). For the final OUTFIL (I've called it OUTA) I'd suggest using SAVE instead of INCLUDE. SAVE means "all records which aren't on another OUTFIL go here". Even if you get more than 10 groups, at least you'll have all the data (until you exceed 100 groups).

PUSH is similar to OVERLAY, except it cannot use literal values of any type, only the special fields mentioned above and any data from the record which defines the group.

This PUSH will extend the records. To make it a temporary extension, the BUILD in each OUTFIL returns each record to its original size.

Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
1

Assuming that values you need to sort on will not change on the fly, you could use something like this:

//STEP1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SYSIN  DD DSN=YOUR.INPUT.FILE,DISP=OLD
//OUT1   DD DSN=OUTPUT.FILE.ONE,DISP(NEW,CATLG),
//          SPACE=(CYL,(5,5),UNIT=SYSDA
//OUT2   DD DSN=OUTPUT.FILE.TWO,DISP(NEW,CATLG),
//          SPACE=(CYL,(5,5),UNIT=SYSDA
//SYSIN DD *
  OPTION COPY
  OUTFIL INCLUDE=(6,4,CH,EQ,C'ABCD'),FNAMES=OUT1
  OUTFIL INCLUDE=(6,4,CH,EQ,C'PQRS'),FNAMES=OUT2
/*

Then you can repeat this up to as many times as you need.

Basically, you just need to search that specific location (in this case position 6 for a length of 4) for the literal, then specify the output dataset.

Obviously you space parameters will probably be different than what I used, but that should be more than enough to get you going!

SaggingRufus
  • 1,814
  • 16
  • 32