Search    
 

   
 

 
PRAGMA PROGRAM REFERENCE MANUAL
Index
All Operation

Expand All      ADDENDUM
BEGIN BG Standard Verb File Access Operation
Target = EXTERNAL ECHO (XE)

Positions a file pointer directly ahead of the record referenced by NAME.
BEGIN merely positions a file pointer, so that the subsequent GET NEXT will
access the record. If the file does not contain a record with the referenced
expression, the GET NEXT statement will access the next existing record in the
file.

BEGIN at position NAME in file FILE

NAME identifies the record that you want to access. It can be a noun or an
expression.
FILE is the name that contains the record.

SEE ALSO: GET NEXT / BEGIN THIS

DISCUSSION

BEGIN merely positions a file pointer; it does not GET or SAVE a record. The pointer is placed directly ahead of the indicated record, so the subsequent GET NEXT will access the record. Consider the following statements:


BEGIN at position NAME in file ADDRESSES
GET NEXT in file ADDRESSES


The first statement tells PRAGMA to position the file pointer ahead of the record referenced by NAME. The second statement tells PRAGMA to get the next record, which is the one referenced by NAME, provided that such a record exists.

The file you name does not actually have to contain a record with the referenced number or expression. The next GET NEXT will still access the next existing record in the file. For example, suppose the references in file ACCOUNTS are 600, 700, and 800. The following statements will result in record 700 being accessed.


BEGIN at position 650 in file ACCOUNTS
GET NEXT in file ACCOUNTS


It does not matter to PRAGMA that record 650 does not exist. The next record it gets will be record 700.


EXAMPLES

1. The following example shows the verb RUN ALL STATEMENTS. This verb prints a statement for each record in the file ACCOUNTS and prints out the totals for all statements. The verb BEGIN is used to position the file pointer ahead of the first record in the file ACCOUNTS. Records are accessed via GET NEXT in the verb STATEMENT LOOP; accessing continues until the end of the file is reached.


VERB called RUN ALL STATEMENTS
1 STATEMENT HEADING
2 CLEAR STATEMENT TOTALS
3 BEGIN FIRST in file ACCOUNTS
4 STATEMENT LOOP
5 SHOW STATEMENT TOTALS


Line 1 calls the verb STATEMENT HEADING; the verb prints a heading. Line 2 calls the verb CLEAR STATEMENT TOTALS; the verb clears all statement totals to zero, so new totals can be calculated. Line 3 contains the BEGIN FIRST statement that positions the file pointer ahead of the first record. Line 4 calls the verb STATEMENT LOOP, shown below.

The verb STATEMENT LOOP accesses each record in the file and prints it; the verb returns to RUN ALL STATEMENTS after printing the last record.


VERB called STATEMENT LOOP
1 GET NEXT in file ACCOUNTS
2 STATEMENT PRINTING
3 REPEAT


2. A BEGIN statement can be used to position the file pointer at any record in a file. The following verb, which prints account statements, shows this.


VERB called RUN SOME STATEMENTS
1 DISPLAY LINE FEED
2 DISPLAY the value "Start with account number: "
3 INPUT into the noun START#
4 DISPLAY the value "End with account number: "
5 INPUT into the noun END#
6 IF the value START# ">" the value END#
do
REPEAT
else
end
7 COMMENT text is If starting# = ending#, will do one statement.
8 BEGIN at position START# in file ACCTS
9 STATEMENT HEADING
10 STATEMENT LOOP
11 SHOW STATEMENT TOTALS


Line 1 causes a carriage return and line feed. Lines 2-5 ask you for starting and ending account numbers. Line 6 tests whether the starting number is in the file; if it is not, lines 1-5 are repeated. Line 8 positions the file pointer at the record with the starting account number. Line 9 prints a statement heading. Line 10 calls the verb STATEMENT LOOP (shown next). Line 11 prints statement totals.


VERB called STATEMENT LOOP
1 GET NEXT in file ACCOUNT
2 IF the value ACC NO ">" the value END#
do
RETURN
else
end
3 STATEMENT PRINTING
4 REPEAT


Line 1 retrieves records, beginning with the starting account number and continuing through the ending account number. When the ending number is reached, line 2 returns to RUN SOME STATEMENTS. Line 3 prints statements. Line 4 repeats lines 1-3.


 

CustomWare® is a registered trademark of CustomWare Designs, Inc. All rights reserved.
CustomWare® is a registered servicemark of CustomWare Designs, Inc.  All rights reserved.
All images and designs on this web site are copyrighted© 2021.
v t