• Aucun résultat trouvé

DECLARE X FIXED, Y ENTRY, Z LABEL;

A: PROCEDURE (X,Y) FIXED;

1. OPEN PQR INPUT;

SKIP (N) FILE (PQR) 2. OPEN FILEA OUTPUT;

SKIP FILEA;

The SORT Statement Function:

The SORT statement specifies that records on a particular file are to be sorted and, optionally, merged. The sort-ing is performed on specified fields in ascending or descending order.

The general format is shown in Figure 9.

Syntax rules:

1. The options may appear in any order.

2. The UP and DOWN options may be repeat-ed as requirrepeat-ed, to specify an ascend-ing sort on some fields and a descend-ing sort on others, in the required order.

GE:neral rules:

1. The size of the records to be sorted either must be specified within the ENVIRONMENT attribute for the file name or must be implied by a record description using the RECORD specifi-cation.

2. The FILE specification specifies the files to be sorted. If more than one file name is specified, a merge is also performed.

3. The RECORD specification describes either the format of the whole record

or merely an initial portion of the record. When only an initial portion of the record is to be described, the ENVIRONMENT attribute must be declared for the file name, giving the actual length of the record or the maximum length for varying-length records.

The format list (see Chapter 7) defines fields on the record; the nth format item describes the nth field.

If a format item has an iteration factor of ~, this constitutes m fields. Of the positioning format items listed in Chapter 7, only POSI-TION is permitted; this item does not constitute a field.

4. The UP/DOWN specification indicates the sorting order. UP specifies an ascending sort; DOWN specifies a des-cending sort.

The integers in the specification are decimal integer constants that specify the fields to be sorted with respect to the record description.

The fields to be sorted are taken from the UP/DOWN specification i.n left-to-right order. The file is ordered on the leftmost specified field first, and within that ordering, on the next field, and so on.

The sort comparisons are performed using the character collating sequence for character-string fields, bit comparison for bit-string fields, and algebraic comparison for arithmetic fields.

5. The GIVING option specifies the file on which the sorted output is to be written. If omitted, the standard output file is used.

If an output file is specified that differs from the standard output file and that differs from any of the files to be sorted, the file must not be currently open. Rather the operating system opens i t for output, produces the sorted file, and closes it.

If an output file is specified that differs from the standard output file but is identical to one of the files being sorted, then, after reading the file, the operating system closes it, opens i t for output, produces the sor1ted fiIE~, and closes it.

Example:

SCR~r FILE (MASTER) , RECORD (A (1) , (6) P'99999'), UP (1,3,5) ;

~rhis SORT statement specifies that the file MASTER is to be sorted in ascending sequence. The RECORD speci-fication indicates that each record in MASTER is composed of 7 fields; the first field contains one character;

subsequent fields each contain five digits.

The records are sorted on the first, third, and fifth fields, in thai: order.

~~he sorted file is written on the standard output file.

The SPACE Statement Function:

The S]?ACE statement causes spacing over records on input files and the completion and release of records on output files.

G~:;neral format:

SPACE [(scalar-expression)] [FILE (file-name) ]

G~:;neral rules:

1. The expression, if specified, is evaluated and converted, where neces-sary, to an integer n. If the expres-SiOIl is not specifIed, i t is assumed to be 1.

2. The FILE option specifies that the action is to be taken on the named file. In the absence of a FILE option, the current file is assumed (see "Procedure-Directed Transmission"

for a discussion of current files) • 3. On input, this statement causes the

file to be positioned at the start of the nth record following the current record. On output, this statement causes the completion and release of the current record and the emission of n-1 empty records.

4. The use of SPACE on a REGIONAL or INDEXED file accessed in the DIRECT mode is limited in that an expression may not be specified. Use of SPACE in

such instances causes the current record to be released. Subsequent data transmission to or from the cur-rent file will cause the KEY and REGION values to be reevaluated in order to determine the next record to be accessed.

The STOP Statement Function:

