Reputation: 1088
I'm quite new in ILE RPG. Today I started to work out book from my work. In one of the chapter there are some samples of the usage of the Substring function %SUBSTR
. Here is the code:
DMOD S 5 INZ('VWXYZ')
DCON S 5 INZ('abcde')
DLENGTH S 5 0 INZ(2)
DSTART1 S 5 0 INZ(3)
DSTART2 S 5 0 INZ(4)
D*
C mod DSPLY
C con DSPLY
C start1 DSPLY
C start2 DSPLY
C length DSPLY
C*
C EVAL %SUBST(mod:3:2) = con
C*
C EVAL %SUBST(mod : 3 : 2) = %SUBST(con : 4 : 2)
C*
C EVAL %SUBST(mod:start1:length) =
C %SUBST(con:start1:length)
C*
C EVAL %SUBST(mod:start1-1:length) =
C %SUBST(con:start2/2:length+1)
C*
C MOVE *ON *INLR
When compiling, there is a abnormal execution that tells me there is wrong parameter in function %SUBST
. To be exact: the second parameter is wrong. I only get this error in the last EVAL
.
Upvotes: 2
Views: 231
Reputation: 23783
You're running afoul of RPG's precision rules...
The / operator is not integer division, it's numeric and the results have a decimal place.
You'll need to explicitly control the result type of your expression:
DMOD S 5 INZ('VWXYZ')
DCON S 5 INZ('abcde')
DLENGTH S 5 0 INZ(2)
DSTART1 S 5 0 INZ(3)
DSTART2 S 5 0 INZ(4)
D*
C mod DSPLY
C con DSPLY
C start1 DSPLY
C start2 DSPLY
C length DSPLY
C*
C EVAL %SUBST(mod:3:2) = con
C*
C EVAL %SUBST(mod : 3 : 2) = %SUBST(con : 4 : 2)
C*
C EVAL %SUBST(mod:start1:length) =
C %SUBST(con:start1:length)
C*
C EVAL %SUBST(mod:start1-1:length) =
C %SUBST(con:%int(start2 / 2):length+1)
C*
C MOVE *ON *INLR
Upvotes: 8