 %REPLACE (Replacing string, actual string, starting position, offset)
It is used the segment of a string with the replacement string.
Example
In the example below, source string ‘search string’ will have replacement with replacement string ‘word’ from
position 8 till length 6.

Columns . . . :

6

80Browse

AMIT/QRPGLESRC

SEU==>
FMT D

REPLACE
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data *******************************************
0001.00 D source

S

0002.00 D pos

30A

S

inz ('Search string')

5U 0

0003.00
0004.00

/FREE

0005.00

pos = %scan (' ' : source);

0006.00

source = %replace ( 'word': source : pos+1:6);

0007.00

DSPLY

0008.00

source;

/END-FREE

0009.00 C

SETON

LR

******************************* End of data ******************************

OUTPUT
Search word

as400 built in function- %REPLACE

  • 1.
     %REPLACE (Replacingstring, actual string, starting position, offset) It is used the segment of a string with the replacement string. Example In the example below, source string ‘search string’ will have replacement with replacement string ‘word’ from position 8 till length 6. Columns . . . : 6 80Browse AMIT/QRPGLESRC SEU==> FMT D REPLACE DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++ *************** Beginning of data ******************************************* 0001.00 D source S 0002.00 D pos 30A S inz ('Search string') 5U 0 0003.00 0004.00 /FREE 0005.00 pos = %scan (' ' : source); 0006.00 source = %replace ( 'word': source : pos+1:6); 0007.00 DSPLY 0008.00 source; /END-FREE 0009.00 C SETON LR ******************************* End of data ****************************** OUTPUT Search word