Encodings: EBCDIC, ASCII and UTF-8
| EBCDIC vs ASCII | |
| GnuCOBOL encodings | |
| UTF-8 files |
EBCDIC vs ASCII
Mainframes store text in EBCDIC, where letters sit in different code positions than ASCII. Files that cross between a mainframe and Linux need a conversion step, or the text arrives as punctuation soup.
01 WS-NAME PIC X(30).
MOVE "Ada" TO WS-NAME.
GnuCOBOL encodings
GnuCOBOL handles encodings with the -fencoding flag or the COB_ENCODING environment variable. Setting ASCII or UTF-8 makes file I/O and string literals behave like any Unix tool:
cobc -x -free -fencoding=UTF-8 -o hello hello.cob
UTF-8 files
PIC X fields are byte-oriented, so one UTF-8 character can span several X positions. For multi-byte text, size fields generously and avoid INSPECT on characters that may be split across a field boundary.
Next: Date and time
Article author: Arthur Isaev