Introduction To NATURAL PDF
Introduction To NATURAL PDF
02/07/2009
This document gives a basic introduction to NATURAL programming. Details what is NATURAL, NATURAL Data areas, NATURAL Variables and Statements.
Introduction to NATURAL
What is NATURAL?
NATURAL is a 4th generation programming language. It is free format language where it can be either procedural or non-procedural. Can be used to build both online and batch programs. Databases like ADABAS and DB2 can talk to NATURAL. There are two modes of NATURAL programming, Structured and Reporting. The functional differences between structured mode and reporting mode are provided at the end of the document.
Types of Variables:
Type Alphanumeric Numeric Packed decimal Control Logical Date Time Floating Point Integer Binary Format (Annn) (Nnn.m) (Pnn.m) (C) (L) (D) (T) (Fn) (In) (B) Size 1-253 characters 1-29 digits 1-29 digits 2-byte internal format 1-byte FALSE/TRUE P6 P12 4 bytes for single precision 8 bytes for double precision or 1,2 or 4 bytes 1-128 bytes
Internal Use
Introduction to NATURAL
DATA Areas:
The data areas are used to maintain external NATURAL Data Definitions. Following are the three data areas.
LDA (Local Data Area) Data resides within the program and is used in the program itself. GDA (Global Data Area) Data resides in a common location and is shared by all Natural objects in the application
PDA (Parameter Data Area) Data passed between a natural program and its subprogram, subroutine or a help routine.
In the below example, the fields are defined within the DEFINE DATA statement of the program. In the second example, the same fields are defined in a local data area, and the DEFINE DATA statement only contains a reference to that data area.
Internal Use
Introduction to NATURAL
DEFINE DATA LOCAL 01 #EMP-ID 01 #EMP-NAME 01 #EMP-ADDR 01 #EMP-CITY 01 #EMP-SAL END-DEFINE Example 2 - Fields Defined in a local data area outside the program. (N20) (A25) (A20) (A25) (P9.2)
Internal Use
Introduction to NATURAL
DEFINE DATA statement. Any number of main programs, external subroutines and help routines can share the same global data area.
Each object can reference only one global data area; that is, a DEFINE DATA statement must not contain more than one GLOBAL clause. Example: DEFINE DATA GLOBAL USING SAMPLGDA END-DEFINE
The sequence, format and length of the parameters specified with the CALLNAT/ PERFORM statement in the invoking object must exactly match the sequence, format and length of the fields specified in the DEFINE DATA PARAMETER statement of the invoked subprogram/subroutine. However, the names of the variables in the invoking object and the invoked subprogram/subroutine need not be the same (as the parameter data are transferred by address, not by name). Sample PDA: 01 # GRP-DET R 01 # GRP-DET 02 #GRP-NUM 02 #EMP-NO 02 #EMP-NAME Program reference: DEFINE DATA PARAMETER USING SAMPLPDA END-DEFINE N 9.0 N 9.0 A 10 A 28
Internal Use
Introduction to NATURAL
01 #EMP-SAL (N10.2) END-DEFINE The variables should be declared within the DEFINE DATA and END-DEFINE section. The variables can be used only when declared. NATURAL throws a syntax error if variables are used
Internal Use
Introduction to NATURAL
without declaring them initially. The layouts of input file / output file and other working storage variables can be declared and used. In the above example, the variable #NAME is alphanumeric and of size 25, which means that it can hold names that have 25 characters or less.
The name comprises of two parts, forename and surname. The above redefinition shows that the forename is alphanumeric and of size 10 and surname is alphanumeric and of size 15 and both adds up to 25 characters.
NATURAL Statements
Lets have a look at some of the most frequently used NATURAL Statements in detail. ACCEPT/REJECT Syntax: ACCEPT IF logical-condition REJECT IF logical-condition Example: READ EMPLOY-VIEW ACCEPT IF #SEX = 'F' AND #MAR-STAT = 'S' DISPLAY #NAME END-READ
Internal Use
Introduction to NATURAL