The STOP statement causes immediate ter-mination of the major task and all sub-tasks (see IIAsynchronous Operations and Tasks," in Chapter 6) •

General format:

STOP;

The TAB Statement Function:

During data transmission, the action that occurs is as if a pointer moved across the records being processed. The TAB statement causes this pointer to be aligned on the nth tab of the record or line (see liThe LAYOUT Statement"). Intervening data is skipped.

General format:

'I'AB [(scalar-expression)]

General rule:

The "scalar expression," if specified, is evaluated and converted to an integer n.

This integer represents the nth tab for ali.gnment. If the scalar expression is omitted, the smallest tab value to the right of the current position in the record is used.

Example:

TAB (3)

Suppose the LAYOUT for the current file contains the specification TAB (10, 50, 20, 60) ; then the above statement causes a TAB to column 20 to occur, since 20 is the third tab. This may involve backing up certain character positions. If backing up has occurred, i t is meaningful to use a GET statement even on an output file; and a PUT statement Hiay be used on input files fol-lowed by TAB or POSITION to cause re-reading of a field.

If the TAB statement moves the pointer across a part of an output record which has no data edited into it, the record is assumed to be initially blank.

The WAIT Statement Function:

The WAIT statement is used-to cause the suspension of operations in the task where i t appears until certain events have been completed.

General format:

WAIT (event-name [,event-name) ••• ) [(scalar-expression)]

Syntax rule:

The event name is as described in

"Event Names," Chapter 2.

before the task issuing the WAIT statement can resume. If the value of the expression is zero or negative, the WAIT statement is treated as a null statement. If the value of the expression is greater than the number, n, of event names in the list, the value is taken to be n. If the statement refers to an array event name, then each of the array elements may contribute to the count.

Example:

PI: PROCEDURE;

CALL P2 EVENT (EP2) ;

WAIT (EP2) i

General rules: END;

1. The execution of this statement causes the task in which i t is executed to be suspended until, for some or all of the event names in the list above, the condition

EVENT (event-name) = '1'B

is satisfied. (See "Asynchronous Operations and Tasks," in Chapter 6,

"Event Names," in Chapter 2,

"Pseudo-Variables," in this chapter , and the description of the EVENT built-in function in Appendix 1.) 2. If the optional expression does not

appear, all the event names in the list must satisfy the above condition before the task issuing the WAIT statement can resume.

3. If the optional expression appears, the expression is evaluated when the WAIT statement is executed and con-verted to an integer. This integer specifies the number of events that must satisfy the above condition

The CALL statement, when executed, attaches a task whose completion sta-tus is associated with the event name EP2. When the WAIT statement is encountered, the execution of the task corresponding to PI is suspended until the value of EVENT (EP2) is '1'B, i.e., until the attached task is completed.

The WRITE Statement Function:

The WRITE statement is normally used to transmit data from internal storage to an external storage medium. However, if the STRING option is specified, the write statement causes the movement of data from one or more internal storage areas to another internal storage area.

r---,

WR.ITE ,- FILE (file-name)] {data- specification}

_ STRING (name) 1

-CROSS [(expression)]

_ SEGMENrr (expression) [KEY (expression)]

[HOLD]]

[NEWKEY (expression)] [REGION (expression)]

I I I I I I I I I

[FROM (file-name)] I I

______________________________________________________________________________ J

Figure 10. General Format for the WRITE Statement

Syntax rules::

1. The options may appear in any order.

2. At least one ndata specification" must appear, but more than one is permissi-ble. How(~ver, only one procedure-directed data specification can be givl2n, but i t may appear in conjunction with other data specifi-cations.

3. When the STRING option is used, only the data specification may appear; the othl2r options must not appear.

4. Either a "data specification" or a FRaN option must appear.

General rules:

1. The FILE option specifies the name of the file to be associated with the data transmitted.

'rhe STRING option provides for the

intl~rnal edi ting and moving of strings. It specifies the name of a string variable or the name of an element in a string array into which data is transmitted from the data list. A PICTURE attribute given for the string is ignored.

Tn the absence of a FILE or STRING option, the standard system output file is assumed.

2. The data specifications are discussed in Chapter 7. Only those forms speci-fied for output may be used. All modes of transmission may be arbitrar-ily specified together. The transmis-sions associated with each data speci-fication and edit procedure are per-formed in t:he order that the options

appE~ar.

3. Eacll WRITE statement normally process-es one record; an error condition is produced if the data specification causes the record boundary to be crossed. However, the CROSS option permits dat:a transmission to proceed through any number of records in order to satisfy the specified data

require-ments. The number of records written may be limited by the integer value of the expression in the CROSS option.

If no expression is specified, unlim-ited crossing is allowed. The margin qualifications for the data file, if specified by a LAYOUT statement, remain valid while under control of the CROSS option. Record boundary crossing due to LIST, DATA, or SEGMENT does not require the presence of the CROSS option. It may be specified, however, to limit the number of records crossed. Crossing due to SPACE, SKIP, or GROUP does require its presence.

