DISPLAY & ACCEPT
On z/OS, DISPLAY output goes to SYSOUT (configurable with the OUTDD compiler option).
11.1 DISPLAY
On z/OS, DISPLAY output goes to SYSOUT (configurable with the OUTDD compiler option). Numeric DISPLAY items print as stored (with leading zeros); move them to an edited field for readable output.
DISPLAY "Total: " WS-TOTAL
DISPLAY "No newline here... " WITH NO ADVANCING
* GnuCOBOL: standard error
DISPLAY WS-NAME UPON SYSERR
* IBM: operator console (use sparingly)
DISPLAY "Message" UPON CONSOLE11.2 ACCEPT
Never use plain ACCEPT ... FROM DATE (2-digit year, YYMMDD) in new code — it was the root of many Y2K bugs.
01 WS-INPUT PIC X(40).
01 WS-TODAY PIC 9(8).
01 WS-NOW PIC 9(8).
01 WS-DAY-OF-WEEK PIC 9.
01 WS-JULIAN PIC 9(7).
01 WS-ENV-VALUE PIC X(100).
* ...
ACCEPT WS-INPUT *> keyboard / SYSIN
ACCEPT WS-TODAY FROM DATE YYYYMMDD
ACCEPT WS-NOW FROM TIME *> HHMMSShh
ACCEPT WS-DAY-OF-WEEK FROM DAY-OF-WEEK *> 1 = Monday
ACCEPT WS-JULIAN FROM DAY YYYYDDD
ACCEPT WS-ENV-VALUE FROM ENVIRONMENT "HOME" *> GnuCOBOL11.3 Command-line arguments (GnuCOBOL)
On z/OS, batch programs receive a parameter string through EXEC PGM=...,PARM='...' and a LINKAGE SECTION halfword-length-prefixed area (Chapter 35).
01 WS-ARGS PIC X(100).
01 WS-ARG-COUNT PIC 9(3).
* ...
ACCEPT WS-ARG-COUNT FROM ARGUMENT-NUMBER
ACCEPT WS-ARGS FROM COMMAND-LINE11.4 Reading numbers safely
Accept numbers into an alphanumeric field and convert them with FUNCTION NUMVAL, which handles spaces, a sign, and a decimal point (" -12.5 " becomes −12.5):
Validate the text first with FUNCTION TEST-NUMVAL (Chapter 20).
01 WS-INPUT-TEXT PIC X(15).
01 WS-NUMBER PIC S9(9)V99.
* ...
DISPLAY "Enter an amount: " WITH NO ADVANCING
ACCEPT WS-INPUT-TEXT
COMPUTE WS-NUMBER = FUNCTION NUMVAL(WS-INPUT-TEXT)🧪 Part I Exercises
Install GnuCOBOL, compile and run HELLO, then deliberately put a statement in column 8 and a period past column 72 — observe the compiler messages.
Write a program that displays your name, city, and favorite language, each on its own line, using three 01-level PIC X fields with VALUE clauses.
Declare a CUSTOMER-RECORD group with ID, name (first/last), address, and balance; MOVE values into it and DISPLAY the whole group and each field.
Create a table of 10 PICTURE/value combinations (like §8.3) in a program and print each edited result between brackets.
Compute the storage size of S9(7)V99 COMP-3, S9(9) COMP, S9(4) COMP, 9(8) DISPLAY; verify with FUNCTION LENGTH or LENGTH OF.
Use REDEFINES to split an 8-digit date YYYYMMDD (obtained with ACCEPT ... FROM DATE YYYYMMDD) into year, month, and day, and display it as DD.MM.YYYY.
Define a WS-GRADE-SCORE PIC 999 with 88 levels for grades A–F and print the grade for a score entered by the user.
Write a program that reads two numbers with ACCEPT and NUMVAL, then prints their sum, difference, product, and quotient using edited PICTUREs with commas and a floating minus sign.
Rewrite HELLO and GREET in free format; compile with cobc -free.
Use ACCEPT ... FROM TIME and FROM DAY-OF-WEEK to print a greeting such as "Good morning, today is Tuesday".