1

I'm watching COBOL tutorials, they use the "erase" statement to clean the screen and it doesn't work for me. The compiler indicates "syntax error, unexpected ERASE"

The code is:

DISPLAY "1.- CALC, 2.- CLOSE" ERASE.

It is my mistake?

I am using opencobol on ubuntu Sorry about my English, it's not my native language

Rick Smith
  • 3,962
  • 6
  • 13
  • 24
Liosoft
  • 11
  • 1
  • 2
    The sentence here is `DISPLAY`. `ERASE` here is not a sentence but at best a clause, and a non-standard one. If your Cobol implementation doesn't support it, this is what you will get. – user207421 Jun 02 '21 at 12:05
  • Is your question answered? If yes please mark as answer, if not comment. – Simon Sobisch Aug 02 '21 at 18:14

1 Answers1

3

As noted by @user207421 ERASE is not a statement, it is a clause for the DISPLAY statement, and it even is standardized - but (standard-wise) it needs a specification what you want to erase:

ERASE [END] [OF] LINE
      [END] [OF] SCREEN
      EOL
      EOS

The syntax you have shown is actually the very non-standard, outdated Microsoft-COBOL DISPLAY statement with ERASE phrase.

If you still use open-cobol then the package is heavily outdated, there should be a new gnucobol package available in Ubuntu (otherwise you could build from source). Using GnuCOBOL 2.2 you get a nicer error message:

error: syntax error, unexpected ., expecting LINE or SCREEN

And then you can decide if you want the old ms-cobol variant (that's supported in GnuCOBOL, but only with the pos-specifier) or the standard variant (ERASE EOS would be the compatible version and is supported by many compilers).

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38