Some Natural SQL statements also support the use of Natural views.
A Natural view can be specified instead of a parameter list, where
each field of the view - except group fields, redefining fields and fields
prefixed with L@
or N@
- corresponds to one parameter
(host variable).
Fields with names prefixed with L@
or N@
can
only exist with corresponding master fields; that is, fields of the same name,
where:
L@
fields are converted into LINDICATOR
fields,
N@
fields are converted into INDICATOR
fields.
L@
fields should have been specified at view definition,
immediately before the master fields to which they apply.
DEFINE DATA LOCAL 01 PERS VIEW OF SQL-PERSONNEL 02 PERSID (I4) 02 NAME (A20) 02 N@NAME (I2) /* null indicator of NAME 02 L@ADDRESS (I2) /* length indicator of ADDRESS 02 ADDRESS (A50/1:6) 02 N@ADDRESS (I2) /* null indicator of ADDRESS 01 #PERSID (I4) END-DEFINE ... SELECT * INTO VIEW PERS FROM SQL-PERSONNEL WHERE PERSID = #PERSID ... END-SELECT
The above example is equivalent to the following one:
... SELECT * INTO PERSID, NAME INDICATOR N@NAME, ADDRESS(*)INDICATOR N@ADDRESS LINDICATOR L@ADDRESS FROM SQL-PERSONNEL WHERE PERSID = #PERSID ... END-SELECT
Note:
When accessing VARCHAR
data types with
Natural for Windows or Natural for Linux and Cloud, there must be a
corresponding length indicator variable in the view.