MainframeMaster

FI (Signed Fixed-Point) Format

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.

Data Types & Formats
Progress0 of 0 lessons

What FI Means

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.

Allowed Lengths

FI uses the same lengths as BI:

FI field lengths (signed)
Length (bytes)Common nameSigned value range (typical)COBOL example
2Halfword-32,768 to 32,767PIC S9(4) COMP
4Fullword-2,147,483,648 to 2,147,483,647PIC S9(9) COMP
8Doubleword± about 9.2e18PIC S9(18) COMP

The length in SORT FIELDS is in bytes. For PIC S9(9) COMP you specify 4, not 9.

Syntax: SORT FIELDS with FI

Use FI in SORT FIELDS like this:

text
1
SORT FIELDS=(start,length,FI,direction)
  • start — Starting position of the signed binary field (1-based).
  • length — 2, 4, or 8 (bytes). Must match the actual storage size.
  • FI — Format: signed fixed-point (signed binary).
  • direction — A for ascending, D for descending.

Example: sort by a 4-byte signed binary at position 15, ascending (negatives first):

text
1
SORT FIELDS=(15,4,FI,A)

Example: primary key character at 1–10, secondary key signed binary at 11–14, both ascending:

text
1
SORT FIELDS=(1,10,CH,A,11,4,FI,A)

FI vs BI: Signed vs Unsigned

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 your field is unsigned (only zero and positive values)—e.g. PIC 9(n) COMP—use BI.
  • If your field is signed (can be negative)—e.g. PIC S9(n) COMP—use FI so that -5, -1, 0, 1, 5 sort in that order (ascending).

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.

When to Use FI

Use FI when the field is signed binary integer
Use caseReason
COBOL S9(n) COMP or COMP-4Storage is signed binary; length 2, 4, or 8 bytes.
Deltas, offsets, or quantities that can be negativeFI compares signed value so negatives order correctly.
Any key stored as signed halfword/fullword/doublewordFI is the format for signed binary keys.

When Not to Use FI

  • Unsigned binary (PIC 9(n) COMP) — Use BI. FI is for signed; using FI on unsigned is usually fine but BI is clearer.
  • Packed decimal (COMP-3) — Use PD. Not binary.
  • Zoned decimal (DISPLAY) — Use ZD. Not binary.
  • Character data — Use CH.

Comparing FI to Other Formats

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.

FI in INCLUDE, OMIT, and Build Statements

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.

Explain It Like I'm Five

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.

Exercises

  1. A record has PIC S9(4) COMP at position 8 (2 bytes) and PIC S9(9) COMP at position 20 (4 bytes). Write SORT FIELDS for ascending on both keys using FI.
  2. Why does using BI instead of FI for a PIC S9(9) COMP field cause negative values to sort in the wrong place? Explain in terms of how the bit pattern for -1 is interpreted.
  3. Your copybook has both PIC 9(4) COMP (unsigned) and PIC S9(4) COMP (signed) at different positions. Which format (BI or FI) do you use for each in SORT FIELDS?
  4. What is the sort order of -100, 0, 100, -1, 1 with SORT FIELDS=(1,4,FI,A)? With SORT FIELDS=(1,4,FI,D)?

Quiz

Test Your Knowledge

1. What does FI mean in DFSORT?

  • Floating integer
  • Signed fixed-point (signed binary): the field is interpreted as a signed binary integer and compared by numeric value
  • Field index
  • Format input

2. When should you use FI instead of BI?

  • Always use FI; BI is deprecated
  • When the binary field can hold negative values; FI interprets the sign bit so negatives sort correctly
  • Only for 8-byte fields
  • Only when OPTION EQUALS is used

3. Your COBOL record has PIC S9(9) COMP at position 20 (signed fullword). What SORT FIELDS do you use for ascending numeric order?

  • SORT FIELDS=(20,9,FI,A)
  • SORT FIELDS=(20,4,FI,A)
  • SORT FIELDS=(20,4,BI,A)
  • SORT FIELDS=(20,9,PD,A)

4. Which lengths are valid for FI in DFSORT?

  • 1, 2, 3, or 4 bytes only
  • 2, 4, or 8 bytes (same as BI: halfword, fullword, doubleword)
  • Any length
  • Only 4 bytes

5. What sort order do you get for -100, 0, 100 with FI,A?

  • 0, -100, 100
  • -100, 0, 100 (ascending numeric: smallest first)
  • 100, 0, -100
  • 0, 100, -100