In DFSORT, FI stands for signed fixed-point (signed binary). When you specify FI, DFSORT treats the sort key as a signed binary integer stored in 2, 4, or 8 bytes—the same storage sizes as BI (halfword, fullword, doubleword), but the value is interpreted as signed. The high-order bit is the sign bit: negative numbers are in two's complement form. So with FI, -5 sorts before 0, and 0 sorts before 5 in ascending order. BI is unsigned: the same bit pattern that represents -1 in signed form would be interpreted as a very large positive number with BI, so it would sort after all positive values. FI is the right format for COBOL S9(n) COMP (signed COMP) and any key that can hold negative binary integers. This page explains FI in detail: how it differs from BI, when to use it, allowed lengths, and how to avoid wrong order with signed binary keys.
FI tells DFSORT: "this field is a signed binary integer." The program reads 2, 4, or 8 bytes (same as BI), but instead of treating the value as unsigned (0 to 2^n - 1), it interprets the high-order bit as the sign and the value in two's complement form. So the same 4-byte pattern that means 4,294,967,295 in BI means -1 in FI. In ascending sort, smaller (more negative) numbers come first: -100, -1, 0, 1, 100. In descending sort, larger numbers come first: 100, 1, 0, -1, -100. This is the correct numeric order for signed integers. COBOL PIC S9(n) COMP (or COMP-4) stores signed binary in exactly this way, so FI is the format to use when the sort key is a signed COMP field.
FI uses the same lengths as BI:
| Length (bytes) | Common name | Signed value range (typical) | COBOL example |
|---|---|---|---|
| 2 | Halfword | -32,768 to 32,767 | PIC S9(4) COMP |
| 4 | Fullword | -2,147,483,648 to 2,147,483,647 | PIC S9(9) COMP |
| 8 | Doubleword | ± about 9.2e18 | PIC S9(18) COMP |
The length in SORT FIELDS is in bytes. For PIC S9(9) COMP you specify 4, not 9.
Use FI in SORT FIELDS like this:
1SORT FIELDS=(start,length,FI,direction)
Example: sort by a 4-byte signed binary at position 15, ascending (negatives first):
1SORT FIELDS=(15,4,FI,A)
Example: primary key character at 1–10, secondary key signed binary at 11–14, both ascending:
1SORT FIELDS=(1,10,CH,A,11,4,FI,A)
BI treats the key as unsigned: every bit pattern is a non-negative integer. So the 4-byte value that represents -1 in two's complement (X'FFFFFFFF') is interpreted as 4,294,967,295 with BI. In an ascending sort with BI, that "-1" would come after 0, 1, 2, … and after 4,294,967,294—i.e. at the end. FI treats the same 4 bytes as -1, so in ascending sort it comes before 0 and all positive numbers. So:
If you use BI on a signed field, negative values will sort in the wrong place (as very large positives). If you use FI on an unsigned field that never has the sign bit set, the order is the same as BI; but if any value could be misinterpreted (e.g. a value > 2^31 in a 4-byte field stored as unsigned), FI would treat it as negative. So match the format to the actual data: signed → FI, unsigned → BI.
| Use case | Reason |
|---|---|
| COBOL S9(n) COMP or COMP-4 | Storage is signed binary; length 2, 4, or 8 bytes. |
| Deltas, offsets, or quantities that can be negative | FI compares signed value so negatives order correctly. |
| Any key stored as signed halfword/fullword/doubleword | FI is the format for signed binary keys. |
Using CH on a signed binary field compares raw bytes in EBCDIC order—no numeric meaning. Using PD or ZD expects decimal digit layout, which binary does not have. Using BI on a signed field misorders negatives. So for signed binary integer keys, FI is the correct choice. Product documentation may use terms like "signed binary" or "fixed-point"; FI is the usual DFSORT keyword for this format.
Wherever DFSORT needs to interpret a signed binary field—in INCLUDE/OMIT comparisons or in INREC/OUTREC—specify FI so that numeric tests (e.g. less than zero, greater than 100) use the signed value. Using BI would treat negative values as large positives and comparisons would be wrong.
Some numbers can be minus (like -5) or plus (like 5). The computer stores them in a special way: the first bit can mean "minus." FI is the rule that says: "this part of the record is a number that can be minus or plus." So when we sort, we put the smallest first: minus 10, then minus 1, then zero, then 1, then 10. If we used the "no minus" rule (BI), the computer would think minus 1 is a huge positive number and put it at the end. So we use FI when the key can be negative, like many counts or differences in mainframe files.
1. What does FI mean in DFSORT?
2. When should you use FI instead of BI?
3. Your COBOL record has PIC S9(9) COMP at position 20 (signed fullword). What SORT FIELDS do you use for ascending numeric order?
4. Which lengths are valid for FI in DFSORT?
5. What sort order do you get for -100, 0, 100 with FI,A?