SAVE
Save Program to Disk
This directive writes the current contents of program memory to a file on a disk.
Syntax
Section titled “Syntax”[P]SAVE [program-name [, size, disk-num, sector-num]][,ERR=line-ref|,ERC=error-code] [,PWD=passwd]P- is the optional designator for a password protected SAVE.
program-name- is any string of 8 characters or fewer used to name the program and its program file.
size- is an integer in the range of 1 to 5,242,880 (5*1024*1024) specifying the size of the program (number of bytes).
disk-num- specifies the logical disk directory that contains this file. Valid values are 0 through 35.
sector-num- is the sector number. The only valid value is 0.
line-ref- is the program line number or label to branch to if an error is produced by this directive.
error-code- is a programmer-defined error code. Valid values are positive or negative whole numbers.
passwd- is any string in the range of 4 to 8 characters in length. This parameter is not allowed without the optional P for password save (PSAVE).
Remarks
Section titled “Remarks”Starting with release level 8.2, a program has its format and data names references validated against the data dictionary. Any errors detected with the program’s formats and data names are saved into the ERRBUF system variable and the SAVE directive results in an ERR=160. If the SAVE directive is entered from Thoroughbred Basic Console Mode, then the errors detected are displayed to the screen.
PWD=passwd generates a syntax error (ERR=20) if used with SAVE instead of PSAVE.
ERR=line-ref does not cause a syntax error if used in console mode, but has no meaning unless used in RUN mode.
[P]SAVE does not require size, disk-num, and sector-num if the program file was previously defined by either a PROGRAM directive or a previous [P]SAVE using size, disk-num, and sector-num.
An attempt to use [P]SAVE when the program file already exists on an available logical disk directory generates an ERR=12.
The SAVE directive looks up labels and format element names and converts them into permanent locations. If you modify a program or format after issuing a SAVE directive, the locations may change. Before you run the program, you must use the SAVE directive so that Thoroughbred Basic can find and use the labels or element names.
Starting with release level 8.8, an ERR=37 will be returned when the maximum number of formats in a program is exceeded.
Examples
Section titled “Examples”SAVEsaves the program currently in memory using the PGN system variable for program-name, replacing the current copy on disk.
SAVE "TEST"saves the program in memory into the program file space previously defined for the file TEST.
SAVE PROGRAM_NAME$, 100, 2, 0, ERR=7999If PROGRAM_NAME$ = “TEST1”, the program in memory is placed in logical disk directory number 2 for 256 bytes (even though 100 is specified), under the name TEST1, starting at the next available sector that has sufficient space to contain this program file. If an error results from execution of this directive, this command branches to line 7999.
SAVE PGN, PSZ, 2, 0, ERR=7999If the system variable PGN (program name) contains TEST1 and the system variable PSZ (program size) is 100, performs the same operation as the previous example.
See also
Section titled “See also”ENCRYPT and PSAVE directives
ERRBUF, PGN, and PSZ system variables
From the Thoroughbred Basic Language Reference, Volume III: R–Z, version 8.9.1. Open this page in the PDF