• Aucun résultat trouvé

BEGIN-END Statement

Dans le document Digital Equipment tion (Page 98-102)

BEGIN-END

5.8 BEGIN-END Statement

Function

Groups DATATRIEVE statements into a single compound statement called a BEGIN-END block.

Format

BEGIN

END

statement -1 [statement -2]

Arguments

statement

Is a DATATRIEVE statement. Within the BEGIN-END block, terminate each statement with a semicolon, a RETURN, or both.

Restrictions

• Do not use FIND, SELECT, or DROP statements in a BEGIN-END block.

• Observe all restrictions on statements included in the BEGIN-END block. This manual lists these restrictions in the descriptions of the various statements.

• Do not use DATATRIEVE commands in a BEGIN -END block. You cannot include a procedure that contains DATATRIEVE commands, nor can you invoke a command file that contains DAT ATRIEVE commands in a BEGIN-END block.

• Do not store a command file invocation in a BEGIN-END block. When you type . @file-name within a BEGIN-END block, DATATRIEVE immediately

executes the command file, and all the statements in the file become part of the BEGIN-END block just as though you had typed them yourself.

Results

• DATATRIEVE executes statements in a BEGIN-END block in sequential order.

• When the BEGIN-END block includes a DECLARE statement, the variable it defines is a local variable. You cannot refer to a local variable from outside the BEGIN-END block. DATATRIEVE automatically releases all local variables when it finishes executing the BEGIN-END block in which they are defined.

BEGIN-END

Continued

• Ifa BEGIN-END block that defines a local variable is in a FOR loop or

REPEAT statement, DATATRIEVE initializes the local variable each time it executes the BEGIN-END block. The variable is initialized to zero ifnumeric or blank if string. See Section 5.11 for information about the DECLARE state-ment.

• When you create a single BEGIN-END block interactively, DATATRIEVE prompts you, after you press RETURN, for the elements needed to complete an individual statement or to complete the block. The CON> prompt indicates that DATATRIEVE is ready for you to continue entering statements or ele-ments of stateele-ments into the BEGIN-END block. After you enter END, DATATRIEVE executes all the statements in the BEGIN-END block. When DATATRIEVE completes the last statement in the BEGIN -END block, you see the DTR> prompt indicating you have returned to DATATRIEVE command level.

• When you are entering nested BEGIN-END blocks interactively,

DATATRIEVE does not execute any of the statements in the nested blocks until you enter the END that completes the outermost BEGIN-END block.

DATATRIEVE continues to prompt with CON> until you enter the END that completes the outermost BEGIN-END block.

• If you enter CTRL/C while DATATRIEVE is executing the statements in a BEGIN-END block, DATATRIEVE does not execute any of the remaining statements that follow in the block. DATATRIEVE treats the whole BEGIN-END block as one statement, regardless of the number of statements or nested BEGIN-END blocks it contains. Because CTRL/C cancels the execution of the current statement, it cancels the execution of the remaining outermost BEGIN-END block, regardless of the number of levels of other BEGIN-END blocks nested in it.

• Ifa statement in a BEGIN-END block prompts for a value and you enter a CTRL/C, DATATRIEVE reprompts for the value. To end the execution of a BEGIN -END block, enter CTRL/Z in response to the prompt. DATATRIEVE then stops executing the outermost BEGIN -END block and returns you to DATATRIEVE command level.

Usage Notes

• You can use a BEGIN-END block anywhere you can use a DATATRIEVE statement.

• You can nest BEGIN-END blocks. The only limit to the number of levels of nested BEGIN-END blocks you can form is the amount of system pool avail-able at any given time. If you exceed this limit, DATATRIEVE stops executing statements and signals an error. Your only option at this point is to reduce the levels of BEGIN-END block nesting.

• To repeat an entire sequence ofDATATRIEVE statements, put the statements in a BEGIN-END block, and put the BEGIN-END block in a REPEAT

state-BEGIN-END

Continued

• To repeat all statements in a procedure, invoke the procedure in a BEGIN-END block, and put the BEGIN-BEGIN-END block in a REPEAT statement. If you invoke a procedure in a REPEAT statement (REPEAT n :procedure-name), DAT ATRIEVE repeats the first statement of the procedure n times and then executes the other statements in the procedure one time each.

• Use a BEGIN-END block to include more than one DATATRIEVE statement in a FOR loop.

• Use a BEGIN-END block to include more than one DATATRIEVE statement in the THEN and ELSE clauses in an IF-THEN-ELSE statement.

• When storing or modifying records, use BEGIN-END blocks to include more than one statement in the USING and VERIFY USING clauses of the STORE and MODIFY statements.

• When you invoke a procedure that uses consecutive PRINT statements to for-mat output, the line spacing changes when you invoke the procedure in a BEGIN -END block. The one blank line between the result of each PRINT statement disappears. To preserve that spacing when you include the proce-dure in a BEGIN-END block, edit the proceproce-dure and insert a SKIP print list element at the beginning of the second and each succeeding PRINT statement.

Examples

Store five records in the domain PHONES, each having LOCATION MBI-H2 and DEPARTMENT CEo The SET NO PROMPT command suppresses the.

~~[Looking for ... ]" prompts that precede each CON> prompt. This example also shows how DAT ATRIEVE responds to CTRL/Z when prompting for input:

DTR> SHOW PHONESOO) DOMAIN PHONES

USING PHONE_REC ON PHONE.OAT;

DTR> SHOW PHONE-RECOO) RECORD PHONE_REC

DTR> READY PHONES WRITEffi) DTR> SET NO PROMPTOO)

Enter NUMBER: 555-124300) Enter NAME: KARENOO) Enter NUMBER: 423-888100) Enter NAME: "'z

*.NAMEOO)

*.NUMBEROO) IIMB1-H21100) II CE 1100)

Execution terMinated by operator DTR>

BEGIN-END

Continued

Use a BEGIN -END block to put three statements in the USING clause of a MODIFY statement. Print a YACHTS record, modify the price, and print the result of the modification and the next record to modify:

DTR> READY YACHTS WRITE@

Execution terminated by operator DTR>

Use a BEGIN-END block in a REPEAT statement to repeat an entire procedure:

DTR> SET NO PROMPT(@)

DTR> DEFINE PROCEDURE LOOP_EXAMPLE@

DFN> PRINT II Sh 0 .... ' ho .... ' a BEGIN-END .... 'orKs ""ith REPEAT II @

CLOSE

Dans le document Digital Equipment tion (Page 98-102)