# Directives

SAVE | Write Program to File

## Format

SAVE [EDIT] [ prog_name$ [ ,prog_size ] [, IND=ver ] [, MSG=note ] [ ,OWN=owner_id [, FLG=flg:flg:flg ] ] ]

Where:

EDIT | Use the optional keyword EDIT with the SAVE directive to have the system logically break the lines into segments and indent them. See 'LE' system parameter and LIST directive.
flg | Optional package flags. If you use these, delimit them with a : (colon) and use numeric expressions; i.e. integers between 1 and 25.
note | Optional note/message to be included in the header of the program. This can be retrieved using the VER system command.
ver | Optional version number to be set on the saved program. This can be retrieved using the VER system command.
prog_name$ | Filename to receive the program. Optional. String expression.
prog_size | Program size. Optional. Numeric expression.
owner_id | Optional package number (owner ID) to which this program is to be assigned. Numeric expression.

#### Note:
The OWN= and FLG= options are designed for use by registered application developers. They are used to encrypt programs and establish activation keys to run the programs.

## Description

Use the SAVE directive to copy/write the current program to your given filename. (Include the pathname if the directory you want is neither current nor in your PREFIX definition.)

If the file does not already exist, a program file is created. If you include the prog_size argument, the file specified must not already exist.

If the output of the file is a program file type, the system writes it to the file in internal (compiled) format. For serial and indexed file types, the system writes the program in display (LIST) format. You can only use the SAVE directive for serial, indexed, and program files.

#### Note 1:
You can RUN, CALL or PERFORM text files that contain programs just as you would any regular program file.
Note 2:
When using PxPlus (version 7.00 or later) and you have a .pluscvs file in the target directory where a program is being saved, a source/text copy of the program will be placed in the directory whose name is contained within the .pluscvs file. The source/text file will have a suffix of ".pxprg" appended to its file name to identify it as a PxPlus program.

(The ability to add a Note to a program, the Source Control interface and the ability to store multiple versions of a program on a program file were added in PxPlus v8.00.)

## Source Control Interface

This process is designed to provide an automated means to feed program changes to a source control system.

## Structured SAVE

The SAVE directive can also be used to verify modified programs for structural integrity (see 'SS' system parameter). Logical errors (e.g. a FOR with no corresponding NEXT or a SWITCH without an END SWITCH) will result in a Warning #125: Improper Structure Detected, indicating where the fault was detected.

For more information on logical structures, see Structured SAVE.

## Multiple Program Versions

If the '+R' system parameter is non-zero, the SAVE command will maintain prior 'Interim' versions of the program in the program file. The value set in the '+R' system parameter defines the number of prior versions that the SAVE command will keep (maximum 200, default 5).

When you issue a SAVE command on PxPlus 2018 and have multiple versions enabled, if saving a version that has a password, the system will only preserve passworded versions up to the first non-passworded version. Saving a non-passworded version will preserve both passworded and non-passworded versions.

Maintaining prior versions of the program on the program file will not affect the performance or program size during normal execution. The only impact of keeping prior versions is the physical size of the file and the time required to issue a SAVE command when updating the program.

See Version Control.

## See Also

SERIAL Create a Sequential File
PROGRAM Create a Program File

## Example

save "PROG1A"
save "/usr/a-r/PROGS/ARLIST"

You can SAVE or SAVE EDIT a text file containing the source of a program (be sure to pre-create your SERIAL text file):

> serial "PROG00.TXT"
> load "PROG00"
> save edit "PROG00.TXT" ! Formatted with line breaks and indents