Skip to main content

This article provides you with a way to verify UK postcodes using the LIKE verb.

Problem:

Because of the construct of UK postcodes, it is not a simple matter to verify them using traditional coding methods, but the LIKE verb does the job easily.

Resolution:

The attached sample program “postcode.cbl” contains the required code.

Note that it is not possible currently to just specify the upper-case characters and use CASE-INSENSITIVE; this will cause an Assertion Failure on all versions from 12.02 back. This is why the sample program allows both upper- and lower-case characters in the condition.

For better performance, the declaration of REGEX is a level-number 78 constant-name declaration instead of a level-number 01 data-name declaration. The regular expression is then compiled at compile-time instead of each time it is used at run-time, as would be the case with an 01 declaration.

Old KB# 14338