Focal Point
[Sharing] Know before using STRREP

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1677017276

September 18, 2014, 04:48 AM
Ram Prasad E
[Sharing] Know before using STRREP
Hi,

I would like to share the functionality of STRREP that I recently came across. Not sure if this is a bug or defined behavior.

When source string length is equal to or greater than search string length then no issue. Working as documented.

But when source string length is less then search string length then this function returns only SPACE. So when we use dynamic value for source string, we need to validate the length before using STRREP function.

CODE:
------
-SET &ECHO='ALL';
-****************** Not working as expected ***************
-SET &SOURCE_STRING='Web';
-SET &SEARCH_STRING='WEBFOCUS';
-SET &REPLACE_STRING='WebFOCUS';
-SET &STRREP_STRING=STRREP(&SOURCE_STRING.LENGTH, &SOURCE_STRING, &SEARCH_STRING.LENGTH, &SEARCH_STRING, &REPLACE_STRING.LENGTH, &REPLACE_STRING, 4000,'A400');
-RUN
-TYPE Source String: &SOURCE_STRING
-TYPE Search String: &SEARCH_STRING
-TYPE Replace String: &REPLACE_STRING
-TYPE STRREP String: &STRREP_STRING

-****************** Below one works fine ***************
-SET &SOURCE_STRING='Welcome to WEBFOCUS';
-SET &SEARCH_STRING='WEBFOCUS';
-SET &REPLACE_STRING='WebFOCUS';
-SET &STRREP_STRING=STRREP(&SOURCE_STRING.LENGTH, &SOURCE_STRING, &SEARCH_STRING.LENGTH, &SEARCH_STRING, &REPLACE_STRING.LENGTH, &REPLACE_STRING, 4000,'A400');
-RUN
-TYPE Source String: &SOURCE_STRING
-TYPE Search String: &SEARCH_STRING
-TYPE Replace String: &REPLACE_STRING
-TYPE STRREP String: &STRREP_STRING

OUTPUT:
-------
-****************** Not working as expected ***************
-SET &SOURCE_STRING='Web';
-SET &SEARCH_STRING='WEBFOCUS';
-SET &REPLACE_STRING='WebFOCUS';
-SET &STRREP_STRING=STRREP(03, Web, 08, WEBFOCUS, 08, WebFOCUS, 4000,'A400');
-RUN
-TYPE Source String: Web
Source String: Web
-TYPE Search String: WEBFOCUS
Search String: WEBFOCUS
-TYPE Replace String: WebFOCUS
Replace String: WebFOCUS
-TYPE STRREP String:
STRREP String:
-****************** Below one works fine ***************
-SET &SOURCE_STRING='Welcome to WEBFOCUS';
-SET &SEARCH_STRING='WEBFOCUS';
-SET &REPLACE_STRING='WebFOCUS';
-SET &STRREP_STRING=STRREP(19, Welcome to WEBFOCUS, 08, WEBFOCUS, 08, WebFOCUS, 4000,'A400');
-RUN
-TYPE Source String: Welcome to WEBFOCUS
Source String: Welcome to WEBFOCUS
-TYPE Search String: WEBFOCUS
Search String: WEBFOCUS
-TYPE Replace String: WebFOCUS
Replace String: WebFOCUS
-TYPE STRREP String: Welcome to WebFOCUS
STRREP String: Welcome to WebFOCUS
-RUN



Thanks,
Ram


WebFOCUS 8.1.05
Windows
http://ibiwebfocus.wordpress.com
https://www.facebook.com/groups/ibi.webfocus/
September 18, 2014, 05:14 AM
Alan B
This has been covered on the Forum before, and also documented on the Tech support site, where this behaviour is explained by explaining that as the replacement string is longer than the input string, the result is erroneous and therefore a blank will be returned.


Alan.
WF 7.705/8.007
September 18, 2014, 10:26 AM
j.gross
That's really absurd.

Returning spaces is not noted in the manual (under Usage Notes) as the behavior to expect.

Under normal circumstances, whenever there is no match the result is the input string as-is (truncated or paddedto the specified output length).

When the input length is less than the search-for length, failure to find any matches is of course guaranteed. But (absent an explicit note in the manual to the contrary) the function should return the input string unchanged, just as it would if a match were feasible but not found.


- Jack Gross
WF through 8.1.05