Skip to content

DISPLAY Statement

The DISPLAY statement causes data stored in an identifier (literal, data item, or output from a function call) to be displayed on the terminal screen at the specified location, with the specified attributes.

Format 1

       DISPLAY {identifier-1}  UPON mnemonic-name-1 
              [WITH NO ADVANCING] 
       [END-DISPLAY]

Syntax:

  1. identifier-n is a data element, literal, or data returned from a function call.
  2. mnemonic-name-1 is a system name associated with a hardware device, or a user name associated with a system name in the Special Names area.

General Rules:

  1. mnemonic-name-1 must be CONSOLE, CRT, PRINTER, or a user defined name associated with CONSOLE, CRT, or PRINTER in SPECIAL NAMES.
  2. All mnemonic-name-1 are interpreted as CONSOLE.
  3. In the absence of the UPON clause, UPON CONSOLE is applied as the default.
  4. WITH NO ADVANCING removes carriage return/line feed sequences from the end of the DISPLAY.

Format 2

       DISPLAY {identifier-1}  UPON {ARGUMENT-NUMBER  } 
                                     {COMMAND-LINE     } 
                                     {ENVIRONMENT-NAME } 
                                     {ENVIRONMENT-VALUE} 
                                     {PRINTER} 
       [END-DISPLAY]

Syntax:

identifier-n is a data element, literal, or data returned from a function call.

General Rules:

  1. DISPLAY identifier-1 UPON ARGUMENT-NUMBER is recognized syntax, but is otherwise treated as commentary. A subsequent ACCEPT FROM ARGUMENT-NUMBER does not return the value of identifier-1.
  2. DISPLAY identifier-1 UPON COMMAND-LINE modifies the COMMAND-LINE.
  3. A subsequent ACCEPT FROM COMMAND-LINE statement returns the value of identifier-1.
  4. Creating an environment variable, and assigning it a value can be done with the DISPLAY verb, as follows:
    • DISPLAY identifier-1 UPON ENVIRONMENT-NAME
    • DISPLAY identifier-2 UPON ENVIRONMENT-VALUE
    • This sequence of statements is the equivalent of the SET ENVIRONMENT “ENVIRONMENT-NAME” TO “ENVIRONMENT-VALUE” statement.
  5. The value of identifier-2 can be retrieved from the environment variable named identifier-1 using the ACCEPT FROM ENVIRONMENT statement.
  6. DISPLAY identifier-1 UPON PRINTER, when used with a file defined with the COB_DISPLAY PRINTER environment variable, performs OPEN and WRITE statements on the file, and the file is CLOSE'd after each DISPLAY.

Format 3

       DISPLAY identifier-1 
       [AT {[LINE NUMBER {identifier-2}]}] 
              {COLUMN} NUMBER {identifier-3} 
              {COL   } 
              {identifier-4} 
       [ [WITH] NO ADVANCING ] 
                     [ [WITH] {BELL}      ] 
                              {BEEP} 
                     [ [WITH] {BLINKING}  ] 
                              {BLINK } 
                     [ {HIGHLIGHT}        ] 
                       {LOWLIGHT } 
                     [ REVERSE-VIDEO      ] 
                     [ UNDERLINE          ] 
                     [ OVERLINE           ] 
                     [ FOREGROUND-COLOR is numeric-1 ] 
                     [ BACKGROUND-COLOR is numeric-2 ] 
                     [ SCROLL {UP  } numeric-3 LINES ] 
                              {DOWN} 
                     [ BLANK LINE         ] 
                     [ BLANK SCREEN       ] 
       [END-DISPLAY]

Syntax:

  1. identifier-n is a data element, literal, or data returned from a function call.
  2. identifier-4 is a 4 byte numeric value where the first two bytes represent the line number and the second 2 bytes represent the column number. This provides an alternative way to position a DISPLAY. In effect, DISPLAY [ identifier-1 ] LINE 10 COLUMN 10 is synonymous with DISPLAY [ identifier-1 ] AT 1010.
  3. numeric-n is a literal or data item that is numeric.

