MainframeMaster

Constants

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.

INREC Processing
Progress0 of 0 lessons

Character Constants: C'...'

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.

  • C' ' — One space. Length = 1. Often used as a delimiter or filler.
  • C'ABC' — Three bytes: A, B, C in EBCDIC. Length = 3.
  • C', ' — Comma and space. Length = 2.
  • C'0' — One character, the digit zero. In EBCDIC this is 0xF0. Length = 1.
  • C'00000' — Five zeros. Length = 5. Useful for zero-padding numeric-looking fields.

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.

Hexadecimal Constants: X'...'

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.

  • X'40' — One byte: decimal 64. In EBCDIC this is the space character. So X'40' is the same as C' '.
  • X'C1C2C3' — Three bytes: C1, C2, C3 in hex. In EBCDIC these are the letters A, B, C. So X'C1C2C3' equals C'ABC' in content.
  • X'F0F0F0' — Three bytes: EBCDIC for the digit 0, three times. Same as C'000'.
  • X'00' — One null byte. Useful for binary fields or padding with zero value.
  • X'404040' — Three spaces. Same as C' '.

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.

Common EBCDIC constants
HexCharacter equivalentMeaning
X'40'C' 'Space
X'F0'C'0'Numeric zero (digit 0)
X'C1'C'A'Letter A
X'00'N/ANull byte
X'0D'N/ACarriage return (context-dependent)

Length Rules

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.

Where Constants Can Appear

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:

text
1
2
INREC 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.

When to Use C vs X

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.

EBCDIC vs ASCII

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.

Empty and Single-Byte Constants

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'.

Explain It Like I'm Five

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.

Exercises

  1. How many bytes does C'A,B,C' add to the output? What about X'C16BC3'? (C1=A, 6B=comma, C3=C in EBCDIC.)
  2. Write a constant that inserts exactly 4 spaces using C and using X (EBCDIC).
  3. You want every record to start with the byte value 0x00 (null). Can you use C'...'? What do you use instead?
  4. INREC BUILD=(1,5,C'X',6,10). What is the total output length and what is at output position 6?

Quiz

Test Your Knowledge

1. What is the length of C'HELLO' in the output record?

  • 1 byte
  • 5 bytes
  • Depends on format
  • 0 bytes

2. What is the length of X'C1C2C3' in the output record?

  • 6 bytes
  • 3 bytes
  • 1 byte
  • Same as C'ABC'

3. In EBCDIC, which hex value represents a space?

  • X'20'
  • X'40'
  • X'00'
  • X'FF'

4. Can you use a constant as the only item in INREC BUILD?

  • No
  • Yes—e.g. BUILD=(C'X') produces a 1-byte record of X for every input record
  • Only with FIELDS=
  • Only in OUTREC

5. Why might you use X'...' instead of C'...' for a space?

  • X is faster
  • When you need to be sure of the exact byte value (e.g. EBCDIC 0x40) or when the character is non-printable
  • C' ' is invalid
  • Only for numbers