I need to manipulate xml-files larger than char-field max-length allowed with RPG.
My current solution uses a char-field...
My app stores XML-files in CLOB-fields. I copy the xml-file from CLOB-field to a char-field: [code] /free exec sql SELECT MyCLOBfield INTO :myfield FROM...etc [/code] I then use %scan to find relative position of the string to be replaced, which is done using the %replace bif. Since multiple occurrences of the string to be replaced may exist, I proces the %scan and %replace in a loop untill all occurrences has been replaced.
With SQL it is possible to replace all occurrences in one step (ie statement), which this small RPG test-pgm proves: [code] d myfield s 1000 /free exec sql DECLARE :myfield VARIABLE; exec sql SET :myfield = 'xxx bbb ccc bbb ccc aaa'; exec sql SET :myfield = REPLACE(:myfield, 'bbb', 'xxx'); // myfield now contains 'xxx xxx ccc xxx ccc aaa''. *inLR = *on; [/code]
As can be seen, SQL makes multiple replace's, thus eliminating the need of a programmed loop.
The xml-files I recieve from outside my company tends to be bigger and bigger, and I foresee that my current solution will break down soon. Therefore I want to re-write the code to use pointers. So far, I have this in place: 1. I copy the xml-file from CLOB-field to memory using SQL SELECT multiple fragments (32K at a time) and append the fragment to the xml-string in memory using a pointer. 2. I have RPG-code in place to do the scan/replace task, but I'd like to do this part with sql as well.
Is it possible to use SQL with pointer to make a 'multi-replace'like the way I discovered (see above) it can be done with a char-field. ?
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!