General Rules:

  1. A field-level DISPLAY is positioned with the use of an AT statement, which is used to designate the line number and the column number. This can be done either through the separate use of the keywords LINE and COLUMN, or with a single 4-byte numeric value that represents the location of the DISPLAY with a Line-Column designation, where bytes 1-2 represent the line number, and bytes 3-4 represent the column number.
  2. DISPLAY field1 LINE 1 COLUMN 3 Field2 AUTO UPDATE
    Prior to this enhancement, each field had to be the target of a separate DISPLAY statement, and the AUTO UPDATE clause was supported as WITH AUTO UPDATE.
  3. For information regarding the DISPLAY ATTRIBUTES, see the Screen Attributes section.

Format 4

       DISPLAY screen-name-1 
       [AT {[LINE NUMBER      {identifier-2}]}] 
              {COLUMN} NUMBER {identifier-3} 
              {COL   } 
              {identifier-4} 
       [END-DISPLAY]

Syntax:

  1. screen-name-n is the name of a screen element described in the Screen Section.
  2. identifier-n is a data element, literal, or data returned from a function call.
  3. identifier-4 is a 4-byte numeric value where the first two bytes represent the line number and the second 2-bytes represent the column number. This provides an alternative way to position a DISPLAY. In effect, DISPLAY [screen] LINE 10 COLUMN 10 is synonymous with DISPLAY [screen] AT 1010.

General Rules:

For information regarding the DISPLAY ATTRIBUTES, see the Screen Attributes section.

