![]() |
![]() |
|
|
![]() |
![]() |
KSAM/3000 Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 6 USING KSAM FILES IN BASIC PROGRAMS![]() BKOPEN |
|
A call to procedure BKOPEN initiates file processing.
In order to process a KSAM file, it must be opened with a call to the BKOPEN procedure. BKOPEN initiates processing, and optionally specifies how the file is to be processed. BKOPEN does not create the file; it must have been created previously. You can create a KSAM file through the BUILD command of the KSAMUTIL program (refer to section II). To open a file means to make it available for processing. You can also specify how the file is to be accessed (whether for input, output, input and output, or for update), whether dynamic locking is allowed, whether access to the file can be shared, and whether records written to the file are to be checked for primary key sequence. Default values are assigned for the optional parameters. If you want to change the current processing or access method, you must close the file and then open it again with the parameters set to new values.
After calling BKOPEN, you should always check the status parameter to determine whether the open was successful. Upon successful execution of BKOPEN, the file named in name is available for processing; an identification number is assigned to this file and returned to filenum where it is available to identify the open file in other calls. Until the file is successfully opened with BKOPEN, no operation can be executed that references the file either explicitly or implicitly. If only the first three parameters are specified, and the file is opened successfully, the file has the following default characteristics:
There are two types of write only access: one clears any existing records before writing the specified records to the file (access = 1); the other saves existing records and writes the new records after those already written (access =2). Both these access modes do not permit any read or update access to the file. Read-only access (access = 0) can be specified if you want to insure that the file is not changed. This mode prohibits the writing of new records, and rewriting or deleting of existing records. In read-only mode, you can position the file, and read records in either sequential or random order. The default access mode (access = 3) allows you both to read records from and write records to a file, but not to change or delete existing records. If you plan to read and write records during the same process, but do not want to alter existing records, use this access mode. If you want to rewrite or delete existing records in a KSAM file, you must open with access = 4. This mode allows you to use the BKREWRITE and BKDELETE procedures, as well as all the other procedures described in this section. Table 6-4 “Procedures Allowed by BKOPEN access Parameter” summarizes the procedures you may call depending on the access parameter value you specify in BKOPEN. Table 6-4 Procedures Allowed by BKOPEN access Parameter
By default in a multi-user envornment, all users whose MPE security restrictions allow them to access your file can read the file, but they cannot change the file or add new records to it. This is the default specification of the exclusive parameter in BKOPEN (exclusive=2). It is independent of the value of the access parameter. If you want to prevent other users from reading the file as well as writing to it, you must specify this by setting exclusive=1. This setting allows only you to read from, write to, or alter the file. Another alternative is to set exclusive=0, thereby allowing other users access to the file only when it is opened for read only (access=0). This setting of the exclusive parameter prevents any access by other users when the file is opened for any form of write or update (accesss ≠ 0) . This means that you and other users share read access to the file, but only you can write to or change the file. You can choose to completely share access to the file, reading and/or writing and updating, by setting the exclusive parameter to 3. (Refer to Table 6-5 “Relation of exclusive Parameter to access Parameter” for a summary of the relation between theexclusive parameter and the access parameter.) Table 6-5 Relation of exclusive Parameter to access Parameter
When access is shared, it is good practice to allow dynamic locking so that individual users can dynamically lock the file while performing any updates to the file. The file can be unlocked as soon as the update is complete. An update to a file is when you write a new record, delete a record, or rewrite an existing record. When access is exclusive or semi-exclusive, there is no need for dynamic locking since only the user who has opened the file can update the file. Dynamic locking should also be allowed if access is shared and you plan to read the file sequentially. This is because the sequential read procedure (BKREAD) is dependent on the position of the logical record pointer and, in a shared environment, this pointer can be changed by other users unless the file is locked (Refer to Table 6-3 “Positioning the Logical Record Pointer” for a list of the pointer-dependent procedures.) When sequence checking is specified, you must write records to the file in primary key sequence. An attempt to write a record out of sequence causes the write to fail and the value "21" is returned to status following a call to BKWRITE. (Refer to the description of Status earlier in this section.) As a result of sequence checking, the chronological and the primary key sequence of records in your file is the same. Since the BASIC KSAM procedures have no provision to read the file in chronological sequence, you may want to specify sequence checking for any file that you will want to read in that order. With sequence checking, a file read in logical order by primary key (the default for BKREAD) is also read in chronological order. The example in Figure 6-4 “Opening KSAM File with BKOPEN” shows how to use BKOPEN to open a KSAM file for input and output (default access), with dynamic locking (lock=1), for shared access (exclusive=3), and without sequence checking (default sequence). Figure 6-4 Opening KSAM File with BKOPEN
|
![]() |
||
![]() |
![]() |
![]() |
|||||||||
|