mfsort examples
Summary: On this page you will find examples of mfsort programs written in the style of the quick how-to. All have been run using Server Express on a HPUX host and under Windows using Net Express. Sometimes there are several versions of the same example in order to show different ways to reach the desired goal.
Example 1: Simple sort on a single field
As simple as it gets, a single file is sorted on a pic X(14) field with a single file out as well.
sort fields(257,14,ch,a)
use k0202a.dat org sq record f,270
give k0203.dat
Example 2: Simple sort, multiple fields
This is almost as simple as the first example. The difference is that we have four sort fields, pic X, pic X(27), pic 9(3), and pic 9(13).
sort fields (1,1,ch,a,72,27,ch,a,1,3,nu,a,4,13,nu,a)
use k0205a.dat org sq record f,98
give k0206a.dat
Example 3: Sort and skip some records to another file
Depending on a pic X field, each record is written to one of two out files based on its value. If the field equals H its written to k1709a.dat, all other records are written to k1109a.dat.
sort fields=(135,1,ch,a,7,16,nu,a)
use k1101b.dat org sq record f,143
outfil
give k1109a.dat
omit (142,1,ch,eq,C'H')
outfil
give k1709a.dat
save
Example 4: Multiple input and output files
Two input files, sorted on a single x(33) field. As in the previous example some records are written to another outfile depending on the value of a pic X field.
sort fields(4,33,ch,a)
use k1110a.dat org sq record f,3737
use k3110a.dat
outfil
save
give k1113a.dat
outfil
include (44,1,ch,eq,C'H')
give k1713a.dat
Example 5: Skip records entirely
If a pic 9(6) field isn't zero, that record is dropped and ignored.
sort fields(1,3,nu,a,4,7,nu,a)
use k1181a.dat org sq record f,77
give k1184a.dat
omit cond=(11,6,nu,ne,C'000000')
Example 6: Merge two files, convert to line sequential
Two files are merged into one, but not sorted. The new file is converted to line sequential. NB! This is one case where the end result differs depending on where you run the sort. If you use mfsort in Net Express the end result contains cr-lf line terminators, using Server Express the line terminator is a single lf.
option copy
use k1685b.dat org sq record f 128
use k1110y.dat
give k1688a.dat org ls