I have a string field XXX with the following data.: ++ are blanks. Difficult to represent here.
++++++++GO+NXT+NXT+NXT+DEPENDING+ON+NXTNUM.
I want to change the NXT fields for ABC such that the line now says:
++++++++GO+ABC+ABC+ABC+DEPENDING+ON+NXTNUM.
Now - noting that I don't want to change NXTNUM to become ABCNUM I did the following.
Inspect XXX replacing all "+" by "@". ie: change all spaces to @ signs.
now I did a: MOVE Substitute (XXX "@NXT@" "@ABC@") to YYY.
followed by a reverse: Inspect YYY replacing all "@" by "+". ie: change all the @ signs back to spaces.
and got the following result:
++++++++GO+ABC+NXT+ABC+DEPENDING+ON+NXTNUM.
The question is - should the substitute NOT HAVE ALSO changed the middle NXT to ABC ??.
The manual says the following:
This function parses string, replacing all occurrences of from-n strings with the corresponding
to-n strings. My Highlighting.
Sample program duplicating the above with comments attached.
It looks like you are correct. Maybe after the first replace, the pointer that records current position in the from-string gets incremented by 1 and does not recognize @NXT@ as it is but recognize it as NXT@ only, accordingly it does not replace it.
I tried to convert what you said into a small test program. The last case shows a simpler version of the problem:
IDENTIFICATIONDIVISION.PROGRAM-ID.test.DATADIVISION.WORKING-STORAGESECTION.01xxxpicx(40).01YYYpicx(40).01ORIGINAL-XXXPICX(40).PROCEDUREDIVISION.MOVE" GO NXT NXT NXT DEPENDING ON NXTCNT. "TOORIGINAL-XXXMOVEORIGINAL-XXXTOXXXMOVEFUNCTIONSUBSTITUTE(XXX"NXT""ABC")TOYYY.DISPLAY"1: "YYY*>YYY=GOABCABCABCDEPENDINGONABCCNT."INSPECTXXXREPLACINGALL" "BY"@".DISPLAY"2: "XXX*>@@@@GO@NXT@NXT@NXT@DEPENDING@ON@NXTCNT.@MOVEFUNCTIONSUBSTITUTE(XXX"@NXT@""@ABC@")TOYYY.DISPLAY"3: "YYY*>@@@@GO@ABC@NXT@ABC@DEPENDING@ON@NXTCNT.@*>EXPECTED*>@@@@GO@ABC@ABC@ABC@DEPENDING@ON@NXTCNT.@*>---------INSPECTYYYREPLACINGALL"@"BY" ".DISPLAY"4: "YYY*>GOABCNXTABCDEPENDINGONNXTCNT.*>MyGuess:*>IFANEXTRA@ISUSEDFOLLOWINGNXT,ITWORKSMOVE"@@@NXT@@NXT@"TOXXXMOVEFUNCTIONSUBSTITUTE(XXX"@NXT@""@ABC@")TOYYY.DISPLAYYYY*>@@@ABC@@ABC@STOPRUN.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Works "as designed", which is like Emmad guessed a "pointer wise" change; text that already got replaced - in your case the trailing @ of @NXT@ - should not be re-inspected.
Note: In this special case (length are identical) I'd suggest to use INSPECT instead of FUNCTION SUBSTITUTE, but if you need to inspect the full context left/right you may want to loop over the text.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Inspect replacing fails the same way. I end up with ABC NXT ABC.
Perhaps the 'as designed' needs a repair.
as the manual says replace all occurrences - it's an occurrence - it just falls as part of an existing occurrence.
OK - hows about I pose this question.
A field contains the following - where a + is actually a space.
How do I replace ALL occurrences of NXT (ONLY) with ABC.
++++++GO+NXT+NXT+NXT+DEPENDING+ON+NXTCNT that gives me
++++++GO+ABC+ABC+ABC+DEPENDING +ON+NXTCNT.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I assume you don't meant the manual but the Programmer's Guide. In this case please create a bug report for Vince to adjust it, ideally with a suggestion how it should be changed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
At least 1 thing I've learned from this - you can Move substitute (AAA BBB CCC) to AAA.
Source & Destination can be the same.
I've always done the move from AAA to XXX & then moved back again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a string field XXX with the following data.: ++ are blanks. Difficult to represent here.
++++++++GO+NXT+NXT+NXT+DEPENDING+ON+NXTNUM.
I want to change the NXT fields for ABC such that the line now says:
++++++++GO+ABC+ABC+ABC+DEPENDING+ON+NXTNUM.
Now - noting that I don't want to change NXTNUM to become ABCNUM I did the following.
Inspect XXX replacing all "+" by "@". ie: change all spaces to @ signs.
now I did a: MOVE Substitute (XXX "@NXT@" "@ABC@") to YYY.
followed by a reverse: Inspect YYY replacing all "@" by "+". ie: change all the @ signs back to spaces.
and got the following result:
++++++++GO+ABC+NXT+ABC+DEPENDING+ON+NXTNUM.
The question is - should the substitute NOT HAVE ALSO changed the middle NXT to ABC ??.
The manual says the following:
This function parses string, replacing all occurrences of from-n strings with the corresponding
to-n strings. My Highlighting.
Sample program duplicating the above with comments attached.
It looks like you are correct. Maybe after the first replace, the pointer that records current position in the from-string gets incremented by 1 and does not recognize @NXT@ as it is but recognize it as NXT@ only, accordingly it does not replace it.
I tried to convert what you said into a small test program. The last case shows a simpler version of the problem:
Works "as designed", which is like Emmad guessed a "pointer wise" change; text that already got replaced - in your case the trailing
@
of@NXT@
- should not be re-inspected.Note: In this special case (length are identical) I'd suggest to use
INSPECT
instead ofFUNCTION SUBSTITUTE
, but if you need to inspect the full context left/right you may want to loop over the text.Inspect replacing fails the same way. I end up with ABC NXT ABC.
Perhaps the 'as designed' needs a repair.
as the manual says replace all occurrences - it's an occurrence - it just falls as part of an existing occurrence.
OK - hows about I pose this question.
A field contains the following - where a + is actually a space.
How do I replace ALL occurrences of NXT (ONLY) with ABC.
++++++GO+NXT+NXT+NXT+DEPENDING+ON+NXTCNT that gives me
++++++GO+ABC+ABC+ABC+DEPENDING +ON+NXTCNT.
I assume you don't meant the manual but the Programmer's Guide. In this case please create a bug report for Vince to adjust it, ideally with a suggestion how it should be changed.
YES as you say - looping over does the trick - eventually.
Either looping or applying
SUBSTITUTE
more than once (three times should work for everything).At least 1 thing I've learned from this - you can Move substitute (AAA BBB CCC) to AAA.
Source & Destination can be the same.
I've always done the move from AAA to XXX & then moved back again.