Published at 1/6/2025

Ever heard of Regular Expressions?

Back in 1999, in my days with PHP 3.0, I was introduced to something called Regular Expressions. Without getting into a class on what it is and how to used, it is a way to tell the computer to match a pattern, very used with "find" and "find and replace" operations.

A quick read on Wikipedia if you never heard of it:

https://en.wikipedia.org/wiki/Regular_expression

There are some cases where the pattern that we want to use is very complicated to build by using if/else conditions or string comparison functions. To illustrate, if you want to identify if an e-mail address is valid, it is more than just check if character @ is somewhere in the string. Everything about e-mail addresses and their format is in RFC6854:

https://datatracker.ietf.org/doc/html/rfc6854

If using Regular Expressions, we can match addresses compliant with the RFC by using something like this (precluding comments):

([!#-'*+/-9=?A-Z^-~-]+(\.[!#-'*+/-9=?A-Z^-~-]+)*|"([]!#-[^-~ \t]|(\\[\t -~]))+")@([!#-'*+/-9=?A-Z^-~-]+(\.[!#-'*+/-9=?A-Z^-~-]+)*|\[[\t -Z^-~]*])

 

This would be much more complicated if we were to do that by breaking down the string and applying all the many checks. Regular Expressions look scary at first, just have some patience and read it piece by piece.

 

Use case to illustrate

To demonstrate how this can be applied on Mainframes, I have this simple script that I use from time to time to do a quick check on the subsystem instances that I have to provide support. IMS for example, when someone reports a problem using their business perspective, I have to "translate" that to error messages or something that point me in the right direction. End Users do not know the software, most of the time I do not understand all the internals of the tools they use to correlate the symptom with actual errors or software defects. With that, I like to start by looking at the IMS Control Region in SDSF (or similar product) for any easy to spot errors, but there are systems with so much volume that the system output can be millions of lines.

For these cases, I have this Regular Expression script that finds only "abnormal" messages.

If you are not familiar with IMS, the messages have a prefix of DFS*, DBRC uses DSP*, Common Queue Server uses CQS*, IMS Connect uses HWS*, etc. Db2 for z/OS uses DSN* as the prefix and CICS uses DFH*. There are features and separate tools for these products that have their own prefixes as well.

After the prefix, we usually have 3 to 4 digits for the message code. Some products have 5 or more. And then we have a suffix for the level of the alert, A, E or W in most cases.

An example:

https://www.ibm.com/docs/en/ims/15.4.0?topic=dfs600i-dfs554a

 

DFS554A jobname.region.stepname. prog PSBname(x) transaction-code
sys-completion-code user-completion-code PSB SMB
LTERM:|LUNAME:|RTKN=token
REASON=reason originating terminal

 

Matching these message codes using Regular Expressions is much easier than using regular programming techniques, we know what we are looking for in general terms, just have to write it down.

  1. Any word that starts with DFS.
  2. Followed by 3 or 4 digits (numbers only).
  3. Followed by either letter A, W or E.

All of the above should evaluate to true. We can add other prefixes as well and have it all in one check. Here is the expression that I use for IMS:

(CQS|CSL|DFS|DSP|DXR|FRP|HWS.)[0-9]{3,4}[AWE]

 

IMS Connect (HWS messages), may have a fourth letter in the prefix. The others are much more straightforward. If I run that against the JESMSGLG of the IMS Control Region, or the z/OS System Log, it returns something like this:

 

 1 DFS0226A
 1 DFS225A 
 1 DFS227A 
 1 DFS3374W
50 DFS554A 
 1 DFS810A 

 

That is something I can work with and start looking for potential problems.

 

How to use Regular Expressions in z/OS?

The answer to this depends. It depends on your own system. DFSORT has support for regular expressions (similar products do as well) and I think this is available everywhere.

Unix on z/OS also has support for Regular Expressions in many of its functions, grep for example.

C/C++ and Java programs have access to Regular Expressions.

It is also available in ISPF (if you have it properly configured to have access to the C/C++ runtimes).

For the example I used above, I run it in Unix using grep and then I massage the output a little bit to count and sort the messages. The complete code is in my Github account. In the example I have two JCL steps, one to use the SDSF program to find the IMS Control Region and save the JESMSGLG to a temporary dataset and then a BPXBATCH step to run the RegExp pattern to find the messages.

If you look at the code:

(CQS|CSL|DFS|DSP|DXR|FRP|HWS.)[0-9]{3,4}[AWE]

 

Last part that says [AWE] is the one that finds messages ending with either A, W or E, for abnormal messages. If you would like, this can be replaced by [AWEI ], that would be letters A, W, E, I and a blank space, which should return a list of all messages that were found. It is a way to get a good grasp on what what is happening to your system.

 

https://github.com/bimonti/JCL/blob/master/REGEXPR.JCL

Share on social media

Facebook share buttonReddit share buttonThreads share button