Translate fields to all uppercase (to sort and scan correctly)

To translate text to all uppercase you can use a couple of methods that have been around for years and are simple and effective.

The first method requires either creating or changing the definition of a logical file. Add a field to the logical file (DDS or DDL) to translate descriptions to all uppercase. Make sure you compile the logical over the proper library list.

A ZZPROD
A ZZDESC
A ZZCAPS I RENAME(ZZDESC)
A TRNTBL(QSYSTRNTBL)

The new field is also added as a key field:
A K ZZCAPS
A K ZZPROD

In this example, ZZPROD is the product ID, ZZDESC is an alpha description field, and ZZCAPS is the newly introduced field that uses a system translation table.  The new field is added to the key so that only uppercase is used for sorting and scanning.

~~~~~~~~~~~~~~~~~~~

A second method will convert a field to uppercase within your RPGLE program. The translation is based on two constants fields defined here as 'lower' and 'UPPER'.

D lower     c              'abcdefghijklmnopqrstuvwxyz'
D UPPER     c              'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

Then using the XLATE opcode or %XLATE built-in function does the trick.

/free
   stringfield = %xlate(stringfield:lower:UPPER)
/end-free

The following statement will work in traditional RPG :

C   lower:UPPER    xlate      DESC        TEST

Make it a practice to use the newer BIFs (built-in functions) whenever possible:

C                  Eval       pos  = 0
C                  Eval       TEST = %xlate(lower:UPPER:DESC)
C                  Eval       pos  = %scan('FIND THIS':TEST)

If found numeric field pos will be a position so it won't be equal to zero.  If you are scanning a translated (to UPPER or lower) case field it is best to use a temporary field so that the original field is not changed.