Version 6.3.8 for OpenVMS
 —  Operations  —

Work Files

Work files are files to which data can be written and from which data can be read by Natural programs. They are used for intermediate storage of data and for data exchange between programs. Data can be transferred from or to a work file by using the Natural statements READ WORK FILE and WRITE WORK FILE, or UPLOAD PC FILE and DOWNLOAD PC FILE.

This document covers the following topics:


Defining Work Files

Using the Configuration Utility or the DEFINE WORK FILE statement, you can assign names (including the path) for up to 32 work files.

The maximum number of work files that can be used depends on the setting of the parameter WORK.

If you run a program which uses a work file for which a name and path has not been assigned, Natural automatically creates the file name and writes the work file into the temporary directory specified in the local configuration file. The name of such a file consists of the specified work file number and an arbitrary number assigned by the operating system. The generation of the work file name is based on an algorithm which tries to generate a unique name. Depending on the Natural parameter TMPSORTUNIQ, the naming convention may vary. If work file names are referenced from outside Natural, it is recommended that you specify the names explicitly to avoid problems identifying the files.

The following topics are covered below:

Defining Work File Names with the Configuration Utility

In the Configuration Utility, the work file names are assigned in the category Work Files of a parameter file. The above mentioned parameters WORK and TMPSORTUNIQ can also be found in this category. See Work File Assignments in the Configuration Utility documentation for further information.

The work file name consists of the prefix "W", a number of up to seven digits and the extension "SAG".

Tip:
Locate the work file assignments by searching for "Work Files". See Finding a Parameter in the Configuration Utility documentation for further information.

Defining Work File Names with Environment Variables

The following topics are covered below:

General Information

Work files can also be defined by using OpenVMS logical names. Once you have defined the work file names in the parameter file, the work file names can be set without further change to the parameter file. For example, when you specify the following name for a work file in the parameter file (or in a DEFINE WORK FILE statement):

MYWORKFILE

the following logical name must be defined in your operating system:

DEFINE MYWORKFILE mydevice:[mydir]myworkfile.dat

Instead of MYWORKFILE, you can also enter the following in the parameter file:

Work1:myfile.txt

In this case, the logical name Work1 must be defined in your operating system:

DEFINE Work1 mydevice:[mydir.sub1.sub2]

Defining Work File Names with an Application Programming Interface

You can also define work files with the application programming interface USR1050N in library SYSEXT.

Top of page

Work File Formats

The format of a work file depends on the work file type that has been defined. Different work file formats are available. Natural recognizes the format by checking the file name and its extension:

file-name.extension

where file-name can have a maximum of 8 characters and extension can have a maximum of 3 characters.

The work file formats are:

See also Work Files and Print Files in the Unicode and Code Page Support documentation.

Binary Format

Possible type: SAG.

This format, which is specific to Software AG, is the preferred format since it can be used with all data types.

Each record that is written is preceded by two bytes which contain the length of the record.

To define binary format for a work file, use either a file name with a period and the extension "SAG" (for example, <file-name>.SAG), or just the file name without a period (for example, <file-name>).

ASCII Format

Possible types: ASCII and ASCII compressed.

Since each written record is terminated with a line feed (LF), ASCII format is only recommended for alphanumeric data.

To define ASCII format for a work file, enter either a file name with a period and any extension except "SAG" and "NCD" (for example, <file-name>.<ext>), or a file name with a period and without an extension (for example, <file-name>).

Entire Connection Format

Possible types: Entire Connection and Transfer.

Work files can be accessed in two different ways:

The product Entire Connection uses two files: a data file which contains the actual data and a format file which contains formatting information about the data in the data file.

Natural automatically generates the corresponding format file for the type Entire Connection. The format file has the same name as the data file, however the extension is "NCF". For detailed information on the content of a format file with the extension "NCF", see the Entire Connection documentation.

