Focal Point
stran for reporting?

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

February 10, 2005, 04:47 PM
George Brown
stran for reporting?
So there is a very standard, very useful string function named stran that goes through string_orig and replaces all instances of string1 with string2

stran(string_orig, string1, string2)...

This function is only available in Maintain. I want to know

a) is there a comparable function in reporting

b) if not, then why not.

Does anyone have any ideas?

Functions that are NOT going to work for me are
OVERLAY - with overlay the programmer needs to supply the location of every string they want to alter
CTRAN - with ctran it will only replace one character for another single character.

Why are there functions that are available in maintain but not in focus reporting?
February 10, 2005, 06:23 PM
j.gross
The length of stran's result string may vary, if the From and To string lengths differ.

Maintain can handle that (the result is held in an A0), Define cannot.
February 14, 2005, 04:49 PM
George Brown
I was able to use a replace in a sql passthrough but it seems like a big workaround to do such a simple task. This is one of the first things you are taught in almost any programming language, string manipulation. I would think that it would be a little more intuitive/possible in focus.

Any other suggestions on how to do this in native focus?
February 14, 2005, 05:40 PM
TexasStingray
FYI, WebFOCUS Allows you to create and use your own User Written Subroutines. In windows this would be a dll and unix a .so and in MVS a compile program. I have create on a long time ago for a state agency that need to know who may letters and numbers were in a string like how many 9's how many A' etc. This was so they could order the colored coded folder labels like doctor offices use. Has any one out there created there own subroutines? and if so what do they do? May IBI need to have a site or forum that will allow users to share there subroutines?
February 14, 2005, 08:15 PM
John Calappi
George,

Maybe this will work for you. There are two strategies here. If the 2 strings are the same length then you can use the OVRLAY subroutine in conjunction with the POSIT subroutine. The second method is to split the string up into 3 parts, using SUBSTR and POSIT and concatenate the new string inbetween the two other strings.

The following code replaces the character string AN with XXX in the COUNTRY field of the CAR database.

I hope this helps.

DEFINE FILE CAR
-*IF THE 2 STRINGS ARE DIFFERENT LENGTHS THEN USE THIS CODE.
START_POS /I2 = POSIT(COUNTRY, 10, 'AN', 2, 'I2');
FINSH_POS /I2 = IF START_POS EQ 0 THEN 0 ELSE START_POS + 2;
BEGIN_STR /A10 = SUBSTR (10,COUNTRY,1,(START_POS-1),10,'A10');
END_STR /A10 = SUBSTR (10,COUNTRY,FINSH_POS, 10,10,'A10');
NEW_LNGSTR /A23 = IF START_POS EQ 0 THEN COUNTRY ELSE BEGIN_STR || 'XXX' || END_STR;
NEW_STR /A11 = SUBSTR (23, NEW_LNGSTR, 1,11,11,'A11');
-*IF THE 2 STRINGS ARE THE SAME LENGTH THEN USE THIS CODE.
POS /I2 = POSIT(COUNTRY, 10, 'AN', 2, 'I2');
OVRL /A10 = OVRLAY(COUNTRY, 10, 'XX', 2, POS, 'A10');
END
TABLE FILE CAR
PRINT COUNTRY
POS
OVRL
START_POS
FINSH_POS
BEGIN_STR
END_STR
NEW_LNGSTR
NEW_STR
END
February 14, 2005, 08:35 PM
George Brown
I appreciate the help but again the code provided here only helps for a single occurance. I'm lookinging to replace '|' with '
' in a field that has many instances of the verticle pipe.

It just seems silly to have to jump through so many hoops when in any other language it would be something like

new_string = replace(orig_string, string_2_find, string_2_replace_with)

For anyone who needs it, I used the following code using an sql passthrough...




SQL SQLORA SET SERVER MYSERVERNAME
SQL SQLORA
select REPLACE(field_name, '|', '
')
from table_name
where date = '2004/02/07';
END

This message has been edited. Last edited by: <Mabel>,