MainframeMaster

Uppercase/Lowercase Conversion

In DFSORT you can convert letters in a field from lowercase to uppercase or uppercase to lowercase using the TRAN= parameter: TRAN=LTOU (lower to upper) and TRAN=UTOL (upper to lower). You specify the field by position and length in INREC or OUTREC FIELDS=. Only the letters a–z and A–Z are affected; digits, spaces, and other characters stay the same. Using INREC means the sort and INCLUDE/OMIT see the converted value; using OUTREC means only the final output has the new case. This page explains LTOU and UTOL in detail, when to use each, and how to apply them to specific fields or the whole record.

Data Transformation
Progress0 of 0 lessons

TRAN=LTOU (Lower to Upper)

LTOU converts each lowercase letter (a–z) in the specified field to its uppercase equivalent (A–Z). Any character that is not a lowercase letter is left unchanged. So "smith" becomes "SMITH", "O'Brien" becomes "O&BRIEN", and "Room 101" becomes "ROOM 101". This is useful when you need a consistent uppercase key for sorting (so that "Smith" and "smith" sort together) or when the downstream system or report expects uppercase (e.g. mainframe reports that traditionally use uppercase).

text
1
OUTREC FIELDS=(1,20,TRAN=LTOU,21,60)

This converts the first 20 bytes to uppercase and copies bytes 21–80 unchanged. If the first 20 bytes contained "John Smith", the output would have "JOHN SMITH".

TRAN=UTOL (Upper to Lower)

UTOL converts each uppercase letter (A–Z) to its lowercase equivalent (a–z). All other characters are unchanged. So "SMITH" becomes "smith", and "ID: AB12" becomes "id: ab12". Use UTOL when the receiving system expects lowercase—for example, many Unix or Windows applications, or when building email addresses or web content. On the mainframe, data is often stored in uppercase; converting to lowercase in OUTREC before sending a file off the platform is a common use.

text
1
OUTREC FIELDS=(1,40,TRAN=UTOL,41,40)

The first 40 bytes are converted to lowercase; bytes 41–80 are copied as-is. So a record that had "CUSTOMER NAME" in the first 13 bytes would have "customer name" in the output.

What Gets Converted and What Doesn't

LTOU and UTOL are letter-only conversions. The following are unchanged:

  • Digits (0–9)
  • Spaces
  • Punctuation (e.g. comma, period, hyphen, apostrophe)
  • Special characters (e.g. @, #, $) and any non-letter EBCDIC character

So you can safely apply LTOU or UTOL to fields that contain mixed content (names, addresses, IDs with letters and numbers) without corrupting the non-letter characters. If you need to change specific non-letter characters (e.g. replace one character with another), use FINDREP or a custom ALTSEQ table instead.

Using INREC When Sort or Filter Depends on Case

If you sort by a name or key field that has mixed case, the sort order depends on the collating sequence: uppercase and lowercase may not sort together. To get a consistent order, convert the field to one case in INREC and then sort on that converted field. The sort then sees only uppercase (or only lowercase), so "Smith", "SMITH", and "smith" all sort as the same key.

text
1
2
INREC FIELDS=(1,4,5,30,TRAN=LTOU,35,46) SORT FIELDS=(5,30,CH,A)

Here the 26-byte field at 5–30 is uppercased in INREC. The SORT FIELDS= then sorts by that 30-byte field in ascending character order. Every record's name is in uppercase when the sort runs, so the order is consistent. The same idea applies to INCLUDE/OMIT: if you want to keep only records where the name equals "SMITH", uppercasing in INREC lets you compare against C'SMITH' and match regardless of how the name was stored.

Using OUTREC When Only Output Case Matters

When the sort order and filtering are correct with the original data and you only want the written file to have a different case, use OUTREC. For example, you sort by a numeric ID and only need the name field in lowercase in the output for a Unix application. The sort key is the ID; the name is just part of the output layout. In that case, OUTREC FIELDS=(..., name_start, name_len, TRAN=UTOL, ...) is enough.

Converting Multiple Fields to Different Case

You can uppercase one field and lowercase another in the same INREC or OUTREC. List each field with its own (start, length, TRAN=...).

text
1
OUTREC FIELDS=(1,8,9,30,TRAN=LTOU,39,20,TRAN=UTOL,59,22)

Bytes 1–8 are copied, 9–38 are uppercased, 39–58 are lowercased, 59–80 are copied. So you might have an ID, an uppercase name, a lowercase description, and more data—all in one pass.

Explain It Like I'm Five

Imagine you have a line of letters. Some are big (uppercase) and some are small (lowercase). "Lower to upper" means we make every small letter big: a→A, b→B, and so on. "Upper to lower" means we make every big letter small: A→a, B→b. Numbers and spaces we don't touch. So "abc 123" with lower-to-upper becomes "ABC 123". We can do this to the whole line or just part of it. If we do it before the sort (INREC), the sort sees the new letters; if we do it only when writing the file (OUTREC), the sort still saw the old letters.

Exercises

  1. Write OUTREC to convert bytes 11–50 to uppercase and leave the rest of an 80-byte record unchanged.
  2. You need to INCLUDE only records where a 20-byte name at position 5 equals "JONES" (any case). Should you use INREC or OUTREC for LTOU? Why?
  3. What output do you get from applying UTOL to the string "ID: AB12"?

Quiz

Test Your Knowledge

1. What does TRAN=LTOU do in DFSORT?

  • Sorts by length
  • Translates lowercase letters (a-z) in the specified field to uppercase (A-Z); other characters are unchanged
  • Converts to numeric
  • Merges fields

2. What does TRAN=UTOL do?

  • Upper to lower: converts uppercase letters (A-Z) to lowercase (a-z) in the specified field
  • Unicode only
  • Only for numeric fields
  • Sorts descending

3. Do LTOU and UTOL affect digits and spaces?

  • Yes, they convert everything
  • No—only the letters a-z and A-Z are converted; digits (0-9), spaces, and other characters are left unchanged
  • Only in INREC
  • Only in OUTREC

4. When should you use INREC vs OUTREC for LTOU/UTOL?

  • Always OUTREC
  • Use INREC when the converted value must be used for sorting or INCLUDE/OMIT—the sort and filter see the converted data. Use OUTREC when you only need the case change in the final output
  • Always INREC
  • Only OUTREC for reports

5. Can you convert one field to uppercase and another to lowercase in the same step?

  • No
  • Yes—in FIELDS= list each field with its own TRAN= option, e.g. (1,20,TRAN=LTOU,21,30,TRAN=UTOL,51,30)
  • Only with two SORT steps
  • Only in OUTFIL