Data Type in COBOL

I wrote the following program, I am confused why when I compile the program, I get an error stating that A-COL (1,1) is not a numeric value when displaying A-COL (1,1) gives me 1.

   IDENTIFICATION DIVISION.
   PROGRAM-ID. TEST1.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 DIFF PIC 9(3).
       01 ARRAY.
           05 A-ROW OCCURS 99 TIMES.
               10 A-COL OCCURS 2 TIMES.
                   15 TABLE-CONTENT PIC 9(3).

   PROCEDURE DIVISION.
       MOVE 1 TO A-COL(1,1).
       MOVE 2 TO A-COL(2,1).
       DISPLAY A-COL(1,1).
       COMPUTE DIFF = A-COL(1,1) - A-COL(2,1).
       DISPLAY DIFF.
   STOP RUN.
+4
source share
2 answers

Change the definition of A-COL to

"10 A-COL PIC 9(3) OCCURS 2 TIMES."

and delete TABLE-CONTENT.

Group variables are considered alphanumeric (type X), so they cannot be used in the calculation.

Alternatively, you can do this - refer to the location of the address using the actual number field.

PROCEDURE DIVISION.
   MOVE 1 TO TABLE-CONTENT(1,1).
   MOVE 2 TO TABLE-CONTENT(2,1).
   DISPLAY A-COL(1,1).
   COMPUTE DIFF = TABLE-CONTENT(1,1) - TABLE-CONTENT(2,1).
   DISPLAY DIFF.

You can also make a signed one DIFF.

Additional Information

A-COL(1,1) "1", "1xx", x = . . , , "001".

+5

WORKING-STORAGE . A-COL, THE-CONTENT. THE-CONTENT, A-COL.

   IDENTIFICATION DIVISION.
   PROGRAM-ID. TEST1.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  DIFF PIC S9(3).
   01  ARRAY.
       05  A-ROW 
           OCCURS 99 TIMES.
           10  A-COL 
               OCCURS 2 TIMES.
               15 TABLE-CONTENT            PIC 9(3).

   PROCEDURE DIVISION.
       MOVE 1                       TO TABLE-CONTENT ( 1 1 )
       MOVE 2                       TO TABLE-CONTENT ( 2 1 )
       DISPLAY 
               ">"
               TABLE-CONTENT ( 1 1 )
               "<"
       COMPUTE DIFF                 = TABLE-CONTENT ( 1 1 ) 
                                    - TABLE-CONTENT ( 2 1 )
       DISPLAY 
               ">"
               DIFF
               "<"
       STOP RUN
       .

, . - -, , . , "" .

, , - , , .

"" ( COBOL , OCCURS), , . 1-col-1, row-1-col-2, row-2-col-1, row-2-col-2-to-row-99-col-1, row-99-col -2.

(ADD, SUBTRACT, MULTIPLY, DIVIDE COMPUTE) . , "", .

(, , ) , . PICture, PICture.

+2

Source: https://habr.com/ru/post/1624652/


All Articles