Option 1 — TomLiotta’s suggestion: <i>You can loop through the characters in the string. Replace any byte that is less than x’3F’ with x’3F’</i>
<pre>
d replCharacter c const(x’3F’)
d fld79a s 79 inz(x’F0F1F2F3F44022′) ‘01234’+ blank
+ unprintable
d loc s 5i 0
c for loc = 1 to %len(fld79a)
c if %subst(fld79a:loc:1) < replCharacter
c eval %subst(fld79a:loc:1) = replCharacter
c endif
c endfor
</pre>
Option 2 — BigKat’s original suggestion incorporating TomLiotta’s suggestion: <i>The Character Data Representation Architecture (CRDA) specifies the ‘3F’X character as a replacement character. It should show up as a reverse-image block on the display.</i>
<pre>
d validCharacters…
d c const(‘0123456789 ‘)
d replCharacter c const(x’3F’)
d fld79a s 79 inz(‘01234ABC56789’)
d loc s 5i 0
c eval loc = %check(validCharacters + replCharacter
c :fld79a)
c dow loc <> 0
c eval %subst(fld79a:loc:1) = replCharacter
c eval loc = %check(validCharacters + replCharacter
c :fld79a)
c enddo
</pre>
or if you prefer a procedure for use in a service program (and it even uses <b><i>RECURSION</i></b>) BTW: I arbitrarily chose 132 characters, as that should handle any field on the standard display sizes unless you have used CNTFLD to split a longer field into a continuous multi-line field.
<pre>
d displaySafe pr 132a
d input 132a const
p displaySafe b export
d displaySafe pi 132a
d input 132a const
d validCharacters…
d c const(‘0123456789 ‘)
d replCharacter c const(x’3F’)
d loc s 5u 0
d wrk s 132a
c eval wrk = input
c eval loc = %check(validCharacters + replCharacter
c :wrk)
c if loc = 0
c return wrk
c else
c eval %subst(wrk:loc:1) = replCharacter
c return displaySafe(wrk)
c endif
p displaySafe e
</pre>
Discuss This Question: 7  Replies