Can a paragraph be recursively called in COBOL?

Can you invoke a paragraph in paragraph in COBOL for an IBM mainframe?

200-PARAGRAPH SECTION.

    IF WS-COUNTER < 10
       ADD 1 TO WS-COUNTER
       PERFORM 200-PARAGRAPH
    ELSE
       DISPLAY 'I'M DONE'
    END-IF.

 200-EXIT.
    EXIT.
+4
source share
3 answers

Check the current COBOL Language Reference, but AFAIR a para cannot execute PERFORM. The wording is similar in that you will get unpredictable results, since recursion is not supported.

If you need to rewind the same code, perhaps refactoring to use PERFORM UNTIL is what you need?

+4
source

@jdv is correct.

, , ( Enterprise COBOL) , Enterprise COBOL, , PROGRAM .

, , . .

:

200-PARAGRAPH SECTION.

200-PARAGRAPH - , . SECTION , , . SECTION.

, .

. COBOL 1985 SECTIONS .

( ):

    PERFORM                      200-descriptive-and-meaningful-name
        invariant-data-item-with-a-VALUE-of-ten
                                 TIMES
    DISPLAY "I'M DONE"

200-descriptive-and-meaningful-name.
    CONTINUE (just representative of whatever code you need)
    .

inline-perform, ( PERFORMing , ).

, . , - .

- , PDF . SO. , , .

+4

, , , . .

       PERFORM
         VARYING ws-counter FROM 1 BY 1
           UNTIL ws-counter > 9
       END-PERFORM.
       DISPLAY 'I' QUOTE 'M DONE'.

COBOL, .

   200-SECTION SECTION.
   200-PARAGRAPH.
       IF ws-counter < 10
           ADD 1 TO ws-counter
           GO TO 200-PARAGRAPH
       ELSE
           DISPLAY 'I' QUOTE 'M DONE'
       END-IF.

, , , - GO TO .

   200-SECTION SECTION.
   200-PARAGRAPH.
       IF ws-counter < 10
           ADD 1 TO ws-counter
           GO TO 200-PARAGRAPH
       END-IF.
       DISPLAY 'I' QUOTE 'M DONE'.

, ? , , , , . .

       MOVE 10 TO ws-counter.
       DISPLAY 'I' QUOTE 'M DONE'.

, , .

       05  ws-counter               PIC 9(02).
       05  max-passes               PIC 9(02) BINARY VALUE 10.

       MOVE ZERO TO ws-counter.
       PERFORM 200-PARAGRAPH
           UNTIL ws-counter >= max-passes.
       DISPLAY 'I' QUOTE 'M DONE'.

   200-PARAGRAPH.
       ADD 1 TO ws-counter.
+1

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


All Articles