display command


DISPLAY

Command:

DISPLAY

Syntax:

DISPLAY <literal1> & <literal2> & …

<variable1> <variable2>

<expression1> <expression2>

Description:

The DISPLAY statement is used to display literals, variables, and expressions to the standard output device (normally the screen in command-line mode, and the web browser when using CobolScript with a web server). Because CobolScript allows expressions inside DISPLAY statements, individual arguments to DISPLAY must be clearly separated using the ampersand (&).

Displaying group items is permitted. Using group items as DISPLAY variables is especially useful when constructing web pages, both for code clarity and reusability purposes (group items can be stored in separate copybooks and used by multiple programs using the COPY and INCLUDE statements).

Use of positional string referencing and the use of expressions as arguments in positional string referencing are both permitted in DISPLAY statements. See the Example Usage below.

When directly displaying expressions, five significant digits will usually follow the decimal point if the expression’s value is non-integer. If the expression’s value is extremely large, however (>1,000,000,000), some precision may be lost in the fractional portion of the value. CobolScript has an absolute limit of 16 digits of precision, and will not correctly display or perform computations on any number, expression or variable, with more than 16 total digits.

Displaying numeric variables is preferred to displaying expressions when format masks are relevant, or when a value has more than five decimal places; this is because variables will be displayed according to their defined picture clause format. Numeric variables, however, are limited to ten total digits of precision for values less than 100,000,000, slightly more digits of precision for values equal to or higher than 100,000,000, with a absolute maximum of 16 digits of precision. To use a variable in place of an expression, simply define a variable and assign it to the expression of interest using a COMPUTE statement; then DISPLAY the variable in place of the expression.

The CobolScript string delimiter is the ` (the accent key, usually located in the upper left corner of American keyboards, below the Esc key). String literals must be enclosed by ` in order for them to display properly. Alternatively, the string delimiter can be changed for a particular program run by setting the appropriate command line option. Refer to the section Running CobolScript from the Command Line, in Chapter 2, Getting Started with CobolScript, to learn more about command line options.

Example Usage:

DISPLAY with multiple arguments:

DISPLAY var1 &

var2 & var3.

Expression example:

DISPLAY output + 5.

Positional string referencing example (with expression as argument):

DISPLAY `Hour: ` & time(start_pos:start_pos+1).

Group level data item example:

1 group_level.

5 `This is`.

5 ` a test.`.

DISPLAY group_level.

See Also:

DISPLAYLF, DISPLAYFILE

Sample Program:

DISPLAY.CBL

DISPLAYASCIIFILE

Command:

DISPLAYASCIIFILE

Syntax:

DISPLAYASCIIFILE <filename>

Description:

The DISPLAYASCIIFILE command will display the contents of the specified ASCII file filename to the standard output device.

DISPLAYASCIIFILE is useful for displaying individual files that contain raw HTML to the calling browser window, so long as the appropriate MIME header information is first displayed; this can be useful if you wish to clearly separate program logic from HTML without going through the effort of placing the HTML into group item variables. See the Creating Virtual HTML section of Chapter 5, Building Web-Based Systems, for information on displaying MIME headers.

DISPLAYASCIIFILE can also be used within a CobolScript program to transfer an ASCII file to a remote user. This is useful for user-initiated downloads through CGI form submissions on a web site that requires user verification or other logic to execute prior to the actual file transfer. See Chapter 7, Advanced Internet Programming Techniques Using CobolScript for more information on how to use DISPLAYASCIIFILE in this manner.

DISPLAYASCIIFILE should only be used to display files that are ASCII text; use DISPLAYFILE to display binary files.


Command:

DISPLAYASCIIFILE

Example Usage:

DISPLAYASCIIFILE `test.dat`.

DISPLAYASCIIFILE filename_var.

See Also:

DISPLAYFILE, DISPLAY, DISPLAYLF

Sample Program:

DOWN.CBL

DISPLAYFILE

Command:

DISPLAYFILE

Syntax:

DISPLAYFILE <filename>

Description:

The DISPLAYFILE command will display the contents of the specified binary file filename to the standard output device.

DISPLAYFILE can be used within a CobolScript program to transfer a binary file (such as an executable) to a remote user. This is useful for user-initiated downloads through CGI form submissions on a web site that requires user verification or other logic to execute prior to the actual file transfer. See Chapter 7, Advanced Internet Programming Techniques Using CobolScript for more information on how to use DISPLAYFILE in this manner.

DISPLAYFILE should only be used to display binary files; use DISPLAYASCIIFILE to display ASCII text files.

Example Usage:

DISPLAYFILE `test.exe`.

DISPLAYFILE filename_var.

See Also:

DISPLAYASCIIFILE, DISPLAY, DISPLAYLF

Sample Program:

DOWN.CBL

DISPLAYLF

Command:

DISPLAYLF

Syntax:

DISPLAYLF <literal1> & <literal2> & …

<variable1> <variable2>

<expression1> <expression2>

Description:

DISPLAYLF is the same as DISPLAY, but displays a trailing linefeed character after every elementary item argument has been displayed, including those cases where the initial argument is a group item.

Example Usage:

Example with gldi argument:

1 group_level.

5 `This is`.

5 ` a test.`.

DISPLAYLF group_level.

Example with multiple elementary arguments:

1 var1 PIC X(N) VALUE `This is`.

1 var2 PIC X(N) VALUE ` a test.`.

DISPLAYLF var1 & var2 & `.. .. ..`.

See Also:

DISPLAY, DISPLAYFILE

Sample Program:

DISPLAY.CBL