Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Look for easy way to scan and replace a character in a alpha field

454 views
Skip to first unread message

kbark...@yahoo.com

unread,
Mar 8, 2010, 11:51:27 AM3/8/10
to
I want to get rid of all the commas out of some text fields and
replace them with something else using RPG.

With the %replace to this? If so can somebody post an example of how
to do this?

Thanks,

I would like to avoid doing a bunch of coding involving arrays and
processing it manually a character at a time.

CRPence

unread,
Mar 8, 2010, 1:16:37 PM3/8/10
to

From the limited description, I infer that %xlat would be
sufficient to replace all commas with some other character.?

If not just single characters to replace, such as replacing with
the empty string, fewer, or more characters, then the %replace BIF
in RPG can be used in a DoWhile loop of %scan & the %replace to
process the string directly rather than as an array of characters.
Or just use the REPLACE scalar in SQL which performs for all
occurrences; i.e. loop is part of the function. Searching
http://archive.midrange.com on some variations of the following
tokens should find a variety of examples: DOU DOW REPLACE SCAN

http://archive.midrange.com/rpg400-l/200211/msg00404.html
http://archive.midrange.com/rpg400-l/200611/msg00111.html

Some others, more generically; w/out DOx tokens; or to try to
find some SQL examples more directly, using REPLACE SQL EXEC:
http://archive.midrange.com/midrange-l/201003/msg00173.html
http://archive.midrange.com/rpg400-l/200811/msg00381.html

Regards, Chuck

JTF

unread,
Mar 9, 2010, 10:39:23 AM3/9/10
to
On Mar 8, 11:51 am, "kbarkem...@yahoo.com" <kbarkem...@yahoo.com>
wrote:

Try this. Two examples for you....

***replace double quotes with single quotes
c eval position = %scan(x'7F':ProjDesc)
c dow Position <> 0
c eval %subst(ProjDesc:Position:2)=x'7D'
c eval position = %scan(x'7F':ProjDesc)
c enddo

***For proper html display replace CR/LF hex values with
\n
c eval position = %scan(x'0D25':ProjStsNot)
c dow Position <> 0
c eval %subst(ProjStsNot:Position:2)='\n'
c eval position = %scan(x'0D25':ProjStsNot)
c enddo

0 new messages