Data Files [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Business BASIC/XL Reference Manual
Data Files
A data file contains data that an HP Business BASIC/XL program can read
or has written. The file can be stored on a disk, magnetic tape, or
cards. HP Business BASIC/XL uses program files as well as data files.
The material in this section applies only to data files, unless otherwise
noted. See chapter 2 for information about program files.
The following summarizes the material in this section:
TITLE CONTENT
Data File Types The three types of data files that HP Business
BASIC/XL uses
File Identification How HP Business BASIC/XL identifies a data file
File Input and Output Read from or write to a data file.
Data File Types
HP Business BASIC/XL uses three types of data files: BASIC DATA, binary,
and ASCII. Table 6-14 shows their similarities and differences.
Table 6-14. Data File Types
-------------------------------------------------------------------------------------------------
| | | | |
| | ASCII | BASIC DATA | Binary |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| How Created | CREATE statement or | CREATE statement or | CREATE statement or |
| | operating system | operating system | operating system |
| | command. | command. | command. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Fixed Length | Yes, if created with | Yes, if created with | Yes, if created with |
| | CREATE statement. If | CREATE statement. If | CREATE statement. If |
| | created with an | created with an | created with an |
| | operating system | operating system | operating system |
| | command, it depends | command, it depends | command, it depends |
| | on the command. | on the command. | on the command. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Formatted | No | Yes | No |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Input | READ statement, | READ statement. | READ statement. |
| | LINPUT statement. | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Output | PRINT statement. | PRINT statement. | PRINT statement. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Misc. | Data items are | READ statement | No wasted space; no |
| | separated by commas | type-checks BASIC | item separators as |
| | or record boundaries | DATA file data before | there are in ASCII |
| | in an ASCII input | assigning it to | files. No item |
| | file. | variables. | descriptors as there |
| | | | are in a BASIC DATA |
| | PRINT statement must | Direct word reads and | file. |
| | print commas between | writes are possible | |
| | data items if READ | (see "File Input and | |
| | statement is to read | Output"). | |
| | ASCII file after it | | |
| | is printed. | Conceptually, a | |
| | | series of data items | |
| | | actually, a series of | |
| | | records. | |
| | | | |
-------------------------------------------------------------------------------------------------
The BASIC DATA file is the only formatted file. It contains format words
that describe each datum. When a program writes a datum to a BASIC DATA
file, HP Business BASIC/XL writes the appropriate format words to the
BASIC DATA file (the statement that writes to the file need not specify
them). When a program reads a string datum from a BASIC DATA file, HP
Business BASIC/XL checks the format words for its type and for its size.
Conceptually, a BASIC DATA file is a series of data items, rather than a
series of records. Actually, it is composed of records; each record
contains as many whole data items as it can, with one immediately
following another. A datum never crosses a record boundary.
ASCII and binary files are unformatted; they do not contain format words
that describe their data.
File Identification
The CREATE statement or operating system command that creates a file
names the file; the ASSIGN statement assigns a file number to it. The
CATALOG and file management statements reference files by their names;
the file functions and other statements reference them by their numbers.
fname is a file name used in the Syntax Specification in chapter 4.
fname is represented by one of the following:
* A quoted string literal (for example, "Myfile").
* An unquoted string literal (for example, Myfile).
* A string expression (for example, "File"+ A$).
The following restrictions apply to an unquoted string literal file
representation:
* It must begin with a letter (uppercase or lowercase).
* Its first nonalphabetic character cannot be "$".
* It cannot contain the following characters:
* comma (,)
* semicolon (;)
* space ( )
* exclamation point (!)
* right parenthesis ())
The format of the file name depends on the operating system. For
example, if HP Business BASIC/XL is running on the HP 3000 under MPE XL,
the format of fname is
filename[/lockword][.groupname[.accountname]]
where filename, lockword, groupname, and accountname are strings of one
to eight alphanumeric characters. The first character must be alphabetic
in each.
File Number Syntax (fnum). fnum is the file number that HP Business
BASIC/XL uses to identify the file. In the syntax specifications in
chapter 4, fnum is any numeric expression that evaluates to a positive
short integer greater than zero. The operating system may identify the
same file with another number (see the file function FNUM). The character
# must precede fnum, except when fnum is a parameter in a call to one of
HP Business BASIC/XL's predefined file functions (then the # is
optional).
Examples
Legal fname Representation
"*myfile" Quoted string literal - file back
reference
Abc$ String expression
"mylife. mygroup" Quoted string literal
File$+Group$+ Account$ String expression
myfile Legal unquoted string literal
myfile/password. mygroup Legal unquoted string literal
Illegal fname Reason it is illegal
*myfile Does not start with a letter
Abc$.mygroup First nonalphabetic character is "$"
Abc);def Contains ")"
An HP Business BASIC/XL program must assign a file number to a file
before it can access it; it must open the file. A program can assign
more than one file number to a file; open it more than once. See the
ASSIGN Statement for more information.
Filecodes. If you list your data or program files, you will see the
following file code mnemonic associated with each type of file:
Filecodes
----------------------------------------------------------------------------------------------
| | | |
| Mnemonic | Filecode | Description |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| BSAVE | 1244 | HP Business BASIC/V Save |
| | | file. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| BSVXL | 1247 | HP Business BASIC/XL Save |
| | | file. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| BDATA | 1242 | HP Business BASIC/V Data |
| | | file. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| BDTXL | 1248 | HP Business BASIC/XL Data |
| | | file. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| BBNCM | 1249 | MPE/V binary file. |
| | | |
----------------------------------------------------------------------------------------------
The filecode associated with each of the data files is used to identify
whether the file stores information in the MPE/V or MPE XL format. When
the file is opened by HP Business BASIC/XL, the file code is used to
determine the data storage format. If the file code indicates that the
file is was created on MPE/V, all the subsequent work of floating-point
real data conversion is done automatically. Therefore, it is possible to
share data among MPE XL native mode applications and existing programs
not yet migrated from compatibility mode. However, if the data file is
only intended for native mode programs and the data file was created
on MPE/V or in compatibility mode, run the conversion program
BBCTMPEV.PUB.SYS to avoid the performance impact of data conversion.
File Input and Output
File input and output (I/O) statements read input from and write output
to data files. The following input statements are available:
LINPUT
MAT READ
READ
The following output statements are available:
PRINT
UPDATE
In addition, the CATALOG statement is used to display directory
information about specified files. All of these statements are explained
in chapter 4.
Each data file has a record pointer and a word pointer associated with
it. A BASIC DATA file has a datum pointer as well:.
record pointer Indicates the next record to be read or written.
word pointer Indicates the next word (within the next record) to be
read or written.
datum pointer Indicates the next datum to be read or the next place
to write a datum.
After any file I/O operation, the record, word, and datum pointers
advance to the next respective record, word, or datum depending on the
type of I/O operation. The POSITION statement positions the record
pointer at a specified record. The ADVANCE statement moves the record
pointer forward or backward. These statements are defined in chapter 4.
Regardless of file type, a file I/O operation can be:
sequential Sequentially reads or writes to the record in the file
indicated by the position of the record pointer.
direct The record pointer is moved directly to a specific
record prior to reading or writing.
On a BASIC DATA file, a file I/O operation can also be:
direct word Both the record and word pointers are moved to a
specific word in the file prior to reading and writing.
Refer to Table 6-15 for the data storage and data item descriptor size
for each data type in the BASIC DATA file. This is useful for direct
record and word I/O to a BASIC DATA file.
Table 6-15. BASIC DATA File Contents
----------------------------------------------------------------------------------------------
| | | |
| | Data Storage Size | Descriptor Size (in |
| | (in fileword) | fileword) and |
| | | [Descriptor Value] |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Short Integer | 1 | 1 [5] |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Integer | 2 | 1 [6] |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Short Decimal | 2 | 1 [7] |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Short Real | 2 | 1 [8] |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Decimal | 4 | 1 [9] |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Real | 4 | 1 [10] |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Entire String (for string | (total no. of chars + 1) | 2 [1], second word is the |
| that fits into one record) | div 2 | total no. of chars in the |
| | | string |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Beginning of String | (record size -2) | 2 [2], second word - total |
| | | no. of chars in string |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Middle of String | (record size - 2) | 2 [3], second - total no. |
| | | of chars left |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| End of String | (total no. of chars left + | 2 [4], second word = total |
| | 1) div 2 | no. of chars left |
| | | |
----------------------------------------------------------------------------------------------
Table 6-15 Note: The length of each fileword is two bytes for
consistency with the MPE XL file system.
MPE/iX 5.0 Documentation