Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help for Sorting a file 1

Status
Not open for further replies.

gopalrathi

Programmer
Oct 21, 2003
5
0
0
US
Hi All,
This is my first post in this forum.
I want to know if following can be achieved through SORT (DFSORT or SYNCSORT)or I need to have a program for this.
Input file is as follows. A and B are record types and TRL has the count of A and B records.

HDR
A
A
B
TRL0003

The output of SORT should be two files as follows

HDR
A
A
TRL0002

and....

HDR
B
TRL0001

HDR is same as in the input file. Files are fixed length (900 bytes). Platform : OS/390

Thanks,
Gopal.
 
I believe you can do this with multiple sorts, but . . . I haven't tried it and others with more experience/knowledge may have better approaches. Here are some random thoughts:

1. SORT FIELDS=COPY
2. If you know what the HDR record looks like a priori, use the HEADER1 parameter of the OUTFIL statement to write it. Otherwise, see below.
3. Use two OUTFIL statements to create the two output files. Use the INCLUDE parameter to select the A or B records.
4. Use the TRAILER1 parameter of the OUTFIL statement to write the trailer. The COUNT subparameter will have a count of the selected records.

If you don't know what the HDR record looks like a priori (i.e. the fields in it change from run to run), I think you'll have to do additional sort steps to merge it in to the two output files. Use a third OUTFIL statement in the first sort to extract it by itself. Then merge it in steps 2 (A records) and 3 (B records). Make sure it is SORTIN1 so it gets put first when using FIELDS=COPY.

A COBOL program to do this may or may not be faster depending on the size/location of the files. Sort is generally extremely fast with IO and I avoid COBOL programs (and associated maintenance overhead) when I can accomplish the task fairly easily with standalone SORT. That said, YMMV.

BTW, when you ask your question like "Can I do such-and-such", you run the risk of getting an answer like "Yes" or "No". Better to ask "How can I . . . ".

Regards.

Glenn
 
A further thought, many trailers contain a trailer count. If yours does, it will need manipulation after sorting.
 
Thanks Glenn.
This did solve the problem. I carried the same header as in the input file to both the output files.
But I had to change RECFM of the output files from FB to FBA. What is the difference between the two? Do we need any different handling for FBA compared to FB in the programs (COBOL).
My OUTFIL for SORT look like this....

OUTFIL FNAMES=OUT1,
INCLUDE=(1,1,CH,EQ,C'A',OR,1,3,CH,EQ,C'HDR'),
TRAILER1=(1:'TRL',COUNT)
OUTFIL FNAMES=OUT2,
INCLUDE=(1,1,CH,EQ,C'B',OR,1,3,CH,EQ,C'HDR'),
TRAILER1=(1:'TRL',COUNT)

Thanks,
Gopal.
 
Gopal -

FBA means the output is Fixed, Blocked, with ASA carriage control characters. My guess is that when using TRAILER1, SORT decides you're producing a written report and constructs the DCBs with ASA turned on. You might try the DISK parameter on the OUTFIL cards to resolve this problem.

Regards.

Glenn
 
I tried DISK parameter but it didn't help. Quick refrence says DFSORT accepts this parameter but does not process it.
There is another OUTFIL parameter REMOVECC which could sort this out for me. It removes the carriage control characters. You can also specify RECFM=FB. So life is easier for me now!!

Thanks,
Gopal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top