Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function ord works only sometimes but sometimes not

Tags:

cobol

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?

like image 484
inetphantom Avatar asked Jun 06 '17 05:06

inetphantom


1 Answers

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
like image 196
Edward H Avatar answered Sep 28 '22 11:09

Edward H