Joke of the month:
I just got fired from my job at the keyboard factory. They told me I wasn’t putting in enough shifts.
Tip of the month:
Are you taking advantage of the built-in functions offered in the CL programming language? I was helping a colleague write a CL program recently, and I discovered that he didn’t know about all of the amazing functions IBM has added to CL over the past few years!
Most developers know that CL has always offered %SST (%SUBSTRING), %BIN (%BINARY) and %SWITCH. Many of them also know about %ADDR (%ADDRESS) and %OFS (%OFFSET) if they need to use pointers in CL. But very few people seem to know about the other functions.
Here is a list of most of the CL built-in functions that I use, along with a description of when they were added to the language:
Converts any variable to type(*char) format
Find the first position of string2 that isn’t a character in string1
Find the last position of string2 that isn’t a character in string1
Converts any variable to type(*dec) format.
Converts any variable to type(*int) format.
Converts any variable to type(*uint) format.
Calculates the length of a variable (in characters or digits)
Removes leading blanks from a character string
Removes trailing blanks from a character string
Removes both leading and trailing blanks from a string
Convert text to all lowercase
Convert text to all uppercase
Calculate the size of a variable in bytes
Returns the number of parameters passed into this routine
Scan for a string within this string.
Unfortunately, I don’t have time to write about every parameter of every built-in function (there are even optional parameters that I won’t mention in this article.) So I recommend checking the official documentation for details.
Here are some quick examples of these functions that will give you the gist. They are very useful, I think they are great tools!
Check how many parameters were passed to a CL program:
Convert a numeric field to character:
Check for invalid characters in a character variable:
Determine the length of a variable after trailing blanks are
Convert other data types (*CHAR, *LGL, etc) to numeric:
Get the number of digits in a numeric field, or the number of characters in a character field:
Get the size of a field in terms of the number of bytes of storage it occupies:
Scan for a character or substring in a string. In this case, to help my users when they type IFS paths, I convert the windows-style slahes to the forward slashes used by most other operating systems with a simple loop:
Trim trailing blanks from a character string (without using *TCAT or *BCAT):
Trim leading blanks:
Trim both leading and trailing banks:
Convert a string to lowercase:
Convert a string to uppercase:
As you can see, there are a lot of uses for these functions! They make string handling in CL almost as easy as other languages like RPG or Cobol! Give them a try, they’re definitely going to make your job easier.
Midrange Dynamics Development & Solutions Architect
Scott Klement is an IT professional with a passion for both programming and mentoring. He joined Midrange Dynamics at the beginning of October 2022. He formerly was the Director of Product Development and Support at Profound
Logic and the IT Manager and Senior Programmer at Klement’s Sausage Co., Inc. Scott also serves on the Board of Directors of COMMON, where he represents the Education, Innovation, and Certification teams. He is an IBM Champion for Power Systems.
Subscribe to our newsletter and join us next month to see what is happening in Scott’s Corner. Add a great dad joke to your arsenal and gain an even better IT insight from this recognized industry expert as he continues his quest to educate and support the IBM i community.