This document describes the two programming modes offered by Natural.
Generally, it is recommended to use structured mode exclusively, because it provides for more clearly structured applications. Therefore, the explanations and examples in the Programming Guide usually refer to structured mode only.
The following topics are covered:
Natural offers two ways of programming:
Reporting mode is only useful for the creation of ad hoc reports and small programs which do not involve complex data and/or programming constructs. (If you decide to write a program in reporting mode, be aware that small programs may easily become larger and more complex.)
Please note that certain Natural statements are available only in reporting mode, whereas others have a specific structure when used in reporting mode. For an overview of the statements that can be used in reporting mode, see Reporting Mode Statements in the Statements documentation.
Structured mode is intended for the implementation of complex applications with a clear and well-defined program structure. The major benefits of structured mode are:
The programs have to be written in a more structured way and are therefore easier to read and consequently easier to maintain.
As all fields to be used in a program have to be defined in one central location (instead of being scattered all over the program, as is possible in reporting mode), overall control of the data used is much easier.
With structured mode, you also have to make more detail planning before the actual programs can be coded, thereby avoiding many programming errors and inefficiencies.
For an overview of the statements that can be used in structured mode, see Statements Grouped by Function in the Statements documentation.
The default programming mode is set by the Natural administrator with
the profile parameter
For further information on the Natural profile and session parameter
SM, see SM -
Programming in Structured Mode in the Parameter
The following major functional differences exist between reporting mode and structured mode:
For detailed information on functional differences that exist between the two modes, see the Statements documentation. It provides separate syntax diagrams and syntax element descriptions for each mode-sensitive statement. For a functional overview of the statements that can be used in reporting mode, see Reporting Mode Statements in the Statements documentation.
|Structured Mode:|| Every loop or logical construct must be
explicitly closed with a corresponding
The two examples below illustrate the differences between the two modes in constructing processing loops and logical conditions.
The reporting mode example uses the statements
DOEND to mark the beginning and end of the statement
block that is based on the
AT END OF
DATA condition. The
END statement closes all active
READ EMPLOYEES BY PERSONNEL-ID DISPLAY NAME BIRTH AT END OF DATA DO SKIP 2 WRITE / 'LAST SELECTED:' OLD(NAME) DOEND END
The structured mode example uses an
to close the
AT END OF
DATA condition, and an
END-READ statement to
READ loop. The
result is a more clearly structured program in which you can see immediately
where each construct begins and ends:
DEFINE DATA LOCAL 1 MYVIEW VIEW OF EMPLOYEES 2 PERSONNEL-ID 2 NAME 2 BIRTH END-DEFINE READ MYVIEW BY PERSONNEL-ID DISPLAY NAME BIRTH AT END OF DATA SKIP 2 WRITE / 'LAST SELECTED:' OLD(NAME) END-ENDDATA END-READ END
LOOP statement can be used to close more than one
loop, and the
END statement can be used to close all active loops.
These possibilities of closing several loops with a single statement constitute
a basic difference to structured mode.
SORT statement closes all processing loops and initiates
another processing loop.
FIND ... FIND ... ... ... LOOP /* closes inner FIND loop LOOP /* closes outer FIND loop ... ...
FIND ... FIND ... ... ... END /* closes all loops and ends processing
FIND ... FIND ... ... ... SORT ... /* closes all loops, initiates loop ... END /* closes SORT loop and ends processing
Structured mode uses a specific loop-closing statement for each
processing loop. Also, the
END statement does not close any
processing loop. The
SORT statement must be preceded by
END-ALL statement, and the
SORT loop must be
closed with an
FIND ... FIND ... ... ... END-FIND /* closes inner FIND loop END-FIND /* closes outer FIND loop ...
READ ... AT END OF DATA ... END-ENDDATA ... END-READ /* closes READ loop ... ... END
READ ... FIND ... ... ... END-ALL /* closes all loops SORT /* opens loop ... ... END-SORT /* closes SORT loop END
In reporting mode, you can use database fields without having to define
them in a
DATA statement; also, you can define user-defined variables
anywhere in a program, which means that they can be scattered all over the
In structured mode, all data elements to be used have to be
defined in one central location (either in the
statement at the beginning of the program, or in a data area outside the