× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Seems anything using replace() or even this code misses the point - the OP has a stream file, if I understand it. Unless you pull the entire contents into your variable, there's a lot of work to put the data back after the replacement. Because you are replacing the original with a longer value.

That makes sed such an attractive option. It takes care of all that. Once you learn how to use it, which I will some day, I'm sure!

If you CAN deal with a full variable and writing it back out to a different stream file, I like using the SQL replace function - that replaces all instances of the search string with the replacement value - very cool. Just use a SET statement.

RPG's replace() can do the job, so long as you do it in a loop that uses somewhere around the last found position as the start from value in a loop. SQL is so much easier!!

HTH
Vern

hr@xxxxxxxxxxxx wrote:
Just doing replace dosn't do the job ...

Here are the RPGLE code that does the trick:

* Declare Internal Variables d i s 10i 0 d io s 10i 0 d xml s 1000a varying d xmlout s 42a varying d xmlmax s 10i 0 inz(42) /free // demo xml string xml = '<!-- This is a test of converting string xml elements -->' + '<head id="12345">' + '<name>dsfgdfg dg</name>' + '<currency id="USD" />' + '</head>'; for i = 1 to %len(xml); select; when i = 1; xmlout += %subst(xml:i:1); io += 1; when %subst(xml:i:1) = '<' and %subst(xml:(i-1):1) = '>' or io = xmlmax and xmlout > ''; // insert CRLF or output fixed record to file/print dsply xmlout; xmlout = ''; io = 0; xmlout += %subst(xml:i:1); io += 1; other; xmlout += %subst(xml:i:1); io += 1; endsl; endfor; if xmlout > ''; // insert CRLF or output fixed record file/print dsply xmlout; endif; *inlr = *on; /end-free

Henrik




rob@xxxxxxxxx Sent by: rpg400-l-bounces@xxxxxxxxxxxx
10-02-2010 22:14
Please respond to
RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>


To
RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>
cc

Subject
Re: Replace 1 Char with 3Char's






Jim,

Bypass that step. Instead of trying to "copy" it into a PF and then process that with RPG I'd suggest using Scott's IFS stuff to read the file
directly. It will perform better because 1 - you won't be reading all that data twice, once to reformat it to PF and once to post it.
2 - You'll be less tempted to use CPYFRMIMPF or CPYFRMSTMF to put it in a PF and CPYFRMIMPF can easily be beaten performance wise by using Scott's API's. Try running CPYFRMIMPF in debug and Oy Vey! will the underlying sql astound you.

And if you are using any of those to process this stream file you'll appreciate the flexibility of doing your own. However, since it's raw xml
I'm willing to wager you're not using CPYFRMIMPF but maybe CPYFRMSTMF and flexibility is not a big concern.

However, if you're going with your original intent will %replace work?



Rob Berendt

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.