| Previous | Contents | Index |
| Example 15-3 OPEN STRUCTURE |
|---|
open structure cl: name 'sheerpower:samples\client', &
access input, lock
extract structure cl
include cl(state) = 'CA'
exclude cl(phone)[1:3] = '619'
sort ascending by cl(last)
end extract
print 'List of California clients by last name'
for each cl
print cl(first); ' '; cl(last), cl(phone)
next cl
close structure cl
end
List of California clients by last name
Dale Derringer (818) 223-9014
Earl Errant (408) 844-7676
|
The OPEN STRUCTURE statement is used to open a data structure. The structure must be open in order to reference data in the structure (i.e. change field data, add or delete records). struc_name is a name (i.e. nickname) you assign to the structure. You use this name to refer to the structure within the program. The structure name must be unique within the program or program system. If the structure name is associated with another open structure, an exception is generated. The structure name must meet the requirements for variable names.
After the keyword NAME, is the file specification of the structure file being opened. (See Chapter 16, Database Setup for information on legal structure file names.) The file specification can be any valid string expression.
The ACCESS option tells SheerPower whether to open the structure for input (reading field data) or for input and output (reading, changing and adding field data). ACCESS input is the default open mode for structures, meaning, that if no ACCESS option is provided, SheerPower opens the structure for INPUT.
When SheerPower executes the OPEN statement, it searches for the structure file specified. SheerPower opens the structure and assigns it the structure name. If the structure file does not exist, an exception is generated.
The ACCESS option determines how you can access the structure.
The access options are:
The LOCK option causes SheerPower to lock the structure from write access by others. As long as the structure is open, the structure cannot be modified by others. This can speed up SheerPower's structure statements (EXTRACTs especially). The particular effect depends on the file management system being used.
The DATAFILE option overrides the default datafile as specified by the structure.
DATAFILE file_spec
|
file_spec is the file specification of the data file you want to open. The file_spec can be any string expression.
15.3 CLOSE STRUCTURE struc_name
CLOSE STRUCTURE struc_name
|
| Example 15-4 CLOSE STRUCTURE |
|---|
open structure cl: name 'sheerpower:samples\client'
extract structure cl
include cl(state) = 'CA'
exclude cl(phone)[1:3] = '619'
sort ascending by cl(last)
end extract
print 'List of California Clients'
for each cl
print cl(first); ' '; cl(last), cl(phone)
next cl
close structure cl
end
List of California Clients
Dale Derringer (818) 223-9014
Earl Errant (408) 844-7676
|
CLOSE STRUCTURE closes a structure from further access. Once the structure is closed, you cannot reference records or add them, and you cannot change field data. struc_name is the name associated with the structure, the name assigned with the OPEN statement.
You can use the statement CLOSE ALL to close all open structures and other files.
ADD STRUCTURE struc_name
---
[LET] struc_name(field) = expr
---
END ADD
|
| Example 15-5 ADD STRUCTURE/END ADD - Add structure record |
|---|
open structure cl: name 'sheerpower:samples\client', access outin
input 'Enter ID number': id%
input 'Enter last name': last$
input 'Enter first name': first$
input 'Enter state': state$
input 'Enter phone': phone$
add structure cl
print
print 'Adding '; last$; ', '; first$
let cl(id) = id%
let cl(last) = last$
let cl(first) = first$
let cl(state) = state$
let cl(phone) = phone$
end add
close structure cl
end
Enter ID number? 12233
Enter last name? Jones
Enter first name? Tom
Enter state? NV
Enter phone? 2345556161
Adding Jones, Tom
|
ADD STRUCTURE adds a record to a structure. The ADD STRUCTURE statement begins the add block. struc_name is the name associated with the structure that the record is going to be added to. END ADD marks the end of the block.
When ADD STRUCTURE is executed, SheerPower executes the block of code between the ADD STRUCTURE statement and END ADD. This block of code with LET statements is used to put data into the fields.
LET assigns a value to the field specified. struc_name(field) specifies a field in the structure. expr is an expression. When SheerPower executes the LET statement, it evaluates the expression and assigns the value of this expression to the field specified. END ADD writes out the new record.
CANCEL ADD
|
| Example 15-6 CANCEL ADD - Cancel adding a structure record |
|---|
open structure cl: name 'sheerpower:samples\client', access outin
add structure cl
input 'Client ID': cl(id)
if _exit then cancel add
input 'Last name': cl(last)
if _exit then cancel add
input 'First name': cl(first)
if _exit then cancel add
print 'Adding client'
end add
end
Client ID? 14422
Last name? White
First name? exit
|
CANCEL ADD immediately transfers control to the next statement after the END ADD statement, without adding any of the current record to a structure.
This statement can be used only within an ADD block---that is, between an ADD STRUCTURE and an END ADD pair of statements.
EXIT ADD
|
| Example 15-7 EXIT ADD - Exit when adding a structure record |
|---|
open structure cl: name 'sheerpower:samples\client', access outin
add structure cl
input 'Client ID ': cl(id)
input 'Last name ': cl(last)
input 'First name': cl(first)
input 'Contact ': cl(contact)
if _exit then exit add
input 'Salesman ': cl(salesman)
input 'Mother ': cl(mother)
input 'Comment ': cl(comment)
end add
print 'Client added'
end
Client ID ? 11111
Last name ? Hollerith
First name? Herman
Contact ? exit
Client added
|
EXIT ADD transfers control immediately to the corresponding END ADD statement and ADDS the record to the structure.
This statement is useful when you want to add a record but do not have all the data. You can enter data into the first few fields and skip the rest of the fields.
DELETE STRUCTURE struc_name
|
| Example 15-8 DELETE STRUCTURE - Delete structure record |
|---|
open structure cl: name 'sheerpower:samples\client', access outin
add structure cl
input 'Client ID ': cl(id)
input 'Last name ': cl(last)
input 'First name': cl(first)
input 'Contact ': cl(contact)
input 'State ': cl(state)
end add
print 'Client added'
delay
extract structure cl
include cl(state) = 'PA'
end extract
// delete all clients from Pennsylvania
for each cl
print 'Deleting '; cl(first); ' '; cl(last) ;'...';
delete structure cl
print 'record deleted'
next cl
close structure cl
end
Client ID ? 87433
Last name ? Shores
First name? Sandy
Contact ? 8435557373
State ? PA
Client added
Deleting Sandy Shores...record deleted
|
| Previous | Next | Contents | Index |