8

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?

inetphantom
  • 2,498
  • 4
  • 38
  • 61
  • Just to say: I was not able to solve the problem since we were not using ascii but an other where a to z are not in order but with gaps.. – inetphantom Jul 11 '17 at 08:01

1 Answers1

5

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
Edward H
  • 576
  • 3
  • 8