Uppercase

We can use INSPECT or UPPERCASE or LOWERCASE COBOL function to convert the case of alphanumeric, alphabetic, or national strings. Translation features of INREC, OUTREC and OUTFIL make it easy to change the case of characters in your fields.

INSPECT verb in COBOL is very useful and it is used to do the following functionalities

  •  Count a particular Character in a string
  •  Convert Lower case to upper case
  •  Replace a particular Character with other character in a string
  •  Replace a set of characters with another set of characters

INSPECT FUNCTION FOR UPPERCASE OR LOWERCASE CONVERSION

01 WS-CHAR-CASE.
     05 WS-UPPER-CASE PIC X(26) VALUE "ABCD … Z"
     05 WS-LOWER-CASE PIC X(26) VALUE ' abcd… z'
 
INSPECT WR-IN-STRNG
        CONVERTING WW-LOWER-CASE to WS-UPPER-CASE

LOWER-CASE TO UPPER-CASE FOR LOWERCASE TO UPPERCASE CONVERSION

MOVE FUNCTION UPPER-CASE(STATE-IN) TO STATE-FOR-FILE.

UPPER-CASE TO LOWER-CASE FOR UPPERCASE TO LOWERCASE CONVERSION

MOVE FUNCTION LOWER-CASE(STATE-IN) TO STATE-FOR-FILE.

DB2 UPPER() FUNCTION

The UPPER() function accepts a string and returns a new string in which all characters in the original string are converted to uppercase.

UPPER(expression)

Expression must evaluate to a character string or a value that can be implicitly converted to a character string. 

UPPER() function is useful for case-insensitive searches.

SELECT UPPER('This is Test') FROM sysibm.sysdummy1;

RESULT - THIS IS TEST

LTOU AND UTOL FOR UPPERCASE OR LOWERCASE CONVERSION

Now let’s do this conversion using SORT JCL. Translation features of INREC, OUTREC and OUTFIL make it easy to change the case of characters in your fields.

The TRAN=LTOU operand can be used to change lower-case EBCDIC letters (a-z) to upper-case EBCDIC letters (A-Z) anywhere in a field. The TRAN=UTOL operand can be used to change upper-case EBCDIC letters to lower-case EBCDIC letters anywhere in a field.

Here’s how you could change lowercase letters to uppercase letters in a 50-byte character field starting at position 25 and in a 20-byte character field starting in position 200, in an FB data set with an LRECL of 500:

 OUTREC OVERLAY=(25:25,50,TRAN=LTOU,250:250,20,TRAN=LTOU)

You can convert the case in the entire record. For example, here’s how you could change uppercase to lowercase in the records of an FB data set with an LRECL of 200:

 OUTREC BUILD=(1,200,TRAN=UTOL)

And here’s how you could change uppercase to lowercase in the records of a VB data set with any LRECL:

 OUTREC BUILD=(1,4,5,TRAN=UTOL)

Example

FIRST NAME LAST NAME
WILLIAM    BAYLESS 
RAUL       CAUDILLO 
JOKHI      DINSHAW 
ROBERT     MURRAY 
LORI       RASMUSSEN

If you wanted to display these names with an initial uppercase letter and subsequent lower case letters, you could use the following OUTREC statement:

OUTREC FIELDS=(91,1,92,14,TRAN=UTOL,X,76,1,77,14,TRAN=UTOL)
Result
William Bayless 
Raul    Caudillo 
Jokhi   Dinshaw 
Robert  Murray 
Lori    Rasmussen

Read JCL blogs : Click Here SYNCSORT Manual : Click Here

Scroll to Top