Kednos PL/I for OpenVMS Systems
Reference Manual


Previous Contents Index

9.2.2.4 GET SKIP

The GET SKIP statement positions the input file at the start of a new line. The format of this GET statement is as follows:

GET [FILE(file-reference)] SKIP [(expression)] ; 

The syntax is described in more detail in Section 9.2.2.1.

9.2.2.5 Execution of the GET Statement

When a GET statement is executed, the first action is to evaluate the FILE option, if there is one. For example:


GET FILE(INFILE) LIST(A); 

If INFILE references an open file, PL/I checks that the file has the INPUT and STREAM attributes.

If INFILE has not been opened, PL/I implicitly opens the file with the attributes INPUT and STREAM.

If the associated file does not exist, or if for any reason the associated file cannot be opened, the UNDEFINEDFILE condition is signaled.

If the statement has a STRING option instead of a FILE option, the reference in the STRING option is evaluated.

If the statement has neither a FILE option nor a STRING option, it is taken to refer to the default file constant SYSIN. SYSIN is declared by default with the STREAM INPUT attributes, and it is normally used for input from a terminal (see Section 9.2.6).

If the input stream is a file, the next action is to execute the SKIP option, if there is one. The SKIP option cannot be used with the STRING option. Note that a GET statement can perform a SKIP operation even if it performs no data input. For example:


GET FILE(INFILE) SKIP(2); 
This statement repositions the file referenced by INFILE to the second line following the current line in the file.

A GET statement that has the EDIT or LIST option performs input from the stream to a list of input targets, which must be variables of computational data types. If the input target is an aggregate variable, then input is assigned to each element of the aggregate; input values are assigned to array elements in row-major order and to structure members in the order of their declaration. An input target can also contain a DO construct that further controls the assignment. Because a stream consists only of ASCII characters, and the input targets are not necessarily character-string variables, an input field must be selected from the input stream for each target and must be converted, if necessary, to the type of the target.

In edit-directed (GET EDIT) statements, the selection and assignment of the input field are controlled by a format item that corresponds to the input target. In the default case, which applies to terminal input and to input from most stream files, a data format item assumes that the end of the input field has occurred if it encounters the end of a record in an input file or the end of a line when the input is from a terminal.

For example, a common technique for reading lines of varying length from a terminal is to deliberately use a format item that specifies a field wider than the column width of the terminal. If a carriage return is typed in response to an input request for GET EDIT, or if the end of a record is immediately encountered, the requested field width is filled with spaces and assigned to the input target under the control of the corresponding format item. (Note that all spaces will cause an error for B format items.) However, if the input stream is a character-string expression (GET STRING), the ERROR condition is signaled if the format item causes the end of the input string to be reached in the middle of an input field. If the input stream is a file declared or opened with ENVIRONMENT(IGNORE_LINE_MARKS), the search for characters to complete the input field continues at the next record.

In list-directed (GET LIST) statements, an input field is acquired by examining the input stream for the next character that is not a space character. The following actions are taken depending on the character found:

If the GET LIST statement attempts to read a file after its last input field has been read, or if it attempts to read an empty file, the ENDFILE condition is signaled. If the GET LIST statement attempts to read a character string after its last field has been read, or if it attempts to read a null string, the ERROR condition is signaled.

9.2.3 Output by the PUT Statement

The PUT statement transfers data from the program to the output stream. The output stream can be either a stream file or a character-string variable. The output file can be a declared file or the default file SYSPRINT.

This entry describes the syntax, options, and execution of PUT statements.

9.2.3.1 Syntax Summary of the PUT Statement

The PUT statement has several forms; they are:


*Syntax elements common to two or more forms

output-source

A construct that specifies one or more expressions to be placed in the output stream. Multiple output sources must be separated by commas.

An output source has the following forms:

expression 

The expression is of any computational type, including a reference to a scalar or aggregate variable. If the reference is to an array, data is output from array elements in row-major order. If the reference is to a structure, data is output from structure members in the order of their declaration.

(output-source,... DO reference=expression
[TO expression][BY expression][WHILE(expression)][UNTIL(expression)])

Another form is:

(output-source,... DO reference=expression
[REPEAT expression][WHILE (expression)][UNTIL(expression)])

The output source can be any of these forms, and the references and expressions are as for the DO statement. Notice that the parentheses surrounding this form of output source are in addition to the parentheses surrounding the entire output-source list.

For a discussion of the matching of format items to output sources and of the use of DO specifications, see Section 9.2.4.13.

format-specification

