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     [CLOSED] TRIM(V) patterns

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED] TRIM(V) patterns
 Login/Join
 
Virtuoso
posted
I'm trying to trim white-space off a string from our database, but it doesn't appear to work.

I have something similar to this:
DEFINE FILE CAR
CR/A1 = HEXBYT(13, 'A1');
LF/A1 = HEXBYT(10, 'A1');

A1/A100V = COUNTRY | ' ';
B1/A100V = COUNTRY | CR;
C1/A100V = COUNTRY | LF;
D1/A100V = COUNTRY | ' '|CR|LF;

A2/A100V = TRIMV('B', A1, 100, ' '|CR|LF, 3, A2) | 'x';
B2/A100V = TRIMV('B', B1, 100, ' '|CR|LF, 3, B2) | 'x';
C2/A100V = TRIMV('B', C1, 100, ' '|CR|LF, 3, C2) | 'x';
D2/A100V = TRIMV('B', D1, 100, ' '|CR|LF, 3, D2) | 'x';
END
TABLE FILE CAR
PRINT A2 B2 C2 D2
ON TABLE PCHOLD FORMAT PDF
ON TABLE SET STYLE *
$
TYPE=REPORT, LINEBREAK='LF',$
ENDSTYLE
END


For some reason the strings don't get trimmed. Does trim actually support patterns, or is it just looking for the substring specified as the "pattern"? In that case the D2 string should have been trimmed, and that doesn't seem to be the case... hmm... Perhaps because COUNTRY isn't actually a VARCHAR field (my real field is)?

How do people trim such strings???

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
Expert
posted Hide Post
I don't think you can embed your CR and LF into the TRIMV function, I'm fairly sure "' '|CR|LF, 3, A2" is not recognized like you think it is.

Have you tried hard concatenation "||" instead of soft "|" ?


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
Virtuoso
posted Hide Post
For a moment I thought that would be THE solution, but it appears that the concatenation operator stops stripping white-space on encountering a newline (decimal value 10).

Unfortunately I have lines that end in byte sequences of (32 32 10 32 32) sometimes, and the newline characters (either 10 or 13) are really what I wanted to strip off the end of the text, as they kind of mess up the layout.


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
Try using a variation on:
A2/A100V = TRIMV('B', A1, 100, ' ', 3, A2) | 'x';
B2/A100V = TRIMV('B', TRIMV('B', B1, 100, CR, 3, B2), 100, ' ', 3, B2) | 'x';
C2/A100V = TRIMV('B', TRIMV('B', C1, 100, LF, 3, C2), 100, ' ', 3, A2) | 'x';
D2/A100V = TRIMV('B', TRIMV('B', TRIMV('B', D1, 100, LF, 3, B2), 100, CR, 3, D2), 100, ' ', 3, D2) | 'x'; 


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Virtuoso
posted Hide Post
That would work if you would know beforehand what specific white-space patterns occur in your data, but that's not usually the case.

I was thinking defining a recursive function would solve the issue, but that it would probably be a pretty big performance hit aside, it seems that DEFINE FUNCTION doesn't support recursion. According to the docs: "DEFINE functions can call other DEFINE functions, but cannot call themselves". I tried and you can't indeed!

Instead we decided to just ignore that there's trailing white-space in our reports, for lack of a proper solution.


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
Member
posted Hide Post
Have you tried doing a CTRAN to change the newline character to something else and stripping the new character from the fields?


7.6.10 Oracle 10g Windows XP
 
Posts: 11 | Registered: January 10, 2011Report This Post
Virtuoso
posted Hide Post
I can't do that, as I do need to keep line-breaks inside the text in my fields. I only need to trim them if they're part of leading or trailing white-space.


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
Gold member
posted Hide Post
Does this work for you?

 
DEFINE FILE CAR
CR/A1 = HEXBYT(13, 'A1');
LF/A1 = HEXBYT(10, 'A1');

A1/A20 = COUNTRY | ' ';
B1/A20 = COUNTRY | CR;
C1/A20 = COUNTRY | LF;
D1/A13V = COUNTRY | ' '|CR|LF;

D2/A14V = TRIMV('B', D1, 13, ' '|CR|LF, 3, 'A13') | 'x';
D3/A14V = D1 | 'x' ;
END
TABLE FILE CAR
PRINT D2 D3
END

 


