


or try this procedure. It is i6.1 Remove the "len(4000000)" and set the size for your needs
h option(*nodebugio:*srcstmt) nomain
d htmlSafe pr a len(4000000) varying
d textIn a len(4000000) varying const
p htmlSafe b export
d htmlSafe pi a len(4000000) varying
d textIn a len(4000000) varying const
d wrkText s a len(4000000) varying
d position s 20i 0
d done s n
/free
wrkText = textIn;
dou done;
position = %scan('&':wrkText:position + 1);
if position = 0;
leave;
endif;
wrkText = %replace('&':wrkText:position:1);
enddo;
dou done;
position = %scan('"':wrkText:position + 1);
if position = 0;
leave;
endif;
wrkText = %replace('"':wrkText:position:1);
enddo;
dou done;
position = %scan('<':wrkText:position + 1);
if position = 0;
leave;
endif;
wrkText = %replace('<':wrkText:position:1);
enddo;
dou done;
position = %scan('>':wrkText:position + 1);
if position = 0;
leave;
endif;
wrkText = %replace('>':wrkText:position:1);
enddo;
return wrkText;
/end-free
p htmlSafe e
The ampersand is a special character in XML. A while back, we wrote the following sub procedure for an XML project we were working on. It receives the string and the position of the ampersand. It then breaks the string into two pieces at the ampersand, adds the special XML symbol for the ampersand and then concatenates the two strings back together. You should be able to modify it do suit your needs.
<pre>
‚**********************************************************************
‚* SET COMPILER OPTIONS
‚**********************************************************************
HNOMAIN
HOPTION(*NODEBUGIO:*SRCSTMT)
‚**********************************************************************
‚* PROGRAM NAME: AMPERSANDR
‚* CREATION DATE: 07/10/07
‚* PURPOSE OF PROGRAM: THE “&” IS A SPECIAL CHARACTER IN XML. THIS
‚* PROCEDURE WILL WRAP THE & IN A FORMAT THAT IS
‚* ACCEPTABLE TO XML.
‚*********************************************************************
‚* PROTOTYPE FOR PROCEDURE
‚*********************************************************************
D AMPERSANDR PR 50
D DESCRIPTION 50
D AMPER_POS 5 0
‚*********************************************************************
‚* START PROCEDURE DEFINITION
‚*********************************************************************
P AMPERSANDR B EXPORT
D AMPERSANDR PI 50
D DESCRIPTION 50
D AMPER_POS 5 0
‚*********************************************************************
‚* FIELD DEFINITIONS
‚*********************************************************************
D HOLD_DESC1 S 35 INZ(*BLANKS)
D HOLD_DESC2 S 35 INZ(*BLANKS)
D NEWDESCRIPTION…
D S 50 INZ(*BLANKS)
D AMPERSAND_SYMBOL…
D S 5 INZ(‘&’)
‚*********************************************************************
‚* REPLACE & WITH XML EQUILIVENT.
‚*********************************************************************
/FREE
HOLD_DESC1 = %TRIM(%SUBST(DESCRIPTION : 1 : AMPER_POS – 1));
HOLD_DESC2 = %TRIM(%SUBST(DESCRIPTION : AMPER_POS + 1));
NEWDESCRIPTION = %TRIM(HOLD_DESC1) + ‘ ‘ + AMPERSAND_SYMBOL +
‘ ‘ + %TRIM(HOLD_DESC2);
RETURN NEWDESCRIPTION;
/END-FREE
P AMPERSANDR E
</pre>


Ach! The code block translated my literals
in the %replace(‘ ‘…
Nice solution. Just what I needed also. But I find that when I have a string such as ‘John & CO & Johnson’ it only takes the first ‘&’ which is then output like this.
‘John & CO & Johnson’
I’m not a free form expert by any means but can’t get it to handle if more than one ‘&’ in on the same string
Oops, I solved it
Hi BigKat, NICE solution. Thanks alot
you’re welcome Tantart! Glad it could help!