A list of format items to control the conversion of data items in the output list. Format items can be data format items, control format items, or remote format items. For each variable name in the output-source list, there is a corresponding data format item in the format-specification list that specifies the width of the output field and controls the data conversion (see Section 9.2.4.13 and Section 9.2.4).

FILE(file-reference)

An option that specifies that the output stream be a stream file; the reference is to a declared file variable or constant. If neither the FILE option nor the STRING option is specified, PL/I uses the default file SYSPRINT. SYSPRINT is associated with the default system output file SYS$OUTPUT, which in turn is generally associated with the user's terminal.

If a file is specified, and it is not currently open, PL/I opens the file with the attributes STREAM and OUTPUT.

PAGE

An option that advances the output file to a new page before any data is transmitted. The PAGE option can be used only with implied or explicit print files. The file is positioned at the beginning of the next page, and the current page number is incremented by 1. The PAGE, LINE, and SKIP options are always executed, in that order, before any other output or file-positioning operations. The page size is either the default value or the specific value that you have established for the file (See Section 9.1.3). The PAGESIZE option can be used only with print files.

LINE (expression)

An option that advances the output file to a specified line. You can use the LINE option only with implied or explicit print files. The expression must yield an integer i. Blank lines are inserted in the output file such that the next output data appears on the ith line of a page.

If the file is currently positioned at the beginning of line i, no operation is performed by the LINE option.

If the file is currently positioned before line i, and i is less than or equal to the page size, then blank lines are inserted following the current line until line i is reached.

If the file is currently positioned at or beyond line i, and the file is not at the beginning of line i, then the remainder of the page (the portion between the current line and the current page size) is filled with blank lines. The ENDPAGE condition is signaled.

When the LINE option is used within an ENDPAGE ON-unit, it causes a skip to the next page.

SKIP [(expression)]

An option that advances a specified number of lines from the current line. You can use the SKIP option only with the implied or explicit FILE option. The expression must yield an integer i, which must not be negative and must be greater than zero except for print files. If the expression is omitted, i equals 1.

If the file is not a print file, i-1 blank lines are inserted following the current line, and subsequent output of data begins at the beginning of (current line)+i.

If the file is a print file, i=0 causes a return to the beginning of the current line. If i is greater than zero, and either the current line exceeds the page size or the page size is greater than or equal to the current line plus i, then i-1 blank lines are inserted. Otherwise, the remainder of the current page is filled with blank lines, and the ENDPAGE condition is signaled.

On output devices with the space-suppression feature, SKIP(0) can be used to cause overprinting, underscoring, and so forth. For further information on pages in stream files, see Section 9.2.6.

OPTIONS (CANCEL_CONTROL_O)

A statement option that can be included only with the implied or explicit FILE option. The option is described fully in the Kednos PL/I for OpenVMS Systems User Manual.

STRING(reference)

An option that specifies that the output stream be the referenced character-string variable. The STRING option cannot be used in the same statement with FILE, OPTIONS, PAGE, LINE, or SKIP.

9.2.3.2 PUT EDIT

The PUT EDIT statement takes output sources (variables and expressions) from the program, converts the results to characters under control of a format specification, and places the resulting character strings in the output stream. The output stream is either a stream file or a character-string variable.

With PUT EDIT, the format of the output data is controlled by the program.

The form of the PUT EDIT statement is as follows:


The syntax is described in more detail in Section 9.2.3.1.

Examples


PUTE: PROCEDURE OPTIONS(MAIN); 
 
DECLARE SOURCE FIXED DECIMAL(7,2); 
 
DECLARE OUTFILE PRINT FILE; 
 
OPEN FILE(OUTFILE) TITLE('PUTE.OUT'); 
 
SOURCE = 12345.67; 
 
PUT SKIP FILE(OUTFILE) EDIT(SOURCE) (F(8,2)); 
PUT SKIP FILE(OUTFILE) EDIT(SOURCE) (E(13)); 
PUT SKIP FILE(OUTFILE) EDIT(SOURCE) (A); 
PUT SKIP FILE(OUTFILE) EDIT('American: ',SOURCE) 
      (A,P'ZZ,ZZZV.ZZ'); 
PUT SKIP FILE(OUTFILE) EDIT('European: ',SOURCE) 
      (A,P'ZZ.ZZZV,ZZ'); 
 
END PUTE; 

The program PUTE writes the following output to PUTE.OUT:


12345.67 
 1.234567E+04 
  12345.67 
American: 12,345.67 
European: 12.345,67 

