I have some problem in sorting a file using DFSORT.Scenario is like,
I have to sort a file based on some reference number.But actual file is variable length format and the file format is like
HEADER RECORD (20 BYTES)
DETAIL RECORD (100 BYTES)
DETAIL RECORD (100 BYTES)
DETAIL RECORD (100 BYTES)
DETAIL RECORD (100 BYTES)
TRAILER RECORD (20 BYTES)
We want to sort the detail records based on some reference number with an offset of (50 : 10) in detail record. Here we want to skip the both header and trailer records.
Can we handle this total process in a one DFSORT step?
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
Hi Kranti,
If I interpreted correctly, you want to SORT your VB Input File with skippping Header & trailer Record on basis of field starting from column number 50 up to length of 10 chars.
Here you have not mentioned, that field is of what type ? also REC Length of the Input File....
Output dataset attributes will be same as Input dataset attributes i.e., RECFM, LRECL etc....
1) OPTION VLSHRT - will tell DFSORT to expect input records LESS THAN Sort fields criteria i.e., 54:10.
2) If you want to convert to FB then use option VTOF i.e., Variable to Fixed
3) VLFILL=C'X' to fill the pad / extra spaces at right side with X characters.
4) To exclude Last record (STOPAFT = N) WILL NOT work. To overcome that problem we need to change SORT crieteria to exclude Detail record...But this is the crude way....
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Kran,
The DFSORT job below will do what I think you asked for.
Since you didn't supply a lot of details, I'm going to make some assumptions. If these assumptions are wrong, then change the job accordingly, or supply the details if you want me to show you how to change the job.
Assumptions:
1) When you say "We want to sort the detail records based on some reference number with an offset of (50 : 10) in detail record", you're not counting the RDW in positions 1-4, so the sort field actually starts in position 54. And its a 10-byte CH sort field.
2) When you say "we want to skip the both header and trailer records", you really mean that you want to keep the HEADER and TRAILER records as the first and last records respectively and only sort the DETAIL records in between.
3) There's something in the HEADER and TRAILER records that identifies them, e.g. 'HEADER' in positions 5-10 and 'TRAILER' in positions 5-11.
Code:
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file (VB)
//SORTOUT DD DSN=... output file (VB)
//SYSIN DD *
* Reformat HEADER record to:
* |RDW|'0'|blanks|input|
INREC IFTHEN=(WHEN=(5,6,CH,EQ,C'HEADER'),
BUILD=(1,4,5:C'0',6:10X,16:5)),
* Reformat TRAILER record to:
* |RDW|'9'|blanks|input|
IFTHEN=(WHEN=(5,6,CH,EQ,C'TRAILER'),
BUILD=(1,4,5:C'9',6:10X,16:5)),
* Reformat DETAIL record to:
* |RDW|'1'|key...|input|
IFTHEN=(WHEN=NONE,
BUILD=(1,4,5:C'1',6:54,10,16:5))
* Sort on id/key (id is '0', '1' or '9')
SORT FIELDS=(5,11,CH,A)
* Reformat records back to:
* |RDW|input|
OUTREC FIELDS=(1,4,16)
/*
Hi Frank,
We are very thankful to your reply. Following are the comments for your assumptions.
1. You are correct. reference number will start from 54 and of length 10 (54 : 10).
2. we dont want to see the header and trailer records in the output dataset and want to sort only detail records based on reference number as explained in my earlier mail.
3. first three characters (5 : 3) of the record are zeroes indicates header record. first three characters (5 : 3) of the record are 999 indicates trailer record.
Sorry to say that the solution which u have provided will not work for us.Since we are not using the advanced version,IFTHEN will not work in our environment.