#70 RETURN does not compile without AT END

invalid
closed
nobody
None
1
2 days ago
2014-04-30
Edward Hart
No

RETURN statements do not compile without the AT END clause. For example, take the following program:

      >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. return-test.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT sort-file.

DATA DIVISION.
FILE SECTION.
SD  sort-file.
01  sort-record PIC 9.

WORKING-STORAGE SECTION.
01  nums-area VALUE "749".
    03  nums PIC 9 OCCURS 3 TIMES INDEXED BY num-idx.

PROCEDURE DIVISION.
    SORT sort-file ASCENDING sort-record
        INPUT PROCEDURE in-sort
        OUTPUT PROCEDURE out-sort
    .
in-sort.
    PERFORM VARYING num-idx FROM 1 BY 1 UNTIL num-idx > 3
        RELEASE sort-record FROM nums (num-idx)
    END-PERFORM
    .
out-sort.
    PERFORM VARYING num-idx FROM 1 BY 1 UNTIL num-idx > 3
        RETURN sort-file INTO nums (num-idx)
    END-PERFORM
    .
END PROGRAM return-test.

This fails to compile with:

./test.cob: In paragraph 'out-sort':
./test.cob: 32: Error: syntax error, unexpected END-PERFORM, expecting END
./test.cob: 30: Error: PERFORM statement not terminated by END-PERFORM

Interestingly, the following compiles without warning:

        RETURN sort-file END
        MOVE sort-record TO nums (num-idx)

cobc -info:

cobc (OpenCOBOL) 2.0.20120211
Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Keisuke Nishida
Copyright (C) 2006-2012 Roger While
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Built     Nov 09 2013 10:42:22
Packaged  Feb 11 2012 12:36:31 UTC
C version (Microsoft) 1600
Build information
Build environment        : windows
CC                       : cl
CPPFLAGS                 :
CFLAGS                   :
LD                       : cl
LDFLAGS                  :

OpenCOBOL information
COB_CC                   : cl
COB_CFLAGS               : -I c:/OpenCobol
COB_LDFLAGS              :
COB_LIBS                 : c:/OpenCobol/libcob.lib c:/OpenCobol/mpir.lib
COB_CONFIG_DIR           : c:/OpenCobol/config
COB_COPY_DIR             : c:/OpenCobol/copy
COB_LIBRARY_PATH         : .
COB_MODULE_EXT           : dll
COB_EXEEXT               : .exe
Dynamic loading          : System
"CBL_" param check       : Disabled
Variable format          : 1
BINARY-C-LONG            : 4 bytes
Sequential handler       : Internal
ISAM handler             : VBISAM (Experimental)

Discussion

  • Edward Hart
    Edward Hart
    2014-05-03

    Sorry, I've just realised I'm in the wrong here. I didn't know AT END is compulsory in a RETURN and was fooled by an error in the GNU COBOL Programmer's Guide. Would you mind closing this bug?

     
  • Simon Sobisch
    Simon Sobisch
    2014-05-26

    It's no bug, END is mandatory for RETURN statement. All implementations I know have the same syntax as the COBOL 2002 standard:

    RETURN file-name (RECORD) [ INTO dest-record ] 
    
          (AT) END statement-1 
    
        [ NOT (AT) END statement-2 ] 
    
        [ END-RETURN ]
    

    Therefore the "interesting" sample you've provided should be read:

            RETURN sort-file
               END MOVE sort-record TO nums (num-idx)
    

    OK, I mark this as invalid/closed.
    Rechecked the current Programmer's Guide, it's correct, too.

    • status: open --> closed
    • Group: open --> invalid

    Simon

     
    Last edit: Simon Sobisch 2014-05-26