I am trying to programm some kind of Caesar Cipher in Cobol. But somehow I get the following compile error:
Numeric function "INTEGER FUNCTION ORD" was not allowed in this context.
This error gets fired here (both lines)
000048 MOVE FUNCTION ORD("A") TO a
000049 display function ord("A")
But NOT here
000054 MOVE FUNCTION CHAR(FUNCTION MOD(
000055 FUNCTION ORD(outstring (i:1))
000056 - a + offset, 26) + a)
000057 TO outstring (i:1)
i
is the position of the outstring
we are looking at. a
is the value of "a"
or of "A"
needed to make sure we stay in the 26 letters, defined as
000018 03 a pic S9(3).
Where is the difference? Why does the second work and the first not?
The second example works and the first doesn't because you're allowed to have numeric expressions as function arguments but you can't have numeric expressions as the subject of a MOVE
statement. In your case, your compiler (IBM?) considers a numeric intrinsic function call to be a numeric expression. So you need to replace the MOVE
with COMPUTE
and change the function call in the DISPLAY
to a
.
000048 COMPUTE a = FUNCTION ORD("A")
000049 DISPLAY a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With