Constants in DFSORT are literal values you put into a record in INREC or OUTREC that do not come from the input. You specify them with C'...' (character constants) and X'...' (hexadecimal constants). Each constant is a fixed string of bytes: spaces, commas, record type codes, or any EBCDIC (or hex) value. They are essential for inserting delimiters, padding to fixed lengths, adding prefixes like 'H' or 'D', and building a uniform record layout. This page explains the syntax of C and X constants, how length is determined, common EBCDIC values (space, zero, letters), when to use character vs hex, and how constants interact with (position,length) copies in the same BUILD= or FIELDS= list. The same constant syntax is used in both INREC and OUTREC.
A character constant is written as C'literal'. The characters between the single quotes are taken as-is and encoded in EBCDIC (Extended Binary Coded Decimal Interchange Code), the standard character set on IBM mainframes. Each character produces one byte in the output. So the length of the constant is the number of characters between the quotes.
You can use any character that exists in EBCDIC: letters, digits, spaces, and common symbols. The quotes delimit the literal; they are not part of the output. To include a single-quote character inside the literal, refer to your DFSORT manual—often it is doubled (e.g. C'O''Brien') or escaped.
A hexadecimal constant is written as X'hexdigits'. Each pair of hex digits (0–9, A–F) forms one byte. So the length of the constant is half the number of hex digits. You must have an even number of digits.
Hex constants are useful when you need a non-printable character (e.g. X'0D' for carriage return in some contexts) or when you want to be explicit about the byte value regardless of character set. They are also handy when the character is hard to type or when your editor might change the encoding of a C'...' literal.
| Hex | Character equivalent | Meaning |
|---|---|---|
| X'40' | C' ' | Space |
| X'F0' | C'0' | Numeric zero (digit 0) |
| X'C1' | C'A' | Letter A |
| X'00' | N/A | Null byte |
| X'0D' | N/A | Carriage return (context-dependent) |
The number of bytes a constant adds to the output is: for C'...', the number of characters between the quotes; for X'...', the number of hex digit pairs. So C'HI' adds 2 bytes; X'C8C9' adds 2 bytes (and in EBCDIC is the same as C'HI'). The total record length from INREC or OUTREC is the sum of all (position,length) lengths plus the lengths of all constants.
In INREC or OUTREC FIELDS= or BUILD=, constants can appear in any order with (position,length) items: at the start, between segments, or at the end. Example:
12INREC BUILD=(C'HDR',1,80) OUTREC BUILD=(1,10,C',',11,20,C'|',31,50)
INREC: every record starts with the three bytes H, D, R then the 80-byte input — 83 bytes. OUTREC: 10 bytes, comma, 20 bytes, pipe, 50 bytes — 81 bytes. So both INREC and OUTREC support the same constant syntax.
Use C'...' when the literal is readable text: spaces, commas, labels like 'D' or 'HDR'. It is easier to read and maintain. Use X'...' when: (1) you need a non-printable byte (e.g. null, control characters); (2) you want to be certain of the exact EBCDIC value (e.g. X'40' for space); (3) the character might be ambiguous in your editor (e.g. different kinds of spaces). For most delimiters and padding, C' ' or C', ' is sufficient; for low-level or binary needs, X is safer.
On z/OS and mainframe DFSORT, constants are in EBCDIC. So C'A' is 0xC1, and the space is 0x40. If you are used to ASCII (where space is 0x20 and A is 0x41), remember that the same character can have a different hex value in EBCDIC. When you write X'...', use EBCDIC values so the output is correct on the mainframe.
C'' (empty character constant) may or may not be valid depending on the product; typically you need at least one character. X'' (empty hex) would be zero bytes and is usually not useful. For a single space, C' ' or X'40' is standard. For a single zero digit, C'0' or X'F0'.
When you are building a new row of boxes, sometimes you want to put in something that doesn't come from the old row—like a comma between two numbers or a label at the front that says "Detail." Constants are those fixed things you write in: the comma, the space, or the letter D. The computer has two ways to write them: C'...' is like writing the actual letter or comma (so C', ' means comma and space). X'...' is like giving the secret code number for each letter (so the computer knows exactly which byte to put). Both put the same kind of thing in the row—fixed data that you chose, not copied from the old row.
1. What is the length of C'HELLO' in the output record?
2. What is the length of X'C1C2C3' in the output record?
3. In EBCDIC, which hex value represents a space?
4. Can you use a constant as the only item in INREC BUILD?
5. Why might you use X'...' instead of C'...' for a space?