FILE Examples


Example 1:

 

DEFFILE

FILE

 

DEFFILE may be used for sequential or random file I/O. Since no parameter was specified, the logical sector and buffer sizes are the default (256 bytes). For random I/O, record zero would begin at the first byte in the file, record one at the 257th byte and so forth.

 

Example 2:

 

BUFFILE

FILE

BUFFER=8192

 

BUFFILE may be used for sequential or random file I/O. Its defined logical sector and buffer sizes are set to 8192 bytes. If BUFFILE were used for random I/O, record 0 would begin at the 1st byte in the file, record 1 at the 8193rd, record 2 at byte 16385th and so forth.

 

Example 3:

 

FIXFILE

FILE

FIX=4096

(or)

FIXFILE

FILE

FIXED=4096

 

FIXFILE may be used for sequential or random file I/O. Its defined logical sector and buffer sizes are 4098 bytes for MS-DOS and 4097 bytes for Linux (FIX/FIXED size plus the appropriate EOR). For random I/O, record zero would begin at the first byte in the file, record one would begin at the 4099th (MS-DOS) or 4098th (Linux) byte, record two would begin at the 8197th (MS-DOS) or 8195th (Linux) byte and so forth since sufficient space for the EOR was automatically added.

 

Example 4:

 

PTRFILE

FILE

^

FILE1

FILE

BUFFER=4096

FILE2

FILE

BUFFER=1024

  

...

 

  

CALL

SUB USING FILE1

  

CALL

SUB USING FILE2

  

...

 

SUB

LROUTINE

PTRFILE

  

...

 

  

READ

PTRFILE,...

  

...

 

  

RETURN

 

 

PTRFILE is a Pointer Variable that contains the address of another FILE variable at execution time. This assignment is usually accomplished via the parameterized CALL instruction. Once initialized, PTRFILE may be used as any other FILE variable. It takes on all the attributes of the pointed to FILE variable.

 

Example 5:

 

AUDIT

FILE

%BUFFER=100

 

This instruction defines a global file. It is kept open during the CHAIN instruction.

 

Example 6:

 

AUDIT

FILE

%%

 

This instruction defines a global file whose attributes are undefined. Prior to being opened, it must be defined by performing a LOADMOD instruction or a CALL instruction of a separately compiled routine that defines the file with a '%' operator.

 

Example 7:

 

MasterView

INIT

"mydatabase.master"

.

 

 

File1

FILE

VIEW="somedatabase.userview"

or

 

 

File1

FILE

VIEW=MasterView

 

This instruction defines a global file that is associated with a database and a view.



PL/B Language Reference External Examples FILEIO Example