9.2.3.3 PUT LINE

The PUT LINE statement advances a print file to a specified line. Its format is as follows:

PUT [FILE (file-reference)] LINE (expression); 

file-reference

A reference to the file to which the statement applies. The file must be a print file.

The syntax is described in more detail in Section 9.2.3.1.

9.2.3.4 PUT LIST

The PUT LIST statement specifies a list of output sources (variables and expressions) whose results are converted to character strings and transmitted to the output stream. If the output file is a print file, the output character strings are placed at the start of the next tab stop, where a tab stop is in column 1, 9, 17, and so on. Otherwise, the strings are separated by spaces.

With PUT LIST, the conversion of the output sources and formatting of the output data are automatic and follow the PL/I rules for conversion to character strings.

The form of the PUT LIST statement is as follows:


The syntax is described in more detail in Section 9.2.3.1.

Examples


PUTL: PROCEDURE OPTIONS(MAIN); 
 
DECLARE I FIXED BINARY, 
        F FLOAT, 
        P PICTURE '99V.99', 
        S CHAR(10); 
 
DECLARE INFILE STREAM INPUT FILE; 
DECLARE OUTFILE PRINT FILE; 
 
OPEN FILE(INFILE) TITLE('PUTL.IN'); 
OPEN FILE(OUTFILE) TITLE('PUTL.OUT'); 
 
GET FILE(INFILE) LIST (I,F,P,S); 
PUT FILE(OUTFILE) SKIP LIST (I,F,P,S); 
 
END PUTL; 

Assume that the file PUTL.IN contains the following data:


2,3.54,22.33,'A string' 
Then the program PUTL writes the following output to PUTL.OUT:


    2   3.5400000E+00  22.33   A string 

For print files, each output item is written at the next tab position. Floating-point values are represented in floating-point notation. Character values are not enclosed in apostrophes.

9.2.3.5 PUT PAGE

The PUT PAGE statement positions the output file at the start of a new page. This statement is valid only for print files, that is, files that have been opened with the PRINT attribute.

The form of the PUT PAGE statement is:

PUT [FILE(file-reference)] PAGE; 

The syntax is described in more detail in Section 9.2.3.1.

Example


PUT FILE(REPORT) PAGE SKIP LINE(2); 

The PUT statement advances the file REPORT to the beginning of the next page, advances to line 2, and skips to the beginning of the next line (3).

9.2.3.6 PUT SKIP

The PUT SKIP statement positions the output file at the start of a new line.

The form of the PUT SKIP statement is as follows:

PUT [FILE(file-reference)] SKIP [(expression)]; 

The syntax is described in more detail in Section 9.2.3.1.

9.2.3.7 Execution of the PUT Statement

When a PUT statement is executed, the first action is to evaluate the FILE or STRING option, if there is one. If the statement has a FILE option and is not already open, the referenced file is either opened or created with the STREAM and OUTPUT attributes. The file is opened if it has the APPEND attribute; otherwise, it is created.

If neither the FILE option nor the STRING option is present, the output stream is assumed to be the default file SYSPRINT.

If the output stream is a file, the next action is to execute any of the options PAGE, LINE, and SKIP that occur in the statement, in that order. The output stream must be a file if any of these options are included, and it must be a print file if LINE or PAGE is included. Note that a PUT statement can contain one or more of these options even if it performs no data output. For example:


PUT FILE(OUT) PAGE LINE(20); 
This statement skips to a new page in the file referenced by OUT (which must be a print file), moves to line 20 of the file, and then terminates.

However, if the statement also has a LIST or EDIT option, it then writes out a list of output sources, which must be variables, constants, or other expressions of computational data types. Because a stream consists only of ASCII characters, each output source is converted to a character string before being written out, as follows:

The converted output source is then written to the output stream, as follows:

9.2.4 Format Items

In PL/I, formatted input and output data is transferred with the GET EDIT and PUT EDIT statements, which include a format specification made up of format items.

PL/I format items are categorized as follows:

The data format items refer to a field of characters in the stream. Each data format item specifies the field width in characters and either the manner in which the field is used to represent a value (output) or the manner in which the characters in the field are to be interpreted (input). Because the representation or interpretation is under control of the format items, certain symbols used in the stream with GET LIST and PUT LIST are not used with GET EDIT or PUT EDIT:

The following guidelines apply to errors and mismatches that occur between the actual data values and the fields specified by data format items:

The rest of this section describes each format item in detail. The following subsections describe format-specification lists and the FORMAT statement.


Previous Next Contents Index