Code Sample:

       IDENTIFICATION DIVISION. 
       PROGRAM-ID. DISPLAY-3. 

       ENVIRONMENT DIVISION. 
       CONFIGURATION SECTION. 

      * THE SPECIAL-NAMES PARAGRAPH THAT FOLLOWS PROVIDES FOR THE 
      * CAPTURING OF THE F10 FUNCTION KEYAND FOR POSITIONING OF THE 
      * CURSOR. 

       SPECIAL-NAMES. 
              CURSOR IS CURSOR-POSITION 
              CRT STATUS IS CRT-STATUS. 

       DATA DIVISION. 
       WORKING-STORAGE SECTION. 

      * CURSOR-LINE SPECIFIES THE LINE AND CURSOR-COL SPECIFIES THE
      * COLUMN OF THE CURSOR POSITION. 

       01 CURSOR-POSITION. 
              02 CURSOR-LINE PIC 99. 
              02 CURSOR-COL PIC 99. 

      * NORMAL TERMINATION OF THE ACCEPT STATEMENT WILL RESULT IN A VALUE 
      * OF '0' IN KEY1. WHEN THE USER PRESSES F10, THE VALUE IN KEY1 WILL 
      * BE '1' AND FKEY-10 WILL BE TRUE. 

       01 CRT-STATUS. 
              03 KEY1       PIC X. 
              03 KEY2       PIC X. 
                     88 FKEY-10 VALUE11. 
              03 FILLER PIC XX. 

      * THE FOLLOWING DATA ITEMS ARE FOR A "DAILY CALENDAR." IT SHOWS 
      * THE DAY'S APPOINTMENTS AND ALLOWS APPOINTMENTS TO BE MADE, 
      * CANCELED, AND PRINTED. 

       01 DATA-STORE. 
              03 ACCEPT-ITEM1 PIC X. 
              03 APPT-NAME PIC X(80). 
              03 APPT-DESC PIC X(80). 
              03 APPT-DATE. 
                     05 APPT-DAY PIC 99 COMP. 
                     05 APPT-MONTH PIC 99 COMP. 
                     05 APPT-YEAR PIC 99 COMP. 
              03 APPT-TIME. 
                     05 APPT-HOUR PIC 99. 
                     05 APPT-MINUTE PIC 99. 
                     05 APPT-MERIDIEM PIC XX. 
              03 APPT-VERIFY PIC X. 
              03 EMPTY-LINEPIC X(80). 

      * THE SCREEN SECTION DESIGNS THE DAILY CALENDAR, WITH A MENU 
      * SCREEN FROM WHICH THE USER SELECTS AN OPTION: TO SHOW 
      * APPOINTMENTS, SCHEDULE AN APPOINTMENT, CANCEL AN APPOINTMENT, 
      * AND PRINT THE APPOINTMENTS. 

       SCREEN SECTION. 

       01 MENU-SCREEN BLANK SCREEN 
                     FOREGROUND-COLOR7BACKGROUND-COLOR1. 
              02 MENU-SCREEN-2. 
                     03 TITLE-BAR 
                            FOREGROUND-COLOR7BACKGROUND-COLOR4. 
                                   04 LINE1 PIC X(80) FROM EMPTY-LINE. 
                                   04 LINE1 COLUMN 32 VALUE "DAILY CALENDAR". 

                     03 LINE 7 COLUMN 26 
                            PIC X TO ACCEPT-ITEM1. 
                     03 VALUE " SHOW APPOINTMENTS FOR A DAY ". 
                     03 LINE 9 COLUMN 26 
                            PIC X TO ACCEPT-ITEM1. 
                     03 VALUE " SCHEDULE AN APPOINTMENT ". 
                     03 LINE 11 COLUMN 26 
                            PIC X TO ACCEPT-ITEM1. 
                     03 VALUE " CANCEL AN APPOINTMENT ". 
                     03 LINE 13 COLUMN 26 
                            PIC X TO ACCEPT-ITEM1. 
                     03 VALUE " PRINT YOUR APPOINTMENTS ". 
                     03 HELP-TEXT 
                                   FOREGROUND-COLOR 6 BACKGROUND-COLOR 0. 
                            04 LINE 19 COLUMN 12 
                                   VALUE
                            " USE THE ARROW KEYS TO MOVE THE CURSOR AMONG MENU ITEMS. ". 
                            04 LINE 20 COLUMN 12 
                                   VALUE 
                            " PRESS <RETURN> WHEN THE CURSOR IS AT THE DESIRED ITEM. ". 
                            04 LINE 21 COLUMN 12 
                                   VALUE 
                            " PRESS <F10> TO EXIT.                                    ". 

       01 SCHEDULE-SCREEN BLANK SCREEN. 
              02 TITLE-BAR 
                            FOREGROUND-COLOR 7 BACKGROUND-COLOR 4. 
                     03 LINE1 PIC X(80) FROM EMPTY-LINE. 
                     03 LINE1 COLUMN30 VALUE "SCHEDULE APPOINTMENT". 

              02 FIELDS-TEXT 
                            FOREGROUND-COLOR 7 BACKGROUND-COLOR 1. 
                     03 LINE 5 VALUE " DESCRIPTION OF APPOINTMENT: ". 
                     03 LINE PLUS 4 VALUE " DATE OF APPOINTMENT (DD/MM/YY): ". 
                     03 COLUMN PLUS 5 VALUE"/ /". 
                     03 LINE PLUS 2 VALUE " TIME OF APPOINTMENT (HH:MM MM): ". 
                     03 COLUMN PLUS 5 VALUE ":". 

              02 FIELDS-INPUT 
                            FOREGROUND-COLOR 7 BACKGROUND-COLOR 0 AUTO. 
                     03 LINE 6 PIC X(80) TO APPT-NAME REQUIRED. 
                     03 LINE 7 PIC X(80) TO APPT-DESC. 
                     03 LINE 9 COLUMN 36 PIC 99 USING APPT-DAYFULL . 
                     03 LINE 9 COLUMN 39 PIC 99 USING APPT-MONTH FULL. 
                     03 LINE 9 COLUMN 42 PIC 99 USING APPT-YEAR. 
                     03 LINE 11 COLUMN 36 PIC 99 USING APPT-HOUR. 
                     03 LINE 11 COLUMN 39 PIC 99 USING APPT-MINUTE. 
                     03 LINE 11 COLUMN 42 PIC XX USING APPT-MERIDIEM. 

              02 HELP-TEXT 
                            FOREGROUND-COLOR 6 BACKGROUND-COLOR 0. 
                     03 LINE 16 COLUMN 18 
                            VALUE " USE CURSOR KEYS TO MOVE WITHIN THE FIELDS. ". 
                     03 LINE 17 COLUMN 18 
                            VALUE " PRESS <TAB> TO ENTER NEXT FIELD.           ". 
                     03 LINE 18 COLUMN 18 
                            VALUE" PRESS <RETURN> WHEN FINISHED.               ". 

       01 VERIFY-SUBSCREEN FOREGROUND-COLOR 7 BACKGROUND-COLOR 1. 
              02 LINE 16 COLUMN 1 ERASE EOS. 
              02 LINE 17 COLUMN 25 VALUE " IS THIS ENTRY CORRECT? (Y/N): ". 
              02 PIC X USING APPT-VERIFY AUTO. 

       PROCEDURE DIVISION. 
       P0. 
       #
              DISPLAY MENU-SCREEN. 

      * THE CURSOR POSITION IS NOT WITHIN AN ITEM ON THE SCREEN, SO THE 
      * FIRST ITEM IN THE MENU WILL BE ACCEPTED FIRST. 

              MOVE 0 TO CURSOR-LINE, CURSOR-COL. 

      * THE USER MOVES THE CURSOR WITH THE ARROW KEYS TO THE 
      * DESIRED MENU ITEM (TO SHOW, SCHEDULE, CANCEL, OR PRINT 
      * APPOINTMENTS) AND SELECTS THE ITEM BY PRESSING <RETURN>. 
      * IF THE USER WISHES TO EXIT WITHOUT SELECTING AN OPTION, 
      * THE USER CAN PRESS THE F10 FUNCTION KEY. 

              ACCEPT MENU-SCREEN.
              IF KEY1 EQUAL "0" 
                     PERFORM OPTION_CHOSEN 

              ELSE IF KEY1 EQUAL "1" AND FKEY-10 
                     DISPLAY "YOU PRESSED THE F10 KEY; EXITING..." LINE22. 

              STOP RUN. 

       OPTION_CHOSEN. 

      * FOR BREVITY, THE SAMPLE PROGRAM INCLUDES COMPLETE CODE 
      * FOR THE "SCHEDULE APPOINTMENT" SCREEN ONLY. A COMPLETE 
      * PROGRAM FOR A CALENDAR WOULD ALSO INCLUDE CODE FOR 
      * DISPLAYING, CANCELING, AND PRINTING THE DAY'S APPOINTMENTS. 

              IF CURSOR-LINE = 7 
                     DISPLAY "YOU SELECTED SHOW APPOINTMENTS" LINE 22. 

              IF CURSOR-LINE = 9 
                     MOVE "01" TO APPT-DAY 
                     MOVE "01" TO APPT-MONTH 
                     MOVE "94" TO APPT-YEAR 
                     MOVE "12" TO APPT-HOUR 
                     MOVE "00" TO APPT-MINUTE 
                     MOVE "AM" TO APPT-MERIDIEM 
                     DISPLAY SCHEDULE-SCREEN 

      * THE USER TYPES THE DESCRIPTION, DATE, AND TIME OF THE 
      * APPOINTMENT. 

              ACCEPT SCHEDULE-SCREEN 

              MOVE "Y" TO APPT-VERIFY 
              DISPLAY VERIFY-SUBSCREEN 

      * THE USER IS ASKED, "IS THIS ENTRY CORRECT?" ANSWER IS 
      * Y OR N. 

              ACCEPT VERIFY-SUBSCREEN. 

              IF CURSOR-LINE = 11 
              DISPLAY "YOU SELECTED CANCEL APPOINTMENTS" LINE 22. 

              IF CURSOR-LINE = 13 
              DISPLAY "YOU SELECTED PRINT APPOINTMENTS" LINE 22. 

              ENDPROGRAM SCREEN2.
Back to top