Copyright: Copyright (C) 2002 Micro Focus International Ltd. All rights reserved.
Citation: Copyright (C) 2002 Micro Focus International Ltd. All rights reserved.


Mfsort

Mfsort (mfsort.exe) enables you to sort and merge files. It is invoked from the operating system command line as follows:

mfsort instructions

When specifying Mfsort instructions, you should bear in mind the maximum length of the command line allowed by the operating system. One way around this problem is to invoke Mfsort as follows:

mfsort take filename

where filename is the name of a file which contains a list of Mfsort instructions.

During a sort/merge operation, Mfsort uses a temporary workfile. This workfile is paged to disk in the current directory or, if it is set, in the directory specified by the TMP environment variable.

Mfsort copies all the records from each of the input files, truncated or padded as appropriate, to the temporary workfile. The workfile is then sorted/merged according to its key description. After being sorted/merged in the workfile, the records are copied to each of the output files and truncated or padded as appropriate.

If you do not want any of the records to be truncated, you must ensure that the record length of the workfile is sufficient for the longest record to be sorted.

If your input files are of variable-length and the sort workfile is not, all concept of variable-length is lost.

If your input file is fixed-length and the workfile is variable-length, the record length of the record in the workfile is either the fixed length of the input file or the maximum record length of the workfile, whichever is the smaller.

Mfsort Instructions

Mfsort Error Messages

Example Mfsort Command Line

Example Mfsort Instruction File


Mfsort Instructions

Mfsort is invoked from the operating system command line as follows:

mfsort instructions

The SORT and MERGE instructions are mutually exclusive.

Instruction	Meaning
*	The rest of the line is treated as a comment.
CHAR-EBCDIC	Specifies EBCDIC data. CHAR-EBCDIC must precede all USE, GIVE, SORT, or MERGE instructions.
SIGN-EBCDIC	Specifies that numeric DISPLAY items with included signs are interpreted according to the EBCDIC convention. SIGN-EBCDIC is not used when CHAR-EBCDIC is specified but for data that is otherwise ASCII, such as when the program which created the data was compiled with the SIGN"EBCDIC" Compiler directive. SIGN-EBCDIC must precede all USE, GIVE, SORT, or MERGE instructions.
SORT	Specifies a sort operation and must be followed by a FIELDS statement, and optionally a RECORD statement.
MERGE	Specifies a merge operation and must be followed by a FIELDS statement, and optionally a RECORD statement.
FIELDS	The fields on which the file is to be sorted.
RECORD	The sort workfile record size and format.
USE	Input file(s). You must specify all USE statements before any GIVE statements.
GIVE	Output file(s).
Fields Instruction

Input and Output Files


Mfsort Fields Instruction

Sort fields are specified using the FIELDS instruction:

fields ({start, length, type, order},...)

start	Starting position of the sort field in the record, counting in bytes from 1.

length	Number of bytes in the sort field.

type	Type of data in the sort field.

order	Ordering of output, which can be either of:

A	ascending

D	descending

Up to 16 fields can be specified by repeating the parameter set (start, length, type, and order). The parameter sets must be separated by commas.

Field Types

The field type must be one of the following:

Type	Definition
CH	PIC X DISPLAY
NU	PIC 9 DISPLAY
PD	PIC S9 COMP-3
FI	PIC s9.99 DISPLAY
BI	COMP
C5	COMP-5
C6	COMP-6
C5	S9 COMP-5
CX	COMP-X
LS	PIC S9 LEADING SEPARATE
TS	PIC S9 TRAILING SEPARATE
LI	PIC S9 LEADING INCLUDED
TI	PIC S9 TRAILING INCLUDED (compiled SIGN"EBCDIC")
Example Mfsort Fields instruction.


Mfsort Input and Output Files

The following instructions are used to define each input and output file and should be placed immediately after the associated USE or GIVE instruction.

Instruction	Meaning
RECORD	The record size and format.
ORG	The file organization, one of:
	IX - indexed RL - relative SQ - sequential LS - line sequential
	The default value of ORG is SQ.
KEY	Specifies the key or keys to be used.
If you omit any of the above statements, the last specified values are used. This means that if the input and output files are all of the same type and format, you need only define the first file.

Record Instruction

Key Instruction


Mfsort Record Instruction

The RECORD instruction is optional. It is used to specify the format and length of records both in the sort workfile and, when it follows the associated USE or GIVE instruction, in the input and output files.

The RECORD instruction takes the following form:

record format,rec-len,max-len

format	The record format, one of:

F	Fixed length records of length rec-len

V	Variable length records with a minimum length of rec-len and a maximum length of max-len

If you do not specify a RECORD instruction for the sort workfile, it defaults to fixed record format, with the record size equal to the largest record specified in the USE or GIVE instructions.


Key Instruction

The KEY instruction specifies the key structure for the file and is therefore only required for indexed files.

