• Aucun résultat trouvé

Example of Use of ON-Conditions

Dans le document PL/I System/360 (Page 181-184)

The routine shown in Figure 13-1

illustrates the use of the ON statement, the SIGNAL and REVERT statements, and condition prefixes. The routine reads batches of cards containing test readings.

Each batch has a header card with a sample therefore inserted just before the

procedure statement heading INPUT. This check list specifies the labels in INPUT, and the array TABLE.

It is worth noting again that the CHECK condition prefix can be applied only to PROCEDURE and BEGIN blocks, and not to individual statements. The first statement executed is the ON ENDFILE statement in card 9,. This specifies that the external procedure SUMMARY is to be called when an ENDFILE interrupt occurs. This action applies within DIST and within INPUT and within all other procedures called by DIST.

unless they establish their own action for ENDFILE..

Throughout the procedure, any conditions except SIZE, SUBSCRIPTRANGE, STRINGRANGE, and CHECK are enabled by default; and for all conditions except those mentioned explicitly in ON statements" the system interrupt occurs. since this action

consists of more than one statement, i t is bracketed by BEGIN and END statements.

The main loop of the program starts with the statement HEADER. Since the CHECK condition is enabled for HEADER, an interrupt will occur before HEADER is executed. The READ statement with the INTO option will cause a CHECK condition to be raised for the variable specified in the INTO option (unless:, for the F Compiler, the EVENT option is used); consequently, the input is listed in the form of

data-directed output.

The card read is assumed to be a header card.. If i t is not, the SIGNAL CONVERSION statement causes execution of the BEGIN block, which in turn calls a procedure (not shown here) that reads on, ignoring cards until i t reaches a header card. The begin block ends with a GO TO statement that terminates-the on-unit.

The GET statement labeled NEWBATCH uses the STRING option to get the different test numbers that have been read into the

r---1

I

(CHECK(HEADER,NEWBATCH,INPUT,BADBATCH,SAMPLE»: /*DEBUG*/ 01

I

DIST: PROCEDURE; 02

I

DECLARE 1 SAMPLE EXTERNAL, 03

l

2 BATCH CHARACTER(6), 04

I 2 SNO PICTURE'9999-, OS

I

2 READINGS CHARACTER(70)" 06

TABLE(15,lS) EXTERNAL; 07

/* ESTABLISH INTERRUPT ACTIONS FOR ENDFILE S CONVERSION */ 08

ON ENDFILE (PDATA) CALL SUMMARY: 09

ON CONVERSION BEGIN: CALL SKIPBCH: 10

GO TO NEWBATCH; 11

END: 12

ON ERROR DISPLAY(BATCHIISNOIIREADINGS): 13

/* MAIN LOOP TO PROCESS HEADER & TABLE */ 14

HEADER: READ INTO (SAMPLE) FILE (PDATA): 15

/* THE CHECK ACTION LISTS INPUT DATA FOR DEBUG */ 16

IF SNO , = 0 THEN SIGNAL CONVERSION: 17

NEWBATCH: GET LIST (OMIN,OINT,AMIN,.AINT) STRING (READINGS): 18

TABLE = 0: 19

CALL INPUT: 20

CALL PROCESS: 21

GO TO HEADER: 22

/* ERROR RETURN FROM INPUT */ 23

BADBATCH: SIGNAL CONVERSION: 24

(CHECK (IN1, IN2 .• ERR2.ERRl ,TABLE» : /*DEBUGIi=/ 25

INP'aT: PROCEDURE: 26

/* ESTABLISH INTERRUPT ACTIONS FOR CONVERSION & SUBRG */ 27

ON CONVERSION BEGIN: 28

IF ONCODE = 624 & ONCHAR = ,1 -,I 29 THEN DO: ONCHAR

= I'

O' # 30

GO TO ERRl; 31

END: 32

ELSE GO TO BADBATCH: 33

END: 34

ON SUBSCRIPTRANGE GO TO ERR2: 35

/* LOOP TO READ SAMPLE DATA AND ENTER IN TABLE */ 36

IN1: READ INTO (SAMPLE) FILE (PDATA); 37

IF SNO= 9999 THEN RETURN: /*TRAILER CARD*/ 38 IN2: GET EDIT (R,OMEGA,ALPHA) (3 PI 999,1) 39

STRING (READINGS); 40

(SUBSCRIPTRANGE): TABLE«OMEGA-OMIN)/OINT,(ALPHA-AMIN)/AINT)

=

R: 41

GO TO IN1: 42

/* FIRST CONVERSION

&

SUBSCRIPrRANGE ERROR IN THIS BATCH */ 43 ERR2: ON SUBSCRIPTRANGE GO TO BADBATCH; /*FORNEXT ERROR*/ 4,4

CALL ERRMESS(SAMPLE,02); 45

GO TO IN1: 46

ERR1: REVERT CONVERSION: /*SWITCH FOR NEXT ERROR*/ 47

CALL ERRMESS(SAMPLE,Ol): 48

GO TO IN2.: 49

END INPUT: 50

END DIST: 51

_____________________________________________________ ~----___________________________ -1

Figure 13-1. A Program Checkout Routine

character string READINGS, which is an element of SAMPLE. Since the variables named in the data list are not explicitly declared, their appearance causes implicit declaration with the attributes FLOAT DECIMAL (6).

The array TABLE is initialized to zero before the procedure INPUT is called. This procedure inherits the on-units already established in DIST, but i t can override them.

The first statement of INPUT establishes a new action for CONVERS ION interrupts ,.

Whenever an interrupt occurs, the ONCODE is tested to check that the interrupt is due to an illegal P format input character and that the illegal character is a blank. If the illegal character is a blank, i t is replaced by a zero, and control is transferred to ERR!.

ERR1 is internal to the procedure INPUT,.

The statement, REVERT CONVERSION, nullifies the ON CONVERSION statement executed in INPUT and restores the action specified for conversion interrupts in DIST (which causes the batch to be ignored).

After a routine is called to write an error messagel, control goes to IN2, which retries the conversion. If another

conversion error occurs, the interrupt action is that specified in cards 10 and 11.

The second ON statement in INPUT

establishes the action for a SUBSCRIPTRANGE interrupt. This condition must be

explicitly enabled by a SUBSCRIPTRANGE prefix-for an interrupt to occur. If an interrupt does occur" the on-unit causes a transfer to ERR2" which establishes a new on-unit for SUBSCRIPTRANGE interrupts, overriding the action specified in the ON statement -in card 35,. Any subsequent subscript errors in this batch will,

therefore, cause control to go to BADBATCH, which signals the CONVERSION condition as i t existed in the procedure DIST,. Note that on leaving INPUT, the on-action reverts to that established in DIST, which in this case calls SKIPBCH to get to the next header card,.

After establishment of a new on-unit, a message is printed, and a new sample card is read,. '

The statement labeled IN! reads an 80-column card image into the structure SAMPLE. A, READ statement does not cause input data to be checked for validity, so the CONVERSION' condition cannot arise.

The statement IN2 checks and edits the data in card columns 11 through 19

according-to the picture format item. A non-numeric character (including blank) in these columns will cause a conversion interrupt, with the results discussen above.

The next statement (card 41) has a SUBSCRIPTRANGE prefix. The data just read is used to calculate a double subscript.

If either subscript falls outside the bounds declared for TABLE, an interrupt occurs. If both fall outside the range, two interrupts occur.

Chapter 14: Based Variables and List Processing

The purpose of

thi~

chapter is to describe

Dans le document PL/I System/360 (Page 181-184)