Natural Part1
-
Upload
tusharkhodwe -
Category
Documents
-
view
224 -
download
0
Transcript of Natural Part1
-
7/28/2019 Natural Part1
1/34
FUNDAMENTALS OF NATURAL PROGRAMMING
-
7/28/2019 Natural Part1
2/34
Objective of the Session
The objective of this course is to understand thebasic programming concepts of Natural
Prerequisites :
Mainframe background (TSO/ISPF, JCL)
-
7/28/2019 Natural Part1
3/34
TOPICS OF INTEREST INTRODUCTION
NATURAL PROGRAMMING MODES
NATURAL OBJECTS
DATA AREAS
DEFINING DATA
STATEMENTS & OPERATORS & FUNCTIONS
USER DEFINED CONSTANTS
ARRAYS
CONDITIONAL & LOOPING STATEMENTS
PROGRAM & ROUTINE INVOKING STATEMENTS
SEQUENTIAL FILE HANDLING
SYSTEM VARIABLES & EDIT MASK
-
7/28/2019 Natural Part1
4/34
INTRODUCTION
-
7/28/2019 Natural Part1
5/34
ABOUT NATURAL Natural is a complete application development environment for designing,
developing and employing business-critical applications
It supports all popular platforms, including mainframes, Windows, Unix, andLinux
Programming Language Developed by Software AG
It has been used by enterprises around the world since it was introduced in1979
Fourth Generation Language
Has both Online and Batch features
Can access
Sequential files
ADABAS
DB2
Programming modes
Structured
Reporting
-
7/28/2019 Natural Part1
6/34
ADVANTAGES
Natural can be used to open up key information to clients and partners without
major redevelopment
Simple and efficient
Natural requires fewer lines of code for a given task than other development
languages
The language is easy to learn; developers new to Natural can be trained and
made productive in a matter of weeks
-
7/28/2019 Natural Part1
7/34
NATURAL PROGRAMMING MODES
-
7/28/2019 Natural Part1
8/34
Natural offers two ways of programming:
Reporting mode
Reporting mode is only useful for the creation of adhoc reports and small
programs which do not involve complex data and/or programming
constructs
Structured mode
Structured mode is intended for the implementation of complex
applications with a clear and well-defined program structure
-
7/28/2019 Natural Part1
9/34
Setting the Programming Mode
The default programming mode is set by the Natural administrator with the
profile parameter SM. You can change the mode by using the Natural system command
GLOBALS and the session parameter SM:
Structured Mode: GLOBALS SM=ON
Reporting Mode: GLOBALS SM=OFF
-
7/28/2019 Natural Part1
10/34
Functional Differences
The following major functional differences exist between reporting mode and
structured mode:
Syntax Related to Closing Loops and Functional Blocks
Closing a Processing Loop in Reporting Mode
Closing a Processing Loop in Structured Mode
Location of Data Elements in a Program
Database Reference
-
7/28/2019 Natural Part1
11/34
Reporting
Mode:
(CLOSE) LOOP and DO ... DOEND statements are used for this purpose.
END-... statements (except END-DEFINE, END-DECIDE and END-
SUBROUTINE)
cannot be used.
Structured
Mode:
Every loop or logical construct must be explicitly closed with a
corresponding END-...statement.
Thus, it becomes immediately clear, which loop/logical constructs ends
where.
LOOP and DO/DOEND statements cannot be used.
Syntax Related to Closing Loops and Functional Blocks
-
7/28/2019 Natural Part1
12/34
Closing a Processing Loop in Reporting Mode
The statements END, LOOP (or CLOSE LOOP) or SORT may be used to close a
processing loop
The LOOP statement can be used to close more than one loop, and the END
statement can be used to close all active loops
A SORT statement closes all processing loops and initiates another processing loop
Closing a Processing Loop in Structured Mode
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 an END-ALL statement and the SORT
loop must be closed with an END-SORT statement
-
7/28/2019 Natural Part1
13/34
Location of Data Elements in a Program
In reporting mode, you can use database fields without having to definethem in a DEFINE DATA statement
Also, you can define user-defined variables anywhere in a program, which
means that they can be scattered all over the program
In structured mode, alldata elements to be used have to be defined inone central location (either in the DEFINE DATA statement at the beginning
of the program, or in a data area outside the program)
-
7/28/2019 Natural Part1
14/34
-
7/28/2019 Natural Part1
15/34
NATURAL OBJECTS
-
7/28/2019 Natural Part1
16/34
OBJECTS OF NATURAL Objects are used to achieve efficient application structure
Types of objects :
Program
Subprogram
Subroutine
Copycode
Map
Local data area
Global Data Area
Parameter Data Area
-
7/28/2019 Natural Part1
17/34
Creating and Maintaining Objects
To create and maintain all these objects, you use the Natural editors
Local data areas, global data areas and parameter data areas arecreated/maintained with the data area editor
Maps are created/maintained with the map editor
All other types of objects listed are created/maintained with the program
editor
-
7/28/2019 Natural Part1
18/34
DATA AREAS
-
7/28/2019 Natural Part1
19/34
Natural supports three types of data area:
Local Data Area
Global Data Area
Parameter Data Area
-
7/28/2019 Natural Part1
20/34
Local Data Area
Variables defined as local are used only within a single Natural programming object
There are two options for defining local data:
You can define local data within a program
You can define local data outside a program in a separate Natural programming object
Example 1 - Fields Defined Directly within a DEFINE DATA Statement:
DEFINE DATA LOCAL
1 VIEWEMP VIEW OF EMPLOYEES
2 NAME
2 FIRST-NAME
2 PERSONNEL-ID
1 #VARI-A (A20)
1 #VARI-B (N3.2)
1 #VARI-C (I4)END-DEFINE
...
-
7/28/2019 Natural Part1
21/34
Example 2 - Fields Defined in a Separate Data Area:
Program:
DEFINE DATA LOCAL
USING LDA39
END-DEFINE
...
Local Data Area "LDA39":
I T L Name F Length MiscellaneousAll -- -------------------------------- - ---------- ------------------------->
V 1 VIEWEMP EMPLOYEES
2 PERSONNEL-ID A 8
2 FIRST-NAME A 20
2 NAME A 20
1 #VARI-A A 201 #VARI-B N 3.2
1 #VARI-C I 4
-
7/28/2019 Natural Part1
22/34
Global Data Area
A global data area (GDA) is a Natural programming object that allows programs
and external subroutines to share data elements
The data elements shared can be read or modified
In a GDA, you define the characteristics and the sequence of data elements thatdetermine the layout of a GDA instance
A GDA instance is a piece of storage containing data element values that can be
shared by Natural programming objects
Any modification of a data element value in a GDA affects all Naturalprogramming objects that reference the same instance of this GDA
-
7/28/2019 Natural Part1
23/34
Parameter Data Area
A Natural programming object of the type parameter data area (PDA) is used to
define the data elements that are passed as parameters to a subprogram or
external subroutine.
A PDA allows subprograms and external subroutines to use the same data element
definitions.
Subprogram is invoked with a CALLNAT statement. With the CALLNAT statement,parameters can be passed from the invoking object to the subprogram.
These parameters must be defined with a DEFINE DATA PARAMETER statement in
the subprogram
They can be defined in the PARAMETER clause of the DEFINE DATA statementitself; or
They can be defined in a separate parameter data area, with the DEFINE DATA
PARAMETER statement referencing that PDA.
-
7/28/2019 Natural Part1
24/34
Parameters Defined within DEFINE DATA PARAMETER Statement
-
7/28/2019 Natural Part1
25/34
Parameters Defined in Parameter Data Area
-
7/28/2019 Natural Part1
26/34
DEFINING DATA
-
7/28/2019 Natural Part1
27/34
DEFINING USER VARIABLES User-defined variable can be defined by specifying the following in the DEFINE DATA
statement
DEFINE DATA LOCAL
level-number variable-name (format/length)level-number variable-name (format/length)
level-number variable-name (format/length)
END-DEFINE
LEVEL-NUMBER => 1 or 2 digit numbers of range 01 to 99 (leading 0 optional)
VARIABLE-NAME => Should be alphanumeric format with length of 32 characters
Note: Working variables usually have # as first char
-
7/28/2019 Natural Part1
28/34
Level Numbers
The level numbering in view definitions, redefinitions and groups must besequential; no level numbers may be skipped
If you define a view, the specification of the view name must be on Level 1 andthe fields the view is comprised of must be on Level 2
Example of Level Numbers in View Definition:
DEFINE DATA LOCAL
1 VIEWEMP VIEW OF EMPLOYEES
2 NAME
2 FIRST-NAME
2 BIRTH
...
END-DEFINE
-
7/28/2019 Natural Part1
29/34
While redefining a field, the REDEFINE option must be on the same level as the originalfield and the fields resulting from the redefinition must be one level lower
Example of Level Numbers in Redefinition:
DEFINE DATA LOCAL
1 VIEWEMP VIEW OF STAFFDDM
2 BIRTH2 REDEFINE BIRTH3 #YEAR-OF-BIRTH (N4)3 #MONTH-OF-BIRTH (N2)3 #DAY-OF-BIRTH (N2)
1 #FIELDA (A20)
1 REDEFINE #FIELDA2 #SUBFIELD1 (N5)2 #SUBFIELD2 (A10)2 #SUBFIELD3 (N5)
...
END-DEFINE
-
7/28/2019 Natural Part1
30/34
Format/length of VARIABLE TYPES Alphanumeric (Annn) - 1 to 253 characters
Numeric (Nnn.m) - 1 to 29 digits
Integer (In) - 1,2 or 4 bytes
Date (D) - 4 bytes
Time (T) - 7 bytes
Logical (L) - 1 byte (TRUE/FALSE)
PACKED NUMERIC (P) - 1 TO 29 DIGITS
EXAMPLE :
DEFINE DATA LOCAL 01 #ENDOFFILE (L)
01 #DATEOFJOIN (D)
01 #EMPL-NAME (A20)
01 #EMP-SAL (N9.2) 01 #WS-COUNTER (I2)
END-DEFINE
-
7/28/2019 Natural Part1
31/34
INIT AT DEFINING
Initial value can be set while defining a variable
Example :
DEFINE DATA LOCAL01 #FIELD1 (N3) INIT 01 #FIELD2 (A10) INIT 01 #FIELD3 (L) INIT
END-DEFINE
-
7/28/2019 Natural Part1
32/34
REDEFINE The redefinition must be specified immediately after the definition of the
original field
In the following example #VAR2 is redefined as #VAR3
DEFINE DATA LOCAL
01 #VAR1 (A15)
01 #VAR202 #VAR22 (N4)
01 REDEFINE #VAR2
02 #VAR3 (A4)
END-DEFINE
-
7/28/2019 Natural Part1
33/34
FILLER FILLER can be used as in COBOL
1 #OUT-DETAIL-LINE (A100) INIT
1 REDEFINE #OUT-DETAIL-LINE
2 #OUT-MAILB-ID (A8)
2 FILLER 2X
2 #OUT-USER-IDEN (A25)
2 FILLER 2X
2 #OUT-DATE-ADDED (A10)
2 FILLER 2X
2 #OUT-TIME-ADDED (A8)2 FILLER 2X
2 #OUT-STATUS (A10)
2 FILLER 4X
2 #OUT-BTCH-NUM (N7)
-
7/28/2019 Natural Part1
34/34