System Variables and System Functions

#### Search Results

Search

# System Variables and System Functions

This document describes the purpose of Natural system variables and Natural system functions and how they are used in Natural programs.

The following topics are covered:

- System Variables

- System Functions

- Example of System Variables and System Functions

- Further Examples of System Variables

- Further Examples of System Functions

## System Variables

The following topics are covered below:

- Purpose

- Characteristics of System Variables

- System Variables Grouped by Function

### Purpose

System variables are used to display system information. They may be referenced at any point within a Natural program.

Natural system variables provide variable information, for example, about the current Natural session:

- the current library;

- the user and terminal identification;

- the current status of a loop processing;

- the current report processing status;

- the current date and time.

The typical use of system variables is illustrated in the Example of System Variables and System Functions below and in the examples contained in library `SYSEXPG`.

The information contained in a system variable may be used in Natural programs by specifying the appropriate system variables. For example, date and time system variables may be specified in a `DISPLAY`, `WRITE`, `PRINT`, `MOVE` or `COMPUTE` statement.

### Characteristics of System Variables

The names of all system variables begin with an asterisk (*).

#### Format/Length

Information on format and length is given in the detailed descriptions in the System Variables documentation. The following abbreviations are used:

Format
A | Alphanumeric
B | Binary
D | Date
I | Integer
L | Logical
N | Numeric (unpacked)
P | Packed numeric
T | Time

#### Content Modifiable

In the individual descriptions, this indicates whether in a Natural program you can assign another value to the system variable, that is, overwrite its content as generated by Natural.

### System Variables Grouped by Function

The Natural system variables are grouped as follows:

- Application-Related System Variables

- Date and Time System Variables

- Input/Output Related System Variables

- JSON-Related System Variables

- Natural Environment-Related System Variables

- System Environment*Related System Variables

- XML-Related System Variables

For detailed descriptions of all system variables, see the System Variables documentation.

## System Functions

Natural system functions comprise a set of statistical and mathematical functions that can be applied to the data after a record has been processed, but before break processing occurs.

System functions may be specified in a `DISPLAY`, `WRITE`, `PRINT`, `MOVE` or `COMPUTE` statement that is used in conjunction with an `AT END OF PAGE`, `AT END OF DATA` or `AT BREAK` statement.

In the case of an `AT END OF PAGE` statement, the corresponding `DISPLAY` statement must include the `GIVE SYSTEM FUNCTIONS` clause (as shown in the example below).

The following functional groups of system functions exist:

- System Functions for Use in Processing Loops

- Mathematical Functions

- Miscellaneous Functions

For detailed information on all system functions available, see the System Functions documentation.

See also Using System Functions in Processing Loops (in the System Functions documentation).

The typical use of system functions is explained in the example programs given below and in the examples contained in library `SYSEXPG`.

## Example of System Variables and System Functions

The following example program illustrates the use of system variables and system functions:

    ** Example 'SYSVAX01': System variables and system functions
    ************************************************************************
    DEFINE DATA LOCAL
    1 MYVIEW VIEW OF EMPLOYEES
      2 CITY
      2 NAME
      2 JOB-TITLE
      2 INCOME    (1:1)
        3 CURR-CODE
        3 SALARY
        3 BONUS   (1:1)
    END-DEFINE
    *
    WRITE TITLE LEFT JUSTIFIED 'EMPLOYEE SALARY REPORT AS OF' *DAT4E /
    *
    READ (3) MYVIEW BY CITY STARTING FROM 'E'
      DISPLAY GIVE SYSTEM FUNCTIONS
              NAME (AL=15) JOB-TITLE (AL=15) INCOME (1:1)
      AT START OF DATA
        WRITE 'REPORT CREATED AT:' *TIME 'HOURS' /
      END-START
      AT END OF DATA
        WRITE / 'LAST PERSON SELECTED:' OLD (NAME) /
      END-ENDDATA
    END-READ
    *
    AT END OF PAGE
      WRITE 'AVERAGE SALARY:' AVER (SALARY(1))
    END-ENDPAGE
    END

Explanation:

- The system variable `*DATE` is output with the `WRITE TITLE` statement.

- The system variable `*TIME` is output with the `AT START OF DATA` statement.

- The system function `OLD` is used in the `AT END OF DATA` statement.

- The system function `AVER` is used in the `AT END OF PAGE` statement.

Output of Program `SYSVAX01`:

Note how the system variables and system function are displayed.

    EMPLOYEE SALARY REPORT AS OF 11/11/2004

         NAME           CURRENT                 INCOME
                       POSITION
                                    CURRENCY   ANNUAL     BONUS
                                      CODE     SALARY
    --------------- --------------- -------- ---------- ----------

    REPORT CREATED AT: 14:15:55.0 HOURS

    DUYVERMAN       PROGRAMMER      USD           34000          0
    PRATT           SALES PERSON    USD           38000       9000
    MARKUSH         TRAINEE         USD           22000          0

    LAST PERSON SELECTED: MARKUSH

    AVERAGE SALARY:      31333

## Further Examples of System Variables

See the following example programs:

- EDITMX05 - Edit mask (EM for date and time system variables)

- READX04 - READ (in combination with FIND and the system variables *NUMBER and *COUNTER)

- WTITLX01 - WRITE TITLE (with *PAGE-NUMBER)

## Further Examples of System Functions

See the following example programs:

- ATBREX06 - AT BREAK OF (comparing NMIN, NAVER, NCOUNT with MIN, AVER, COUNT)

- ATENPX01 - AT END OF PAGE (with system function available via GIVE SYSTEM FUNCTIONS in DISPLAY)

### On this page

- System Variables
- System Functions
- Example of System Variables and System Functions
- Further Examples of System Variables
- Further Examples of System Functions