Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] String replacing

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] String replacing
 Login/Join
 
Virtuoso
posted
I have a string in my data that I need to cut the head off if its start matches the regular expression: /^[Qq][Rr][1-5][:;]\s*/
Meaning, if the string starts with 'QR' (regardless of case), followed by a semi-colon or a colon and any following white-space, I need to cut that part off it.

I've seen some approaches that replaced constant strings, but that would hardly suffice in my case.

Is there some way to do this?
Pretty much any language I know of does have this ability, I suppose WebFOCUS does too?

Examples:
 original          | result
-------------------+--------
 Qr1: Pilot        | Pilot
 QR4;Production    | Production
 qr2:   Testing    | Testing

This message has been edited. Last edited by: Kerry,


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Virtuoso
posted Hide Post
I did manage a hand-crafted "solution", see below. It's not very flexible, but it fits my immediate needs.

DEFINE FILE CAR
 CARUP/A128V	= UPCASE(128, CAR, CARUP);
 HDLEN/I2	= IF (EDIT(CARUP, '99') EQ 'QR') AND (EDIT(CARUP, '$$9') EQ '1' OR '2' OR '3' OR '4' OR '5') AND (EDIT(CARUP, '$$$9') EQ ':' OR ';')
 	THEN 5 ELSE 1;

 CARTAIL/A128V	= SUBSTR(128, CAR, HDLEN, 128, 128 - HDLEN, CARTAIL);
 CAR2/A128V	= TRIM('B', CARTAIL, 128 - HDLEN, ' ', 1, CAR2);
END
TABLE FILE CAR
PRINT CAR
END


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Expert
posted Hide Post
WebFOCUS does not have regular expressions.

You could always put in a NFR (New Feature Request), but I would not keep your hopes up.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Expert
posted Hide Post
We "never" DEFINE columns as variable...
  
VAL1/A128 = IF EDIT(COLUMN_NAME,'$$$9') EQ ';' OR ':' THEN SUBSTR(128,COLUMN_NAME,5,128,124,'A128') ELSE COLUMN_NAME;
VAL2/A128 = STRREP(128,VAL1, 1,' ',0,'X',128,'A128');


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Expert
posted Hide Post
The best use I've found for variable length chars is concatenating fields, where you don't care about losing the overflow.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Virtuoso
posted Hide Post
Come on guys, it's 2011! We're not living in the 80's anymore... Isn't it about time for WebFOCUS to sprout some modern features?

Other languages have regular expression support. They use variable length strings by default, aren't riddled with arbitrarily short length limitations, usually have an extensive and convenient library of built-in functions for - say - date formatting, etc, etc.

Way too much of my time is spent on getting WebFOCUS to behave. I don'tget to spend my time developing, I'm too busy bashing a bloody dinosaur into shape with my bone club.

If I would be asked to advise a company on a reporting solution, WebFOCUS would be among the bottom of my list. Unfortunately it's the only reporting solution I'm familiar with - doesn't matter, being better than the competition (and I doubt WF is better) doesn't make a product good, just less bad.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Expert
posted Hide Post
quote:

Other languages have regular expression support.

Really? Name one, and, show the example.

COGNOS String Replace

Crystal Reports:

@alpha
"ABCDEFGHIJKLMNO"

@replace_string1
Replace({@alpha},"ABC","Z")

The result is 'ZDEFGHIJKLMNO'. This is a "constant", your example "is not".

SQL

SELECT CHAR(REPLACE( 'DINING', 'N', 'VID' ), 10),
FROM SYSIBM.SYSDUMMY1

The result is 'DIVIDIVIDG'. Again, a constant.

OR, SQL CASE logic, which is just as much code as WebFOCUS...

Of course, all of the above DID NOT give you your correct string because SUBSTR has not even been used yet, which, if I was coding in SQL, would use CASE logic...

So, let us ALL know of the function(s) you are referring to...


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Virtuoso
posted Hide Post
That's easy: Java, Python, PHP, Perl - to name a few. Even shell scripts have that option by calling sed or awk or grep.

For an example of regular expressions in SQL, see: http://www.postgresql.org/docs...NCTIONS-POSIX-REGEXP


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Expert
posted Hide Post
WebFOCUS is a reporting tool. Don't mix apples and oranges. Use a "reporting" tool, and, you forgot JavaScript...

And, where's the substring in your examples, and, removing spaces?

And, the SQL examples can be run within WebFOCUS...

This message has been edited. Last edited by: Tom Flynn,


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Expert
posted Hide Post
Don't ask us to fix it.

quote:
You could always put in a NFR (New Feature Request)



Also Tom has a good point.

WebFOCUS supports ANSI SQL, and RDBMS specific SQL.

This message has been edited. Last edited by: Waz,


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Silver Member
posted Hide Post
I took a bit of interest in the topic @ hand and found these articles where regex is supported in tsql and db2....

http://msdn.microsoft.com/en-u...gazine/cc163473.aspx

and


http://www.ibm.com/developerwo...olze/0301stolze.html

So I guess the moral of the story thus far is just skip WF and use the features of the native RDMS.


7.6.6 Mainframe
7.6.4 Web Focus
Windows

 
Posts: 45 | Location: Gaffney SC | Registered: March 30, 2007Report This Post
Virtuoso
posted Hide Post
quote:
Originally posted by Tom Flynn:
and, you forgot JavaScript...


