[SOLVED] Best way to remove alpha characters from alphanumeric fields
I have a field (A22 format) which can contain a series of either numbers or letters. What is the best method to remove all occurances of alpha characters from the field so that only numbers are remaining? The letters may occur in any positions within the field: (ex - 123AA or AA123 or 1A2A3).
Thanks in advance.This message has been edited. Last edited by: Kerry,
Linux x86 Apache Excel, CSV, HTML, PDF
November 09, 2012, 01:25 PM
Francis Mariani
Take a look at this post, SQL Code conversion in Focus for an example of a DEFINE FUNCTION that does what you require.
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
November 09, 2012, 01:28 PM
kadkins
Thx Francis. I was looking for a method similar to using regular expressions within FOCUS. I'll check it out.
Linux x86 Apache Excel, CSV, HTML, PDF
November 09, 2012, 02:00 PM
Francis Mariani
As far as I know, there are no regular expressions, but there are many ways to do something.
Here's another way, using three built-in functions, PATTERN, STRREP and EDIT. Note this will only work if the column contains only alpha or numeric characters - PATTERN leaves special characters untouched.
I've left out the NOPRINT for JPATTERN1 and JPATTERN2 so you can see the transformations. First I use PATTERN to determine where the alpha and numeric characters are. Then I use STRREP to replace the 'A' (for alpha) by '$'. Then I use EDIT to extract the numeric characters ('$' is a mask character which excludes the alpha characters). Pretty nifty until someone comes up with a better idea.
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
November 11, 2012, 03:45 PM
Waz
Awesone solution Francis.
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
November 12, 2012, 09:27 AM
kadkins
Agreed. Awesome solution. Thanks!
Linux x86 Apache Excel, CSV, HTML, PDF
November 12, 2012, 05:17 PM
Doug
Ditto Clever use of WebFOCUS! and outside the box.
November 12, 2012, 05:26 PM
Waz
I think this is an excellent example of WebFOCUS capabilities.
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
November 12, 2012, 06:33 PM
Francis Mariani
I'm happy that my brain is still FOCUSing after all these years.
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server