You have to be careful that the pattern is actually at the end of the field.

Edward Wolfgram


IBI Development
 
Posts: 61 | Registered: November 15, 2005Report This Post
Member
posted Hide Post
Can you use the squeeze function then instead of TRIMV?

SQUEEZ(length, string, outfield)


7.6.10 Oracle 10g Windows XP
 
Posts: 11 | Registered: January 10, 2011Report This Post
Virtuoso
posted Hide Post
It would appear that readers of this forum aren't familiar with the term "whitespace" and seem to assume that I simply mean space characters (decimal ASCII code 32). The full set of white-space characters (in ASCII, there are some more in other encodings) are codes 9 (tab), 10 (line-feed), 13 (carriage return) and 32 (space).

Any number of consecutive characters from that set in any particular order is considered whitespace.

If that's at the end of my data, I would like to remove it.

quote:
Originally posted by Edward Wolfgram:
You have to be careful that the pattern is actually at the end of the field.


That's a problem, as I have no way of knowing the exact pattern beforehand. This is user-entered data which can contain some formatting (that I need to keep!) inside the body of the text.

Trailing spaces (as opposed to whitespace in general) aren't so much of a problem, it's new-lines embedded in those spaces that are causing empty lines between the records in my reports; I don't want those.

quote:
Originally posted by RReeder:
Can you use the squeeze function then instead of TRIMV?

SQUEEZ(length, string, outfield)


Not only does that not remove the new-lines I need to get rid of, it will also touch the body of the text and change formatting that the users entered (quite possibly on purpose). My problem is exclusively with leading and trailing whitespace.


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
Member
posted Hide Post
Then CTRAN should still work. Change the newline field to something that trimv will not ignore. trim your fields and then ctran it back to newline. Other than that you will just have to tell you customers that the garbage they put in will just have to be put out again.


7.6.10 Oracle 10g Windows XP
 
Posts: 11 | Registered: January 10, 2011Report This Post
Virtuoso
posted Hide Post
Along the lines of RReeder's suggestion, this might work - although it ain't elegant. Function PATTERN displays all of the non-printable characters as 'X's. Use function STRREP to replace the 'X's with spaces. Trim spaces from first the front and then both front and back of the string. Determine the lengths of the un-trimmed, trimmed-leading, and trimmed-both strings, and use them to calculate the actual starting position and length of the fully trimmed string. Use function SUBSTV to cut the fully trimmed string from the original string. This method should preserve non-printable characters in the middle of the string.

DEFINE FILE CAR
 CR/A1 = HEXBYT(13, 'A1');
 LF/A1 = HEXBYT(10, 'A1');
 STR/A100V         = ' ' | CR | ' ' | LF | ' ' | COUNTRY | CR | ' ' | LF | CAR | CR | ' ' | MODEL | ' ' | CR | LF | ' ';
-*
 STR_PATTERN/A100V = PATTERN(100,STR,'A100V');
 STR_STRREP/A100V  = STRREP(100,STR_PATTERN,1,'X',1,' ',100,'A100V');
 STR_TRIML/A100V   = TRIMV('L',STR_STRREP,100,' ',1,'A100V');
 STR_TRIMB/A100V   = TRIMV('B',STR_STRREP,100,' ',1,'A100V');
 STR_LENGTH/I5     = ARGLEN(100,STR_STRREP,'I5');
 TRIML_LENGTH/I5   = ARGLEN(100,STR_TRIML,'I5');
 TRIMB_LENGTH/I5   = ARGLEN(100,STR_TRIMB,'I5');
 STR_START/I5      = STR_LENGTH - TRIML_LENGTH + 1 ;
 STR_CUT/A100V     = SUBSTV(100,STR,STR_START,TRIMB_LENGTH,'A100V');
-*
 STRZ/A100V        = 'z' | STR | 'z' ;
 STR_CUTZ/A100V    = 'z' | SUBSTV(100,STR,STR_START,TRIMB_LENGTH,'A100V') | 'z';
END
-*
TABLE FILE CAR
 PRINT STR STRZ STR_CUTZ
 ON TABLE PCHOLD FORMAT PDF
 ON TABLE SET STYLE *
  TYPE=REPORT, LINEBREAK='LF',$
 ENDSTYLE
END


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report 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     [CLOSED] TRIM(V) patterns

Copyright © 1996-2020 Information Builders