Ubuntu GnuCobol CURRENCY SIGN IS "£" causes compile errors
Asked Answered
P

1

6

Using GnuCOBOL 2.2.0 on Ubuntu 18.10. Working through 'Beginning COBOL for Programmers' by Michael Coughlan. GnuCOBOL has been compiling the book's examples without trouble up until Chapter 9, when this program:

IDENTIFICATION DIVISION.
PROGRAM-ID. Listing9-2.
AUTHOR. Michael Coughlan.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
    CURRENCY SIGN IS "£".
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Edit1    PIC £££,££9.99.

PROCEDURE DIVISION.
Begin.
    MOVE 12345.95 TO Edit1
    DISPLAY "Edit1 = " Edit1
    STOP RUN.

...throws the following errors when attempting to compile:

~/Documents/COBOL$ cobc -x -free Listing9-2.cbl
Listing9-2.cbl: 8: error: PICTURE SYMBOL for CURRENCY must be one character long
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: in paragraph 'Begin':
Listing9-2.cbl: 15: error: invalid MOVE statement

If all the £ characters are replaced by $, the compile succeeds. Could the problem be that GnuCOBOL does not support the British pound sign? Or, does one have to enter it a different way than just pressing '£' on the keyboard?

Piliform answered 3/3, 2019 at 22:7 Comment(3)
The default character encoding (character set) on many linux systems is UTF-8 which has both single and double byte characters. The pound symbol is a multi-byte character in UTF-8. GNU Cobol only handles single byte characters ~ hence the CURRENCY must be one character long message. Use a single byte encodng. note: COBOL tends to be byte basedPublicness
I am curious as what did you end up doing to resolve this? Could you please share findings? Thank.Marlo
With the file open in Geany, choose the menu option: Document > Set Encoding > West European > Western (ISO-8859-15) Then save the file, after which the problem stops occurring.Piliform
L
6

As the compiler says:

PICTURE SYMBOL for CURRENCY must be one character long

so the £ found in the source file is not a character long - I assume you've used UTF-8 encoding and GnuCOBOL doesn't directly supports any multi-byte source encoding (you actually get away with it as long as there is no "size overflow" anywhere).

If possible I suggest to change the encoding to ISO-8859-15 which is a single-byte encoding which has the pound sign included.

Listless answered 3/3, 2019 at 22:31 Comment(1)
Just to confirm the issue was not explicitly setting encoding. Geany has an option for ISO-8859-15, which does compile successfully.Piliform

© 2022 - 2024 — McMap. All rights reserved.