Displaying values on a screen or in a file (DISPLAY)

You can display the value of a data item on a screen or write it to a file by using the DISPLAY statement.

About this task


Display "No entry for surname '" Customer-Name "' found in the file.".

In the example above, if the content of data item Customer-Name is JOHNSON, then the statement displays the following message on the system logical output device:


No entry for surname 'JOHNSON' found in the file.

To write data to a destination other than the system logical output device, use the UPON phrase with a destination other than SYSOUT. For example, the following statement writes to the file that is specified in the SYSPUNCH DD statement:


Display "Hello" upon syspunch.

You can specify a file in the z/OS® UNIX file system by using the SYSPUNCH DD statement. For example, the following definition causes DISPLAY output to be written to the file /u/userid/cobol/demo.lst:


//SYSPUNCH DD PATH='/u/userid/cobol/demo.lst',
// PATHOPTS=(OWRONLY,OCREAT,OTRUNC),PATHMODE=SIRWXU,
// FILEDATA=TEXT

The following statement writes to the job log or console and to the TSO screen if you are running under TSO:


Display "Hello" upon console.

When you display the value of a USAGE NATIONAL data item to the console, the data item is converted from Unicode (UTF-16) representation to EBCDIC based on the value of the CODEPAGE option. This is the only case in which conversion of national data is done when you use the DISPLAY statement. Conversion is done in this case because the output is known to be directed to a screen.

To have a national data item be converted when you direct output to a different device, use the DISPLAY-OF intrinsic function, as in the following example:


01 Data-in-Unicode pic N(10) usage national.
. . .
    Display function Display-of(Data-in-Unicode, 00037)

Related references  
CODEPAGE
  
DISPLAY statement (Enterprise COBOL for z/OS Language Reference)