I don't generally use regular expressions, as I generally don't know when they would be of use, and of course they aren't directly available in COBOL. But I did recently find a decent use of Oracle database regular expressions.
select all ctd.merchant_name_address , th.system_date as system_date , case when ctd.merchant_name_address like 'CVS%' then 'CVS' end||' #'||cast(to_char(to_number(regexp_substr( ctd.merchant_name_address,'[0-9]+')),'FM00000') as char(5)) as normalized_merch_id , th.transaction_amt The use case was to turn any number of formats under which we see the "merchant name" for CVS/pharmacy stores in to something more 'normalized' so that we could see activity at certain CVS/pharmacy stores. Each store seems to have more than one format, and the formats are not consistent across stores, i.e.: CVS 00007 CVSPHARMACY #0007 Q03 CVS #2372 CVS 02372 CVS PHARMACY #5026 Q03 CVS PHARMACY #193 The Oracle regexp_substr function used above allowed me to return for each of those formats a simple 5 digit (with leading zeroes, when necessary) store number for each, based on the first set of consecutive digits in the merchant_name_address column. Once I had this it was easy to place transactions in the bucket for the proper store number. Had this been a COBOL search of a text file I would have had to code this relatively simple regular expression 'by hand' (searching the text for the first set of numeric characters and then using a COBOL MOVE to add the leading zeroes. Would I use regex instead of more readily available? I honestly don't know. But I can imagine seeing something like this added to COBOL: MOVE FUNCTION REGEX(MY-FIELD,'[0-9]+') TO MY-NORMALIZED-FIELD or IF FUNCTION REGEX(MY-FIELD),'[0-9]+') = '987' ... But until I run in to some real life use cases where the above would be useful I won't seriously suggest it. I would be interested to hear some real life COBOL business application cases where regex would have been useful. Then we can have people suggest "better alternatives". :-) >________________________________ > From: Bernd Oppolzer <[email protected]> >To: [email protected] >Sent: Wednesday, March 26, 2014 7:38 AM >Subject: Re: Another Article On Lagging Mainframe Skills > > >I use regular expressions very rarely; in fact, for me it is >mainly a grammar which I use as a base for my scanner >generator which in turn produces scanner functions that >I use in various tools, be it an XML parser or a database >load/unload tool or a PL/1 source code analyzer (all those >tools are written in ANSI C and work on all platforms, >including Windows, OS/2, Unix, and z/Arch). > >To do analysis of text files (for example trace files from >test runs of our applications etc.), I normally write REXX functions >that filter those trace files and get the relevant informations out >of it using REXX PARSE and write nice reports. Works best for me, >this is the fastest way to do it. And, guess what, the REXX procedures >run on WINDOWS machines !!! because its OO REXX, and I >download the trace files from the z/OS mainframe, just because >it is much faster this way ... so I'm not afraid to use other platforms, >although >I like z/Arch most. > >Inside the editor which I use most of the times, I have a search function >that allows me to do combined searches, that is, look for patterns >and combine the patterns with AND, OR and NOT, and this is sufficient >for most daily work ... if not, I write an editor macro (in REXX, BTW, >although, again, the editor is NOT running on the mainframe). > >That's my point: no matter what tools you use: the key is that you >master your tools, and that you are fast and efficient in using them. >That is what you have to achieve, no matter what your platform is ... > >That said: for me regular expressions on z/OS are not very important, >besided from the ones that I use in my own scanner generator >(but I didn't port the scanner generator to z/OS yet - but it should >not be a problem. because it is written in C). Especially, >regular expressions on z/OS IMHO don't help in "modernizing" >the platform - I've seen a lot of "modernizing" in the last years on >the z/Arch platform. Instruction set, PL/1 language, DB2 ... of course, >some areas still look old (file system, JCL). > >Another important point for me: using the C language, the z/Arch >platform is >just another platform supporting C. Not more or less modern >than others; simply no difference. > >Kind regards > >Bernd > > > > > > >Am 26.03.2014 13:24, schrieb Tony Thigpen: >> Just to be clear, I really do understand, and respect, your feelings. >> It's a tool you would like to continue using because you are familiar >> with it. >> My opinion is just that, my opinion. And, in my shops I can enforce my >> opinion. :-) >> I was not criticizing the port, just tying to explain why it might not >> be of interest to many mainframe programmers. And why nobody bothered to >> download it. By saying why I was not interested in it. >> >> Now, as to COBOL, we normally deal with non-text based numbers. >> Everything in the file is stored packed or binary, not as text. Once it >> is passed the "input program", the only need is to convert it back to >> text for reports. And we have simple PIC clauses to hand that conversion. >> As to the "input program", these have traditionally worked with input >> fields that do not have all the dashes, commas, and such. We started >> with keypunches (where the special characters were removed by the >> keypunch operator). We then moved to BMS screens (for CICS) where CICS >> had a built-in de-edit function. (Of course many shops wrote their own.) >> But, even then, we normally expected the return value to be just digits. >> Even as we move from CICS to Web, it's still under CICS with the >> existing tools already in place. >> We have been working this way for 30+ years. Regular expressions is >> relatively young. >> >> Do we need regular expressions in COBOL? I don't think so. Can you, and >> others, continue to try to evangelize about regular expressions? Yes you >> can. Maybe, some day, I will change my mind. I just doubt it. :-) >> >> Maybe you should start a thread: Why COBOL needs Regular Expressions. >> >> Tony Thigpen >> > > >
