Using %BIN to Change the Case of Letters in CL Programs
The EBCDIC representations of lowercase letters differ from those of uppercase letters only in bit 1 (the second bit from the left). If you treat the characters as unsigned binary integers, then the lowercase letters are 64 less than their uppercase counterparts. In other words, you can add 64 to a lowercase letter to capitalize it, and you can subtract 64 from an uppercase letter to make it lowercase.
You can use this method along with the %BIN function to capitalize characters in a CL program. %BIN requires a two- or four-byte argument, so you'll need to move the character to the low-order byte of a two-byte character field which has been initialized to binary zero. Add 64 to the field and then move it back. Refer to 1 for an example.
You can use this method along with the %BIN function to capitalize characters in a CL program. %BIN requires a two- or four-byte argument, so you'll need to move the character to the low-order byte of a two-byte character field which has been initialized to binary zero. Add 64 to the field and then move it back. Refer to Figure 1 for an example.
You may also use this method to capitalize the diacritic characters (e.g., those with accent marks or tildes); but the difference between lowercase and uppercase is 32, not 64.
Using %BIN to Change Case of Letters in CL Pgms
Figure 1 Changing Case in CL
DCL VAR(&BINVAL) TYPE(*CHAR) LEN(2) VALUE(X'0000') DCL VAR(&MESSAGE) TYPE(*CHAR) LEN(80) DCL VAR(&N) TYPE(*DEC) LEN(3) DCL VAR(&ONECHAR) TYPE(*CHAR) LEN(1) ... /* If the &Nth character of &MESSAGE is a lowercase letter, + capitalize it */ CHGVAR VAR(&ONECHAR) VALUE(%SST(&MESSAGE &N 1)) IF COND((&ONECHAR *GE 'a' *AND &ONECHAR *LE 'i') *OR + (&ONECHAR *GE 'j' *AND &ONECHAR *LE 'r') *OR + (&ONECHAR *GE 's' *AND &ONECHAR *LE 'z')) THEN(DO) CHGVAR VAR(%SST(&BINVAL 2 1)) VALUE(&ONECHAR) CHGVAR VAR(%BIN(&BINVAL)) VALUE(%BIN(&BINVAL) + 64) CHGVAR VAR(%SST(&MESSAGE &N 1)) VALUE(%SST(&BINVAL 2 1)) ENDDO





Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:
LATEST COMMENTS
MC Press Online