When using the type Transfer, the format file is generated by the product Entire Connection (provided that the option Create format file has not been deactivated in the user properties; see the Entire Connection documentation for further information).

To define Entire Connection format for a work file, enter a file name with a period and the extension "NCD" (for example, <file-name>.NCD).

You can read/write work files in Entire Connection format directly from/to your local disk.

See also Special Considerations for Work Files with Extension NCD.

Notes:

  1. The RECORD option of the READ WORK FILE statement is not available for reading work files of format Entire Connection.
  2. The operand format U (Unicode) is not supported for the work file types Entire Connection and Transfer. If U is used with these work file types, a runtime error message is displayed.

Portable Format

Possible type: Portable.

The type Portable performs an automatic endian conversion of a work file when the work file is transferred to a different machine. For example, a work file written on a PC (little endian) can be read correctly on an RS6000 or HP machine (big endian). The endian conversion applies only to field formats I2, I4, F4, F8 and U. The floating point format is assumed to be IEEE. There are, however, slight differences in IEEE floating point representation by different hardware systems. As a rule, these differences apply only to infinity and NaN representations, which are normally not written into work files. Check the hardware descriptions if you are uncertain.

The files are always written in the machine-specific representation, so that a conversion is performed only if the file is read by a machine with different representation. This keeps performance as fast as possible.

There are no other conversions for this format apart from the conversions mentioned above.

When a READ WORK FILE statement is used for a dynamic variable, the variable is resized to the length of the current record.

Unformatted Format

Possible type: Unformatted.

The type Unformatted reads or writes a complete file with just one dynamic variable and just one record (for example, to store a video which was read from a database). No formatting information is inserted; everything is written and read just as it is.

CSV Format

Possible type: CSV (comma-separated values).

Note:
If you want to use the work file type CSV, you have to recatalog your sources using the CATALOG or STOW command. It is not possible to use the work file type CSV with generated programs of Natural Version 4.

The Natural fields are stored in a CSV work file as described below.

  1. In the first step, the internal field data is converted into a readable format:

  2. In the second step, the field data in readable format is copied to the CSV work file record. The fields in the work file are separated by the specified separator character. If a field contains special characters, the field is delimited by double quotes. Each written record is terminated with a carriage return and line feed (CR/LF).

If you have defined that a header with the Natural field names is to be written to the work file (see Work File Assignments in the Configuration Utility documentation), the following applies:

Top of page

Record File Format

Work files (1 to 32) with binary format are created with RMS file format variable length, whereas all other files are created with RMS file format stream line feed and record attribute carriage return carriage control.

Top of page

Special Considerations for Work Files with the Extension NCD

If files with the extension "NCD" are created by Entire Connection and are then read into Natural via the READ WORK FILE statement, it is required that the Entire Connection option Keep trailing blanks is activated in the session properties. See your Entire Connection documentation for further information.

Note:
When you create an NCD file using Entire Connection and load this file using the Object Handler, you may receive an error indicating that the source control record is missing. To avoid this, make sure that the option Keep trailing blanks is active when you create the NCD file.

The following considerations apply for work files in Entire Connection format:

Top of page

Using the Work File Type "Transfer"

With local access (that is, without any data transfer being involved), you can read/write work files in Entire Connection format directly from/to your local disk. However, work files in Entire Connection format can also be accessed by using a data transfer. Both methods can be used simultaneously, but with different work file numbers only.

Work files to be accessed by using a data transfer (type Transfer) must be in Entire Connection format (NCD).

With data transfer, the Natural statements READ WORK FILE and WRITE WORK FILE do not read from and/or write to your local disk, but transfer the data to a PC that runs Entire Connection. The read/write operations are then done by Entire Connection from/to the disk of the PC.

For the work file number to be used, you have to set the profile parameter ECPMOD to "ON" in the Configuration Utility. It is not required that you assign a work file name in this case, because Entire Connection prompts you to enter a file name.

Top of page