Just for the heck of it, I wrote a "quick and dirty" UDF code that
(*maybe*) could suit your requirements. You can find it here:
Sorry about the "lack of elegance" of the code. It is a quick adaptation of
an old routine I wrote a long time ago.
IBM Certified Systems Expert — eServer i5 iSeries