As I said, "to name a few". There are plenty other languages that I didn't mention that support regexes and I was fully aware that Javascript is one of them when I wrote that - I just chose to not mention it, as several other languages.

quote:

And, where's the substring in your examples, and, removing spaces?


You seem to have gotten confused by my workaround without regexes, to get the desired result in WebFOCUS. The substring and trim are only needed because WebFOCUS doesn't support regexes, which is the reason we're having this conversation.

But if you need an example, in Postgres I'd have done:
SELECT regexp_replace(CAR, '/^[Qq][Rr][1-5][:;]\s*/', '') FROM CAR


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Expert
posted Hide Post
I don't need an example, I've done this via SQL many times, through WebFOCUS. And, I especially don't need a database engine example, either.

We are in 2011, remember, and your negativity/lambasting of WebFOCUS for not having functions that would accomplish your need, yet, you don't site a single example from another reporting tool, but, you use SQL.

Yes, your workaround works, and, so does mine. The flexibility of WebFOCUS allows for many ways to accomplish certain tasks, even those that address a lousy front end/ETL tool.

I bet you are an utter joy to work with.

Best wishes, I'll leave your threads alone...


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Virtuoso
posted Hide Post
People are using computers to make their work easier, not to make it harder.

Especially in the reporting business it must be quite common that data from a data-source doesn't exactly match what you need, or that data from different sources use different representations for the same thing. It is very likely that especially your customers run into situations like these a lot, and WebFOCUS is not helping, because it does not provide regex support. IMHO that would be a great feature and I'm quite surprised it's not already implemented, seeing how common these are in the world of computing.

Suggesting to solve the problem using native SQL, well... what was the reason we use WebFOCUS in the first place again? There are always some things require native SQL, but kneading data into a usable shape shouldn't be among them.

It's a shame that you only look at other reporting tools to compare what features WebFOCUS would benefit from. Yes, you should keep an eye on the competition to stay competitive, but don't you have any intention to go beyond that?


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Virtuoso
posted Hide Post
quote:
'/^[Qq][Rr][1-5][:;]\s*/', ''

I pray I never have to write anything like this gibberish to do something in WebFOCUS. I want my fourth generation language to stay that way (or maybe progress to fifth, but not go back to third or second generation syntax). That doesn't mean WF couldn't do with some fancy new functions and improved capabilities. I have skirmishes with this software almost every day (in many ways the fun part of my day). But remember that it is essentially a mainframe language that had to transform itself for the Web. So it has a lot of old baggage that it still has to schlepp around. I for one have been truly amazed at some of the ways IBI has managed to get this old dog do some of the tricks it does today. The GUIs still suck (partly because a lot of that clicking and dragging must translate into good old FOCUS code), but if you're fluent in the FOCUS language, you can be the master of your data universe. On the other hand, I was not happy about ReportBroker's devolution into ReportCaster (Focus code --> Java), nor the fact that -CRTFORM and Dialogue Manager can't be used to build Web launch pages, which instead require learning foreign tongues like HTML, JavaScript, XML, and what next? Yes, do make WF better, more powerful, easier to use, etc., etc., but please don't make it any more difficult to understand than it already is.


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Expert
posted Hide Post
Wep5622, I would like to remind you that there are many options in WenFOCUS.

As I have said before, put in a NFR.

You could build a DEFINE function to do this.

You could also build your own User Defined function for regular expressions. If you do, share it with IBI, they may add it to the function library.

I have to admit, having regular expressions testing would be quite useful in some circumstances.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Gold member
posted Hide Post
What is 'regular expressions testing'? I look at '/^[Qq][Rr][1-5][:;]\s*/', '' and am not sure what is being accomplished.
 
Posts: 60 | Location: Ellensburg Washington | Registered: May 22, 2009Report This Post
Virtuoso
posted Hide Post
I suppose regular expressions are from the UNIX world. Not many Windows applications seem to have support for it - the few that do usually are related to programming.

Regular expressions are a way to describe a pattern that a string (or substring) should match for an operation to apply to it. They're usually placed between '/'s, after which you can specify some options like whether the pattern as a whole repeats, whether it should be applied case-sensitive or not, whether to handle new-lines, etc.

The pattern quoted: /^[Qq][Rr][1-5][:;]\s*/ means:
^ - if it starts with...
[Qq] - a 'Q' or 'q', followed by
[Rr] - a 'R' or 'r', followed by
[1-5] - a character (number) from '1' to '5', followed by
[:;] - a ':' or ';', followed by
\s* - any number of white-space characters (or none)

Used in regexp_replace(pattern, string, substitution) this replaces the part of the string that matches the pattern by the string in substitution.

In my case I wanted to remove the start of strings that are like "Qr3: ", which is what the mentioned regular expression used with the regexp_replace-function would accomplish.

If you want to know more, here's a good place to start reading: http://www.regular-expressions.info/


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Expert
posted Hide Post
Regular expressions are used in JavaScript and also in my favourite Windows program, EditPlus Text Editor.


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Gold member
posted Hide Post
Thanks - It looks like a useful tool.
 
Posts: 60 | Location: Ellensburg Washington | Registered: May 22, 2009Report This Post
Expert
posted Hide Post
quote:
my favourite Windows program, EditPlus Text Editor




Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] String replacing

Copyright © 1996-2020 Information Builders