The format of the KEY instruction is:

key ({start,length,ixkey},...)

start	Starting position of the sort field in the record, counting in bytes from 1.

length	Number of bytes in the sort field.

ixkey	one of:

P	Primary key (must always be defined first)

A	Alternate key

AD	Alternate key with duplicates

C	Component of the last-specified primary or alternate key.

The KEY instruction should be repeated as required to describe the entire key structure. The parameters sets (start, length, ixkey) should be separated by commas.

You must define the keys in order of importance. The primary key first, followed by all its components if it is split, then the first alternate key and all of its components, and so on.

Example of Mfsort Key instruction.


Mfsort Error Messages

001	002	003	004	007	008	009

010	011	012	013	014	015	016	017


001 Instructions are needed

You have executed Mfsort without specifying any instructions.

Resolution

Execute Mfsort supplying instructions on the command line or in an instructions file.


002 SORT or MERGE already specified

You have specified the SORT and/or MERGE instruction more than once.

Resolution

Remove one of these and resubmit your instructions to Mfsort.


003 Failed to open filename

Mfsort could not open the specified file containing your SORT or MERGE instructions. This can be because the file is locked or is not in the location you have specified.

Resolution

Check that the file is in the location specified and resubmit your instructions to Mfsort.


004 Failed to read filename

Mfsort encountered an error while reading the instructions file.

Resolution

Check your instructions file and resubmit it to Mfsort.


007 Invalid or illegal syntax

You have specified syntax that is not recognized by Mfsort.

Resolution

Correct the syntax error in your instructions and resubmit to Mfsort.


008 Unsupported syntax

The syntax that you have specified is not currently supported.

Resolution


009 Unable to get enough memory, aborting

Mfsort is unable to allocate sufficient memory space to carry out the SORT or MERGE instructions.

Resolution

You must obtain more memory in which to execute Mfsort. Refer to your operating system documentation for details of how you can obtain more memory, if this is possible.


010 Too many input files

You have specified more than the maximum number of input files allowed for your SORT/MERGE.

Resolution

You need to recode your instructions reducing the number of input files, and resubmit your instructions to Mfsort.


011 Too many output files specified

You have specified more than the maximum number of output files allowed for your SORT/MERGE.

Resolution

You need to recode your instructions, reducing the number of output files, and resubmit your instructions to Mfsort.


012 All input files must be specified before specifying output files

Resolution


013 Record format not specified

You have omitted to specify a recording format of F or V.

Resolution

Specify a recording format of F or V and resubmit your instructions to Mfsort.


014 SORT failure, file status code:status

The SORT or MERGE has failed. The file status code is displayed.

Resolution

Look up the meaning of the file status code to determine  why the SORT or MERGE has failed.


015 Please specify EBCDIC before other arguments

You must specify EBCDIC as the first instruction to Mfsort.

Resolution

Correct your instructions and resubmit them to Mfsort.


016 SIGN-EBCDIC incompatible with CHAR-EBCDIC

You have specified both SIGN-EBCDIC and CHAR-EBCDIC, which is illegal.

Resolution

Correct your instructions and resubmit them to Mfsort.


017 Prime key not specified first

You must specify the prime key before all other keys.

Resolution

Re-order your key instructions and resubmit them to Mfsort.


Sorting Files
Example Mfsort Command Line

The following example shows the Mfsort command to sort four files:

mfsort use file1 record (v,4,8) use file2 use file3 use file4 give file5 sort fields (1, 1, s5, a, 2, 1, c5, d)


Mfsort Instructions
Example Mfsort Instruction File

The following is an example Mfsort instruction file, called sample.srt:

use file1 record (v,4,8)
use file2
use file3
use file4
give file5
merge fields (1,1,S5,a,2,1,c5,d)

Note that ORG is not needed here as SQ is the default, and that file2 through file5 and the merge workfile use the RECORD format specified for file1.

This instruction file would be used as follows:

mfsort take sample.srt


Example of Mfsort Fields Instruction
Example Mfsort Fields Instruction

The following example sorts the file on a 6-byte alphanumeric field which starts at the second byte of the record, in ascending order, with a secondary ordering on a 4-byte (PIC 9(8))COMP field starting at the tenth byte of the record, in descending order.

mfsort sort fields (2, 6, ch, a, 10, 4, bi, d)


Example of Mfsort Key Instruction
Example Mfsort Key Instruction

The following example defines three keys:

key (4,5,p,10,5,c,20,2,ad,40,2,a,46,10,c)

The first key, the primary key, is split with its first component starting at character position 4 with a length of 5 bytes and its second component starting at character position 10 with a length of 5 bytes.

The second key (alternate key) enables duplicates, starts at character position 20 and is 2 bytes in length.

The third key is a split alternate key, with the first component starting at character position 40 with a length of 2 bytes and the second component starting at character position 46 and with a length of 10 bytes.