• Keine Ergebnisse gefunden

PATTERN TESTING: THE PATTERN HATCHING IF COMMAND

Im Dokument The Picl(System (Seite 164-168)

TYPE II VERB The type II verbs

5.16 PATTERN TESTING: THE PATTERN HATCHING IF COMMAND

: the pattern matching form of the IF command allows parameters in the input:

: buffers to be tested for a specific pattern match.

The pattern matching form of the IF command is an extended version of the simple IF form (see topic titled TRANSFERRING CONTROL: THE GO AND SIMPLE IF COMMANDS). The pattern matching form is as follows:

IF a-cmnd op (pattern) proc-cmnd

Where a-cmnd and proc-cmnd are as defined for the simple IF form, where op is one of the relational operators described for the relational IF form, and where pattern is a pre-defined format string enclosed in parentheses.

A pattern is used to test a parameter for a specified combination of numeric characters, alpha characters, alpha-numerIc characters, or literals. The pattern specification in an IF statement consists of any combination of the following:

An integer number followed by the letter N (which tests for that number ot numeric characters).

An integer number followed by the letter A (which tests for that number of alpha characters).

An integer number followed by the letter X (which tests for that number of alpha-numeric characters).

A literal string (which tests for that literal string of characters).

As an example, consider the following command:

If A (3NABC) G 3

This command causes a transfer of control to the command with label 3 when the current parameter of the currently active input buffer consists of three numerals followed by the characters ABC (e.g., 123ABC).

If the integer number used in the pattern is 0, the test is true only if all the characters in the parameter conform to character type. The following command, for example, outputs the message OK if the characters of the current parameter are all alpha characters:

IF A = (OA) OOK

Note that for any of the three IF command forms, the PROC statement which is conditionally executed may in turn be another IF command (i.e., IF commands may be nested). The following command, for example, transfers control to label 99 if the current parameter consists of two numerals in the range 10 through 19 (inclusive):

IF A = (2N) IF A 1 10 IF A [ 19 GO 99

The user may wish to visualize nested IF commands as though implied AND operators were placed between them.

CHAPTER 5 - PROC Copyright (c) 1985 PICK SYSTEMS PAGE 151

NOTE: The following eX&mples assume that the primary input buffer is the ourrently aotive input buffer and contains the following parameters:

: ABC 10/09/77 XYZ B123C 33

COMMAND

IF A = (3A) G 7

IF A2 = (2N/2N/2N) G 5

IF A4 (ON) G 9 IF A5 (ON) GO 2 IF A4 (lA3NC) OGOOD

IF A1 (3X) IF A1

>

ABB G 9

EXPLANATION

Control is transferred to the command with label 7.

Control is transferred to the oommand with label 5

Control continues with next sequential command.

Control is transferred to the oommand with label 2.

The message GOOD is output to the terminal; control continues with next sequential command.

Control is transferred to the command with label 9.

Sample Usage of Pattern Matohing IF Command.

CHAPTER 5 - PROC Copyright (c) 1985 PICK SYSTEMS PAGE 152

5.17 FURTHER FORMS OF THE IF COMMAND: THE IF E and IF S COMMANDS and SELECT LIST AND PROC INTERACTION

The IF E form of the IF command may be used to test for errors generated by a preceding PROC-generated statement. The IF S form of tho IF command may be used to test whether a LIST. as generated by a SELECT. SSELECT.

QSELECT or GET-LIST statement. is in effect.

J'ORMAT:

IF (#]E (op string] proc-cmnd

'Where "op string" &nd "proc-cmnd" a.re &8 defined previously.

This command allows PROCs to test for system generated orrors (as specified in the ERRMSG file). The E command is Talid only after a P type command. that is. when a PROC-generated statement has completed execution.

and control is returned to the PROC. The E command use. the .econdary input buffer. and therefore is valid only until an "IS" command i, executed.

The errors tested for may be unspecified (i.e. Any error) or they may b.

specified by the error number. The relational operators "=". ">".

"<" .

.. [ ... ] .. may also be used to test for errors in specified ranges. Thus the error command may be used in two ways. An examplo of the first would be :

016 IF E X ENCOUNTERED AN ERROR AT LINE 15

whouby control will transfer to TCL and the text "ENCOUNTERED AN ERROl! AT LINE 15" will be printed if any error were encountered.

An example of a statement that tests for an error range is 015 IF E 91 IF E

<

99 X TAPE ERROR!

in which case control will transfer to TCL and the text will be printed if an error in the range 92-98 had been encountered.

There are certain TCL statements that select lists of item-ids or Talue ••

such a8 SELECT. SSELECT. QSELECT and GET-LIST. Refer to the appropriato areas of the documentation for details regarding these statemonts. There ia an important interaction between these statoments and a PROC. • selected list must be used by the TCL statement immediately following it.

or el •• it will be lost. If the select-type statement h~s been exocuted by a PROC. the TCL statement that uses it is normally placed in the STACK prior to execution of the select statement. This second TCL statement will automatically execute after the select is complete; the PROC will not gain control in between! If there is a null line in the STACK. the PROe will then regain control. The PROC may then test if the select statement executed correctly.

CHAPTER 5 - PROC Copyright (c) 1985 PICK SYSTEMS PAGE 153

The general form of the IF S command is:

IF {#JS proc-cmnd where proc-cmnd is any PROC command.

This command will test for the presence of a selected-list; the selected list will be present only if a select-type TCL statement has already been executed at the time that the IF S command is encountered.

If the select statement has generated an error, such as "NO ITEMS PRESENT"

or "ITEM NOT ON FILE", the select list will not exist, and the IF S may be used to check on this condition.

TESTI TEST2

001 PQ 001 PQ

002 HGET-LIST 002 HGET-LIST

003 OENTER LIST-NAME+ 003 ENTER LIST-NAME+

004 IP? 004 IP?

005 A 005 A

006 STON 006 STON

007 H< 007 HLIST INVENTORY LPTR

008 P 008 P

009 IF #S XILLEGAL LIST-NAME! 009 next statement 010 HLIST INVENTORY LPTR

all P

012 next statement

The PROCs TESTI and TEST2 will operate identically if the GET-LIST statement executes without an error (that is, if the list exists on file).

However, TEST2 will continue with PROC execution even if the list is not on file, since there cannot be an IF S test after the stacked LIST statement executes. TESTl, on the other hand, has a null line in the stack when the GET-LIST executes; therefore, control is returned to the PROC, which can test to see if it executed properly. If the list is not on file, the PROC will terminate on line 10.

Sample usage of the IF S command, and of PROC-SELECT interface.

CHAPTER 5 - PROC Copyright (c) 1985 PICK SYSTEMS PAGE 154

5.16 ADDITIONAL FEATURES: THE PLUS (+), MINUS (-), U AND C COMMANDS

Im Dokument The Picl(System (Seite 164-168)