A HOLD option permits part of one record to be processed. The HOLD option causes the position of the record pointer to be remembered on completion, so that the next WRITE begins its data scan at the point where the previous one ceased scan-ning. If a HOLD option is not speci-fied and the record is of fixed length, the remaining part of the record is padded. HOLD may not be specified for a file which is accessed in more than one task.

The SEGMENT option implies both the CROSS and HOLD options. The expres-sion in the SEGMENT option is convert-ed, if necessary, to a character string. This string serves as a seg-ment mark.

At completion of record construc-tion for the WRITE operaconstruc-tion (through one or possibly more records), the specified mark is added to the last record. Emission of the record is not thereby implied. Subsequent data is appended to this record until the maximum record length is met. A maxi-mum SEGMENT length is defined by each implementation.

4. The KEY, NEWKEY, and REGION option may be used when direct access to

a

parti-cular record is required (see "The KEY

Option," "The NEWKEY Option,- and -The REGION Option,- in Chapter 7. If a file is declared with the access attribute DIRECT, then the KEY, NEWK-EY, or REGION option must be used with each WRITE for that file unless the previous WRITE for that file had the HOLD option.

S. The FROM option specifies that the last record read from the file, the name of which is specified in the FROM option, is to be written on the output file. Data specifications given in a WRITE with the FROM option replace the initial portion of the record read from. If both the FILE option and the FROM option specify the same file, the file must be a direct access file. In this case, the KEY option may be dropped to signify that the new and old keys are the same. FROM may not be used with files accessing in two simultaneous asynchronous procedures.

6. A count. is kept of the number of scalar data items transmitted. The COUNT (file-name) built-in function may be used to determine this number of transmitted data items.

Examples:

1. WRITE FILE (INVENTORY), (ITEM. NAME, ITEM.COST) (A (20) ,F (5,2» ;

One record of the file named INVEN-TORY is written under format-directed transmission. The character-string variable ITEM. NAME is written in the first 20 characters of the record.

The variable ITEM. COST is converted to 2.

3.

4.

fixed decimal and written in the next 5 characters of the record.

WRITE FILE (TABLES) , (F (5) ) , KEY (Q);

(TABLE. POOL) A record is constructed from the contents of the TABLE. POOL array, and a key, the value of the variable Q, is appended. Should the key be identical

~o an existent key within the data file, the WRITE causes replacement of that keyed .record.

WRITE FILE (FILEZ), (' FINAL DATA', X, Y) (A, F (3,2), E (5,2» ;

-Three data items are transmitted to FILEZ (assuming X and Yare scalar variables). The first is the charac-ter string of length 10, FINAL_DATA, then the fixed-point form of the value of x, then the floating-point form of the value of Y.

WRITE DATA (X,Y,Z)

The values of the three variables X, Y, and Z are transmitted to the standard output file in the data-directed format. If X is floating-point value 3.1141593, Y is fixed-paint value 347, and Z is character-string value MATH then the output data stream would appear as the following:

X=3.1141593, Y=347, Z='MATH'

It would be in a form suitable for data-directed input.

A PL/I source program may contain compile-time variables and statements.

These may be used to effect program param-eterization and modification and iterative program generation. The name "macro" is used to describe such compile-time activi-ty. To differentiate the PL/I macro lan-guage 'from the rest of PL/I, the latter is called the Hexecution-time H language.

When a source program involves macro activity, the compiler is supplied with text consisting of a skeleton execution-time program with interspersed macro statements. This text is called the Hsource text. II Compile-time activity is

perform~ed by a part of the compiler called the Nma4C::ro processor. H The macro processor converts the source text into text rep-resentilrlg an e)cecution-time PL/I program., This cr4eated text is called "program text. II :For ease of learning, the PL/I macro statements and the variables and labels have b4een madE~ very similar to the corres-ponding execution-time entities. Wi th OnE!

exception, thE~ macro language forms a sub-set of 1the execution-time language. (The exception is the CHARACTER attribute in thE!

DECLARE statememt.)

Macro statements and skeleton execution-time text can, in general, be interspersed in any ''lay in t:he source text. Each macro statement begins with a percent sign.

Macro statements are recognized by the~

occurrence of a percent sign other than wi thin a 'comment or character string. The restric1:ions on the form of source text are as follows:

If the source program involves any macro activity, the first statement.

must be the macro DECLARE statement.

Quotation marks and comments delimiters must be matched within the skeleton execution-time program.

Beyond the requirements above there is no requirement that the skeleton execution-time program be syntactically correct.

MACRO Vl\RIABLES

If compile-time activity is to take place, t:he source text must contain one and only one macro DECLARE statement. The first character of the souzce text must be