You are on page 1of 156

NATURAL/ADABAS Training

Copyright 2010 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture.

Objectives
The objective of this presentation is To be familiar with NATURAL PROGRAMMING LANGUAGE.

Copyright 2010 Accenture All Rights Reserved.

Learning Outcome
At the end of this course, you are expected to Use NATURAL Programming language with ADABAS. code both Batch and Online Programs using NATURAL.

Copyright 2010 Accenture All Rights Reserved.

What is Natural ?
Developed by Software AG Programming Language 4th generation free format procedural Non-procedural Online Batch File Types accessible ADABAS DB2 DL1 Programming Modes Structured Reporting
Copyright 2010 Accenture All Rights Reserved. 4

Natural Editor Commands

Natural editor commands are not programming statements. They are means by which various editors may be invoked and programming objects may be invoked and SAVED and otherwise manipulated. Programming objects are entered and changed using the editors. When they are saved , a copy is placed in an ADABAS file known as FUSER.

Copyright 2010 Accenture All Rights Reserved.

Natural Editor Commands


CREATE EDIT SAVE
CLEAR

READ EXECUTE CHECK( or Just C) RUN STOW

Copyright 2010 Accenture All Rights Reserved.

Natural Objects
Object-type: COPYCODE(C), GLOBAL(G), HELPROUTINE(H), LOCAL(L), MAP(M), PARAMETER(A), PROGRAM(P), SUBPROGRAM(N), SUBROUTINE(S) or TEXT(T). (must be specified if object-name not specified). Object-name: The name of the object to be edited, which will then be loaded in the edit work area. Library-ID : May only be specified if the object is contained in a library other than the one to which you are currently logged on. -> Must not start with 'SYS' except 'SYSTEM' -> Must not be specified if NATURAL SECURITY is installed. Example: EDIT MAP object-name library-id
Copyright 2010 Accenture All Rights Reserved. 7

Natural Commands
SCRATCH Used to: delete one or more objects. Parameter(s): Object-name(s). (If not specified, a list of existing objects will be displayed for you to mark with an 'X' the objects to be deleted.) Result : The specified object(s) will be deleted (in source and object form) from the NATURAL system file of the library to which you are currently logged on. Examples : SCRATCH program-name

SCRATCH program-name1 program-name2 program-name3

Copyright 2010 Accenture All Rights Reserved.

Natural Commands
FIN HELP KEY LAST LIST MAINMENU SYSFILE TEST CATALOG UNCATALOG UPDATE Terminates a Natural session. Question mark or HELP, it invokes NATURALs interactive help facility. Sets or changes command level function key settings. It displays the last command executed It invokes list utility MainMenu invokes NATURAL main menu provides information about available work Files and Printers TEST is used to turn Natural's Debugging Utility on. Catalog compiles source currently in work area and stores only the object module in the NATURAL System File. Uncatalog deletes one or more object modules from the NATURAL System File. Used to execute a maintenance program under test conditions without actually modifying the data bases

Copyright 2010 Accenture All Rights Reserved.

Editors
------------------------------------------------------------------------------------------------COMMAND EDITOR INVOKED USAGE ------------------------------------------------------------------------------------------------EDIT COPYCODE Program Editor Create/Edit copy code EDIT GLOBAL EDIT HELPROUTINE EDIT LOCAL EDIT MAP Data Area Editor Program Editor Data Area Editor Map Editor Create/Edit global data area Create/Edit help routine Create/Edit local data Create/Edit screen and form layouts for use with INPUT and WRITE statements

Copyright 2010 Accenture All Rights Reserved.

10

Editors
EDIT COMMAND SET STAY ON/OFF OFF EXPLANATION ON Current screen remains when ENTER key is pressed. Positioning to next screen with ENTER key. (Default) type Change type of object to be edited. Type may be PROGRAM, SUBROUTINE, SUBPROGRAM, HELPROUTINE, or COPYCODE. -nn/+nn Shift source lines delimited by X and Y markers nn positions to the left or right; comment lines are not shifted. --/++ Shift source lines delimited by X-marked and Ymarked lines to leftmost / rightmost (max. 99 ) positions. Comment lines are not shifted. Perform structural indentation of NATURAL source statements and identify structural inconsistencies.

SET TYPE

SHIFT

SHIFT

STRUCT

Copyright 2010 Accenture All Rights Reserved.

11

Program Structure: DEFINE DATA LOCAL 1 #A 2 #A1 (A2) 2 #A2 (93) 1 EMPLOY VIEW VIEW OF EMPLOYEES 2 PERSONNEL ID 2 FIRST NAME 2 NAME 2 CITY 1 VEH VIEW VIEW OF VEHICLES 2 PERSONNEL ID 2 MAKE END DEFINE LIMIT 4 RD. READ EMPLOY VIEW BY NAME SUSPEND IDENTICAL SUPPRESS FD. FIND VEH VIEW WITH PERSONNEL ID = PERSONNEL ID (RD.) IF NO RECORDS FOUND MOVE ALL * TO FIRST NAME (RD.) END NOREC DISPLAY NOTITLE (ES=OFF IS=ON ZP=ON AL=15) NAME (RD.) FIRST NAME (RD.) CITY (RD.) END FIND END READ END
12

Copyright 2010 Accenture All Rights Reserved.

Defining Data in Natural


Topics Covered

Types of Variables and Data Areas Defining Database Views Defining User Variables Redefinition Of Variables

Copyright 2010 Accenture All Rights Reserved.

13

Types of Variables
Alphanumeric (Annn) Numeric (Nnn.m) Packed decimal (Pnn.m) Control (C) Logical (L) Date (D) Time (T) Floating Point (Fn) Integer (In) Binary (B) 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 1,2 or 4 bytes 1-128 bytes

Copyright 2010 Accenture All Rights Reserved.

14

Data Areas
Used to maintain external NATURAL Data Definitions LDA (Local Data Area) : Data residing and used in the program itself GDA (Global Data Area) : Data shared by Natural objects in the application PDA(Parameter Data Area) Data that is passed when a Natural program invokes subprogram, subroutine or a helproutine

Copyright 2010 Accenture All Rights Reserved.

15

Advantages Of Data Areas


Sharing Definitions across different areas

Ease of access

Less coding in program

Defining Database Views


View consists of database fields to be referenced It can be same as defined in DDM May define own subset of DDM May use same database fields in different view May be defined internal or external(using data areas).

Copyright 2010 Accenture All Rights Reserved.

16

Data definition

Data definition statements start with DEFINE DATA and terminate with END-DEFINE
Example 1: In-line data definition DEFINE DATA LOCAL 1 #SUBTOTAL (P7.2) END-DEFINE Example 2: Data definition using an LDA DEFINE DATA LOCAL USING CLNT-PDA /* PDA FOR SUBPROGRAM CLIENT LOCAL 1 #SUBTOTAL (P7.2) END-DEFINE
Copyright 2010 Accenture All Rights Reserved. 17

PARAMETER DATA AREA


PARAMETER USING allows you to reference a PDA (defining parameter data) from within a subprogram (or helproutine).
Example : Data definition using a PDA DEFINE DATA PARAMETER USING CLNT-PDA /* PDA FOR SUBPROGRAM CLIENT . LOCAL 1 #INDEX (P3) . END-DEFINE

Copyright 2010 Accenture All Rights Reserved.

18

GLOBAL DATA AREA


GLOBAL USING allows you to reference a GDA defining global data.

Example : Data definition using a GDA DEFINE DATA GLOBAL USING INVDATA /* GDA FOR INVOICING APPLICATION LOCAL USING INVREDEF /* LDA REDEFINING INVOICING GDA . END-DEFINE .

Note : For global data there is nothing equivalent to in-line definition.

Copyright 2010 Accenture All Rights Reserved.

19

Record structures
A record structure is simply a group of related elementary fields. Format and length is specified for elementary field.
Example : 2-level record structure DEFINE DATA LOCAL 1 CLNT-REC /* CLIENT RECORD 2 CLIENT-ID (N8) 2 LAST-NAME (A20) 2 FIRST-NAME (A20) 2 MIDDLE-INITIAL (A1) END-DEFINE

When working with record structures, its good practice to qualify field names by prefixing them with the group name followed by a period; for example CLNT-REC.CLIENT-ID. Note: Format and length is not specified for CLNT-REC because it is not an elementary field.
Copyright 2010 Accenture All Rights Reserved. 20

Database views
Access to database fields is by means of a view.

DEFINE DATA LOCAL 1 UPDATE-VIEW VIEW OF CLIENT 2 CLIENT-ID 2 BILLING-NAME END-DEFINE


Format and length should not be specified- they will be derived directly from the database system. Only those fields referenced in the module need to be defined. Views may also be used in an LDA/PDA/GDA.

Example of view in LDA. V 1 UPDATE-VIEW 2 CLIENT-ID 2 BILLING-NAME 2 BILLING-ADDRESS


Copyright 2010 Accenture All Rights Reserved.

CLIENT N8 A 40 A 40 (1:3)
21

Redefining data
An elementary field can be redefined using a REDEFINE statement. Example 1: In-line redefinition DEFINE DATA LOCAL 1 CLNT-REC /* CLIENT RECORD 2 CLIENT-ID (N8) 2 LAST-NAME (A20) 2 REDEFINE LAST-NAME 3 FIRST-LETTER-OF-LAST-NAME (A1) 2 FIRST-NAME (A20) 2 MIDDLE-INITIAL (A1) END-DEFINE The REDEFINE statement must have the same level number as the base field.
Copyright 2010 Accenture All Rights Reserved. 22

Example 2: LDA/PDA/GDA redefinition

* PARAMETER DATA AREA CLNT-PDA 1 CLNT-PDA 2 INPUT-PARAMETERS 3 CLIENT-ID R 3 CLIENT-ID 4 CLIENT-ID-ALPHA 2 OUTPUT-PARAMETERS 3 LAST-NAME R 3 LAST-NAME 4 FIRST-LETTER-OF-LAST-NAME 3 FIRST-NAME 3 MIDDLE-INITIAL

N8

A8
A 20 A1 A 20 A1

Copyright 2010 Accenture All Rights Reserved.

23

Initializing data
Alphanumeric (format A) - space Numeric fields (format N, P, B or I) - zero Date and Time field (formats D and T) - Null date and time Logical fields (format L) FALSE INIT clause An initial value (one which can be subsequently changed by the executing logic) can be assigned using an INIT clause. Example: DEFINE DATA LOCAL 1 #DAYS (P3) INIT<60> 1 #MESSAGE (A50) INIT<WE APPRECIATE YOUR BUSINESS> 1 #FOLLOW-UP (L) INIT<TRUE> END-DEFINE Note : For alphanumeric fields, the initial value must be enclosed in single quotes.
Copyright 2010 Accenture All Rights Reserved. 24

CONST clause
A constant value (one which cannot be changed by the executing logic) can be assigned using a CONST clause. Example: DEFINE DATA LOCAL 1 #DAYS (P3) CONST<60> 1 #MESSAGE (A50) CONST<WE APPRECIATE YOUR BUSINESS> 1 #SUPPRESS-FOLLOW-UP (L) CONST<TRUE> END-DEFINE

Copyright 2010 Accenture All Rights Reserved.

25

Arrays
An array is simply multiple occurrences of a single field, or group of fields. 1, 2 and 3 level arrays are allowed. Example: DEFINE DATA LOCAL 1 #SHORT-NAME (A3/1:12) CONST<JAN,FEB,MAR,APR,MAY, JUN,JUL,AUG,SEP,OCT,NOV,DEC) 1 #MONTH-NBR (P2) END-DEFINE . #MONTH := #SHORT-NAME(#MONTH-NBR)
Copyright 2010 Accenture All Rights Reserved. 26

Example: In-line 2-level array DEFINE DATA LOCAL . 1 #DEPT-NBR (P1) 1 #DOLLARS(P7.2/1:5,1:12) /* 5 DEPARTMENTS, 12 MONTHS 1 #MONTH-NBR (P2) 1 #TOTAL (P7.2) . END-DEFINE . . ADD #DOLLARS(#DEPT-NBR,#MONTH-NBR) TO #TOTAL .

Copyright 2010 Accenture All Rights Reserved.

27

Edit masks
Edit masks are used to validate and format data. For validation, they are used in conjunction with IF statements and certain other statements. For formatting they are used in conjunction with MOVE EDITED,DISPLAY, WRITE and certain other statements. They are also used in map definitions to format output. Examples of Validation: IF #COUNT = MASK(99999) IF #STATE = MASK(AA) IF #NAME = MASK(LLLLLLLLLLLLLLL) Examples of Formatting: MOVE EDITED #COUNT to #COUNT1(EM=ZZZ99)

Copyright 2010 Accenture All Rights Reserved.

28

Data manipulation
Statements in this category manipulate data. The following are covered in this section of the course: RESET := (becomes equal to) ADD SUBTRACT MOVE MOVE ALL COMPRESS EXAMINE EXAMINE TRANSLATE

Copyright 2010 Accenture All Rights Reserved.

29

RESET statement RESET assigns a null value to elementary fields. := (becomes equal to) statement There are several direct assignment statements, including ASSIGN, COMPUTE and MOVE, but := (becomes equal to) is the quickest. The target field is specified before the := symbol. The source field is specified after. Example : #DOLLARS := #INVOICE-AMT #MIN-CLIENT := 1 #MAX-CLIENT := 99999999 #INV-DUE-DATE := #INV-DUE-DATE + 30

Copyright 2010 Accenture All Rights Reserved.

30

COMPUTE statement The COMPUTE statement is another direct assignment statement. COMPUTE must be used when rounding is required, example: COMPUTE ROUNDED #SIX = #ELEVEN / #TWO

ADD statement The ADD statement can be used to change the value of a variable. Example: ADD 30 TO #DUE-DATE SUBTRACT statement The SUBTRACT statement can be used to change the value of a variable. Example: SUBTRACT 30 FROM #DUE-DATE

Copyright 2010 Accenture All Rights Reserved.

31

COMPRESS statement COMPRESS joins 2 or more strings. Example 1: DEFINE DATA LOCAL 1 #ENJOY (A25) CONST<WE HOPE YOU ENJOY> 1 #MESSAGE (A33) 1 #PRODUCT-NAME (A25) END-DEFINE #PRODUCT-NAME := OUR SERVICE . COMPRESS #ENJOY #PRODUCT-NAME INTO #MESSAGE . The COMPRESS statement removes any superfluous spaces between each string, leaving only one. In this example, the resulting string would be "WE HOPE YOU ENJOY OUR SERVICE.

Copyright 2010 Accenture All Rights Reserved.

32

COMPRESS LEAVING NO SPACE DEFINE DATA LOCAL 1 #CLIENT-ID (N8) 1 REDEFINE #CLIENT-ID 2 #CLIENT-ID-ALPHA (A8) 1 #DEPT-NBR (P1) 1 #MESSAGE (A33) END-DEFINE #CLIENT-ID := 31722 #DEPT-NBR := 4 COMPRESS #DEPT-NBR - #CLIENT-ID-ALPHA INTO #MESSAGE LEAVING NO SPACE RESULT : 4-00031722

Copyright 2010 Accenture All Rights Reserved.

33

EXAMINE statement

The EXAMINE statement has several forms. The essential ones are as follows: EXAMINE REPLACE EXAMINE DELETE EXAMINE GIVING LENGTH EXAMINE GIVING POSITION EXAMINE GIVING INDEX

Copyright 2010 Accenture All Rights Reserved.

34

EXAMINE statement - EXAMINE REPLACE EXAMINE REPLACE finds and replaces part of a string. onsider the following example: DEFINE DATA LOCAL . 1 #PRODUCT-NAME (A25) . END-DEFINE . #PRODUCT-NAME := PAYING TOO MUCH ATTENTION . EXAMINE #PRODUCT-NAME FOR MUCH REPLACE WITH LITTLE . In this example the resulting value in #STRING would be PAYING TOO LITTLE ATTENTION.

Copyright 2010 Accenture All Rights Reserved.

35

EXAMINE statement - EXAMINE GIVING LENGTH

EXAMINE GIVING LENGTH returns the length of a string. Consider the following example: EXAMINE #STRING FOR E GIVING LENGTH IN #LENGTH
GIVING LENGTH can also be added to the end of an EXAMINE DELETE statement to return the new length. Consider the following example: EXAMINE #STRING FOR E DELETE GIVING LENGTH IN #LENGTH

Copyright 2010 Accenture All Rights Reserved.

36

EXAMINE statement - EXAMINE GIVING POSITION EXAMINE GIVING POSITION finds part of a string and returns a value indicating the position of the first character. Consider the following example: DEFINE DATA LOCAL 1 #POSITION (P3) 1 #PRODUCT-NAME (A25) END-DEFINE #PRODUCT-NAME := PAYING TOO MUCH ATTENTION EXAMINE #PRODUCT-NAME FOR TOO MUCH GIVING POSITION IN #POSITION . In this example the resulting value in #POSITION would be 8.

Copyright 2010 Accenture All Rights Reserved.

37

EXAMINE statement - EXAMINE GIVING INDEX EXAMINE GIVING INDEX finds a specified value within an array and returns a value indicating the occurrence containing the specified value. Consider the following example: DEFINE DATA LOCAL 1 #INDEX (P2) 1 #SHORT-NAME (A3/1:12) CONST<JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC) END-DEFINE EXAMINE #SHORT-NAME(*) FOR MAY GIVING INDEX IN #INDEX In this example the resulting value in #INDEX would be 5.

Copyright 2010 Accenture All Rights Reserved.

38

EXAMINE TRANSLATE statement

EXAMINE TRANSLATE converts a string to upper or lower case. Consider the following example:
EXAMINE #STRING TRANSLATE INTO UPPER CASE EXAMINE TRANSLATE can also be used to do a character-by-character translation based on the values in an array.

Copyright 2010 Accenture All Rights Reserved.

39

Flow control Statements in this category control logic flow. The following are covered in this section of the course: IF DECIDE ON DECIDE FOR FOR REPEAT PERFORM CALLNAT FETCH STOP

Copyright 2010 Accenture All Rights Reserved.

40

Copyright 2010 Accenture All Rights Reserved.

41

Copyright 2010 Accenture All Rights Reserved.

42

System Variables and Functions


System Variables
Variables containing information about the current status of a Natural session or object execution. Prefixed by asterisk : *system variable All can be used in IF *system -variable MOVE/ASSIGN *system-variable TO #myvariable WRITE/PRINT/DISPLAY/INPUT *system variable COMPUTE #CNT= *COUNTER(READ-1.)*10 Can be used as initial values: 1 #PGM-NAME 1 #CDATE (A8) INIT <*PROGRAM> (N8) INIT <*DATN>

A few can be the object of a statement: MOVE #user-variable TO *system-variable ADD nnn TO *system-variable MOVE constant to *system-variable

Copyright 2010 Accenture All Rights Reserved.

43

System Variables and Functions


System Variables (cont..)
Variable *COUNTER *CURSOR *CURS-COL *CURS-LINE *CURS-FIELD *ERROR-LINE *ERROR-NR *ERROR-TA Format P10 N6 P3 P3 I4 N4 N7 A8 Explanation/Example Loop count for FIND, READ, HISTOGRAM Cursor position(row and column) after user responds to an INPUT statement. Current Cursor column position. Can be modified in NATURAL program. Current Cursor line position, modifiable in NATURAL program. Internal identification of screen field Line number in a program which caused an execution time error. Error number. Can be modified. Equivalent to *ERROR Name of program to receive control if an execution time error occurs.
44

Copyright 2010 Accenture All Rights Reserved.

System Variables (cont..)


Variable
*ISN

Format
P8

Explanation/Example
Internal Sequence number being processed by FIND or READ;periodic group occurrence where value was found by HISTOGRAM Line number of current line Number of records selected by a FIND stmt Identifies key pressed: PA1-PA3,PF1PF24,ENTR(Enter key),CLR(Clear Key),PEN(Light pen). Name assigned to a function key with SET KEY statement. Number of data elements in stack. The name of the executing NATURAL PROGRAM

*LINE-COUNT *NUMBER *PF-KEY

P5 P10 A4

*PF-NAME *DATA *PROGRAM

A10 N3 A8

Copyright 2010 Accenture All Rights Reserved.

45

System Variables (cont..)


Variable Format
*SUBROUTINE *APPLIC-ID *LANGUAGE A32 A8 I1

Explanation/Example

Name of currently executing subroutine Name of NATURAL Library Controls language used for NATURAL error messages. *LEVEL N2 Contains the current level number of the executing module. *COM A128 Communication Area Current Date and Time System Variables *DATD *DATE *DATG A8 A8 A15 Date in DD.MM.YY format Date in DD/MM/YY format Date in DD month name YYYY format

Copyright 2010 Accenture All Rights Reserved.

46

System Variables (cont..)


Variable
*DATI *DATJ *DATN *DATU *DATX *TIMD *TIME *TIMESTMP *TIME-OUT

Format
A8 A5 N8 A8 D(P6) N7 A10 B8 N5

Explanation/Example
Date in YY-MM-DD format Julian date in YYDDD format Date in YYYYMMDD format Date in MM/DD/YY format Date in internal date format Elapsed time Time in HH:MM:SS.T format Machine internal store clock value Seconds left before current transaction is time out Time in HHMMSST format Time in internal format

*TIMN *TIMX

N7 T(P12)

Copyright 2010 Accenture All Rights Reserved.

47

Date and Time Operations


*DATX is current date in internal date format(D) containing the number of days since day 0 in P6 format. *TIMX is the current time in internal time format(T) containing the number of tenths of seconds since day 0 in P12 format. Program can define(D) or (T) format variables:
(D) format variables can be displayed (assume 09/10/87): (EM=MM/DD/YY) (EM=YYMMDD) (EM=YYJJJ) (EM=YYYY WEEK WW) (EM=R) in various formats using edit masks 09/10/87 8709010 87281 1987 WEEK 38 MCMLXXXVII

Copyright 2010 Accenture All Rights Reserved.

48

Date and Time Operations (Cont..)


(T) format variables can be displayed with various edit masks also (assume 9:32:57:1) (EM=HH.II.SS.T) 09.32.57.1 (EM=ZH.II) 9.32 (EM=SS.II.HH) 57.32.09 Numbers can be added or subtracted from (D) format variables yielding a new (and valid) date. The numbers being added to (D) format variables are days (no limit on number which can be added/subtracted) The numbers being added to (T) format variables are tenth seconds (no limit on number which can be added/subtracted)

Copyright 2010 Accenture All Rights Reserved.

49

System Functions

Function
AVER(field) COUNT(field) MAX(field) MIN(field) NAVER(field) NCOUNT(field) N6 null value NMIN(field)

Format
as field N6

Explanation

Average value of field specified Number of iterations through loop for which field had any Value as field Maximum value of field as field Minimum value of field excluding nulls as field Average value of field excluding nulls Number of iterations through loop for which field had a non as field Minimum value of field excluding nulls

Copyright 2010 Accenture All Rights Reserved.

50

System Functions (Cont.)


Function OLD(field) Format as field Explanation Value of field prior to break(very useful in writing subtotal lines at break conditions) Numeric total of all values of field on break condition. Sum of all values for field for all iterations of loop.

SUM(field) TOTAL(field) as field

as field

All the above functions except TOTAL are automatically reset after its evaluating condition criteria are met (BREAK,GIVE FUNCTIONS..)

Copyright 2010 Accenture All Rights Reserved.

51

Example::: DEFINE-DATA 01 MYTABLE VIEW OF EMP-TBL 02 CITY 02 NAME 02 SALARY 01 #MYVAR (A15) END-DEFINE R01. READ MYTABLE BY CITY DISPLAY CITY NAME SALARY AT BREAK OF CITY WRITE 3T AVERAGE: AVER(SALARY) WRITE 3T MAXIMUM: MAX(SALARY) END-BREAK END-READ(R01.) END

Copyright 2010 Accenture All Rights Reserved.

52

Mathematical Functions

Only available in arithmetic statements (ADD, COMPUTE, MULTIPLY, DIVIDE, AND SUBTRACT) Format and length are same as field to which they are applied. Functions are: ABS Absolute value (Positive value) COS Cosine of field FRAC Fractional part of field LOG Natural Logarithm of field SIN Trigonometric sine of field TAN Tangent of field Note that other trigonometric functions can be derived from those provided (e.g. cotangent is 1 / tangent) For trig and log functions move field to F8 format field prior to evaluation, then move result back to the field Example : COMPUTE #X = FRAC(#Y), COMPUTE #X = SQRT(#Y)
53

Copyright 2010 Accenture All Rights Reserved.

SYNTAX:
view-name VIEW [OF] DDM-name { level {ddm-field [(format length)] } Example: 1 FX-BOOK VIEW OF GTI-FX-BOOK 2 TRAN-TYPE 2 GTD-RECEIPT-IND 2 REDEFINE GTD-RECEIPT-IND 3 #RECEIPT-IND (A1) 2 SOURCE-SYSTEM 2 C*CHANGE-HISTORY-GROUP 2 CHANGE-HISTORY-GROUP (1:99) 3 PREVIOUS-CHANGE-USER 3 PREVIOUS-CHANGE-DATE
Copyright 2010 Accenture All Rights Reserved. 54

Basic Programming
Basic Editor Commands

EDIT SET TYPE SET GLOBALS CLEAR SCAN STRUCT Line commands (Ex: .X, .Y, .CX-Y)

Copyright 2010 Accenture All Rights Reserved.

55

Simple Statements

MOVE EXAMINE ASSIGN COMPRESS RESET

MOVE statement
Move value of an operand (or only a part of it) to one or more operands (field or array).

SYNTAX:
1. MOVE ROUNDED operand1 (parameter) TO operand2 2. MOVE operand1 (parameter) SUBSTRING (operand1,operand3,operand4) TO operand2 SUBSTRING(operand2,operand5,operand6) 3. MOVE BY NAME/POSITION operand1 TO operand2 4. MOVE EDITED operand1 TO operand2 (EM=value) 5. MOVE EDITED operand1 (EM=value) TO operand2

6. MOVE LEFT/ RIGHT JUSTIFIED operand1 (parameter) TO operand2


56

Copyright 2010 Accenture All Rights Reserved.

ROUNDED - operand2 is rounded (applicable only if operand2 is numeric) SUBSTRING - the substring option allows you to move only a certain part of an alphanumeric field. operand3/operand5 specify the starting position, operand4/operand6 the length of the field portion. MOVE BY NAME - move individual fields in a data structure to another data structure; only fields present in both structures are moved. MOVE BY POSITION - move fields of a group to another group, regardless of the field names. The number of fields, level structure and array dimensions must be the same.

7.

8.

9.

MOVE EDITED - if edit mask specified for operand2, value of operand1 placed in operand2 using edit mask; if edit mask specified for operand1, edit mask is applied to operand1 and result moved to operand2.

10. MOVE JUSTIFIED - data is left or right justified in operand2.

Copyright 2010 Accenture All Rights Reserved.

57

Example for MOVE BY NAME:


DEFINE DATA LOCAL 1 EMS-MAST VIEW OF EMS-MAST 2 EQ-ID 2 CLASS-CD 2 LOC 1 #WORK-REC 2 EQ-ID (A6) 2 CLASS-CD (A4) 2 LOC (A6) END-DEFINE READ (10) EMS-MAST BY EQ-ID MOVE BY NAME EMS-MAST TO #WORK-REC DISPLAY #WORK-REC END-READ END OUTPUT: EQ-ID CLASS-CD LOC -----------------N00001 1495 211001 N00002 9111 069010 N00003 9111 069010 N00004 9111 101001 N00005 9111 101001
Copyright 2010 Accenture All Rights Reserved. 58

Example for MOVE BY POSITION:DEFINE DATA LOCAL 1 #A 2 #A1 (A2) 2 #A2 (A3) 2 #A3 (A4) 2 #A4 (A5) 1 #B 2 #B1 (A2) 2 #B2 (A3) 2 #B3 (A4) 2 #B4 (A3) END-DEFINE MOVE 10 TO #A1 MOVE 200 TO #A2 MOVE 3000 TO #A3 MOVE 12345 TO #A4 MOVE BY POSITION #A TO #B DISPLAY #B END OUTPUT: #B1 #B2 #B3 #B4 --- --- ---- --10 200 3000 123
Copyright 2010 Accenture All Rights Reserved. 59

MOVE ALL
FUNCTION: The MOVE ALL statement is used to move repeatedly the value of operand1 to operand2 until operand2 is full. SYNTAX: MOVE ALL operand1 TO operand2 [UNTIL operand3]

The source operand contains the value to be moved. All digits of a numeric operand including leading zeros are moved. The target operand is not reset prior to the execution of the MOVE ALL
operation. This is of particular importance when using the UNTIL option since data previously in operand2 is retained if not explicitly overlaid during the MOVE ALL operation. The UNTIL option is used to limit the MOVE ALL operation to a given number of positions in operand2. Operand3 is used to specify the number of positions. The MOVE ALL operation is terminated when this value is reached.

Copyright 2010 Accenture All Rights Reserved.

60

DEFINE DATA LOCAL 1 EMPLOY VIEW VIEW OF EMPLOYEES 2 PERSONNEL ID 2 FIRST NAME 2 NAME 2 CITY 1 VEH VIEW VIEW OF VEHICLES 2 PERSONNEL ID 2 MAKE END DEFINE LIMIT 4 RD. READ EMPLOY VIEW BY NAME SUSPEND IDENTICAL SUPPRESS FD. FIND VEH VIEW WITH PERSONNEL ID = PERSONNEL ID (RD.) IF NO RECORDS FOUND MOVE ALL * TO FIRST NAME (RD.) MOVE ALL * TO CITY (RD.) MOVE ALL * TO MAKE (FD.) END NOREC DISPLAY NOTITLE (ES=OFF IS=ON ZP=ON AL=15) NAME (RD.) FIRST NAME (RD.) CITY (RD.) MAKE (FD.) (IS=OFF) END FIND END READ

END
Copyright 2010 Accenture All Rights Reserved.

61

OUTPUT:
NAME FIRST NAME CITY MAKE ABELLAN *************** *************** ACHIESON ROBERT DERBY FORD ADAM *************** *************** *************** ADKINSON TIMMIE BEDFORD GENERAL MOTORS

EXAMINE
FUNCTION: The statement Examines the Alphanumeric target field (tables & arrays) for occurrence of character string and Replaces first or all occurrences. Deletes first or all occurrences. Counts the number of occurrences. Returns first occurrence in an array.

Copyright 2010 Accenture All Rights Reserved.

62

SYNTAX:
EXAMINE [FULL[VALUE[OF]]] [SUBSTRING] Constant Field-Name Variable Array

[{(beg[,len])}] FOR [FULL[VALUE[OF]]] [PATTERN] Field-Name Variable Constant

ABSOLUTE WITH [DELIMITER]

Variable Constant

[AND]

Replace [First][With][Full[Value[Of]]] Variable Delete [First] Constant [GIVING] Number [IN] Variable Position Length Index
Copyright 2010 Accenture All Rights Reserved. 63

FULL

includes trailing blanks i.e., blanks are treated as any other character with FULL specified. ABSOLUTE is default option. It scans the target field for character string regardless of delimiters. SUBSTRING examines a portion of a field beginning at the user defined starting position and scans left to right for the defined length. PATTERN provides the capability to test the target of an EXAMINE and exclude selected positions from the test. WITH DELIMITERS allows definition of delimiter characters (Blanks or Special characters) GIVING NUMBER returns count of matching occurrences to a numeric variable. GIVING POSITION returns position where first character of string specified starts. GIVING LENGTH returns resulting length of target field after deletions or replacements.

Copyright 2010 Accenture All Rights Reserved.

64

GIVING INDEX returns index occurrence if scanning an array for a


character string into an additional numeric variable. We should maintain the same order as mentioned, if more then one GIVING function is used and each GIVING clause requires a separate and different numeric variable to hold result of request. EXAMPLE
DEFINE DATA LOCAL 1 #TEXT (A40) 1 #A (A1) 1 #NMB1 (N2) 1 #NMB2 (N2) 1 #NMB3 (N2) 1 #NMBEX2 (N2) 1 #NMBEX3 (N2) 1 #NMBEX4 (N2) 1 #POSEX5 (N2) 1 #LGHEX6 (N2) END DEFINE WRITE Example 1 (GIVING NUMBER, WITH DELIMITER) MOVE ABC A B C .A. .B. .C. A B TO #TEXT ASSIGN #A = A EXAMINE #TEXT FOR #A GIVING NUMBER #NMB1 EXAMINE #TEXT FOR #A WITH DELIMITER GIVING NUMBER #NMB2 EXAMINE #TEXT FOR #A WITH DELIMITER . GIVING NUMBER #NMB3 WRITE NOTITLE = #NMB1 = #NMB2 = #NMB3 WRITE / Example 2 (WITH DELIMITER, REPLACE, GIVING NUMBER) WRITE = #TEXT
Copyright 2010 Accenture All Rights Reserved. 65

EXAMINE #TEXT FOR #A WITH DELIMITER REPLACE WITH * GIVING NUMBER #NMBEX2
WRITE = #TEXT = #NMBEX2 WRITE / Example 3 (REPLACE, GIVING NUMBER) WRITE = #TEXT

EXAMINE #TEXT REPLACE WITH + GIVING NUMBER #NMBEX3


WRITE = #TEXT = #NMBEX3 WRITE / Example 4 (FULL, REPLACE, GIVING NUMBER) WRITE = #TEXT

EXAMINE FULL #TEXT REPLACE WITH + GIVING NUMBER #NMBEX4


WRITE = #TEXT = #NMBEX4 WRITE / Example 5 (DELETE, GIVING POSITION) WRITE = #TEXT

EXAMINE #TEXT + DELETE GIVING POSITION #POSEX5


WRITE = #TEXT = #POSEX5 WRITE / Example 6 (DELETE, GIVING LENGTH) WRITE = #TEXT

EXAMINE #TEXT FOR A DELETE GIVING LENGTH #LGHEX6


WRITE = #TEXT = #LGHEX6 END
Copyright 2010 Accenture All Rights Reserved. 66

OUTPUT:
Example 1 (GIVING NUMBER, WITH DELIMITER) #NMB1: 4 #NMB2: 3 #NMB3: 1 Example 2 (WITH DELIMITER, REPLACE, GIVING NUMBER) #TEXT: ABC A B C .A. .B. .C. A B #TEXT: ABC A B C .A. .B. .C. * B #NMBEX2: 1 Example 3 (REPLACE, GIVING NUMBER) #TEXT: ABC A B C .A. .B. .C. * B #TEXT: ABC+++A+B+C+++.A.++.B.++.C.++++*++ B #NMBEX3: 18 Example 4 (FULL, REPLACE, GIVING NUMBER) #TEXT: ABC+++A+B+C+++.A.++.B.++.C.++++*++ B #TEXT: ABC+++A+B+C+++.A.++.B.++.C.++++*++ B+ #NMBEX4: 1 Example 5 (DELETE, GIVING POSITION) #TEXT: ABC+++A+B+C+++.A.++.B.++.C.++++*++ B+ #TEXT: ABCABC.A..B..C.* B #POSEX5: 4 Example 6 (DELETE, GIVING LENGTH) #TEXT: ABCABC.A..B..C.* B #TEXT: BCBC...B..C.* B #LGHEX6: 18
67

Copyright 2010 Accenture All Rights Reserved.

ASSIGN Statement Used to assign a value to one or more fields. SYNTAX: ASSIGN [ROUNDED] field-name = field-name or field-name := field-name (cannot be used when rounded is specified) ROUNDED allows result to be rounded to precision of target field. COMPRESS Statement Combines the contents of two or more fields into a single alphanumeric field. SYNTAX: COMPRESS FULL NUMERIC operand1 (parameter) SUBSTRING (operand1, operand3, operand4)(parameter) INTO operand2 SUBSTRING (operand2, operand5, operand6) LEAVING SPACE LEAVING NO SPACE WITH ALL DELIMITERS operand7
Copyright 2010 Accenture All Rights Reserved. 68

operand1 is the source field, operand 2 is target field With FULL values are transferred in their actual lengths and Without FULL removes leading zeroes and trailing blanks. Without NUMERIC option, decimal points and signs are suppressed before transfer. With NUMERIC option, decimal points and signs are also transferred. Example: COMPRESS FIRST-NAME MIDDLE-I NAME INTO #COMPRESSED-NAME COMPRESS 'A' ' ' 'C' ' ' INTO #TARGET WITH ALL DELIMITERS '* with Result: A**C* COMPRESS 'HELLO' (PM=I) 'ABC' INTO #A LEAVING NO SPACE with Result: OLLEHABC #DATE (D) := *DATX COMPRESS #DATE (DF=I) INTO #ALPHA with Result: 22042002 I-integer, S-short, L-Long
Copyright 2010 Accenture All Rights Reserved. 69

RESET FUNCTION:

The RESET statement is used to set the value of an operand(s) to a null value,
or to an initial value as defined in a DEFINE DATA statement. SYNTAX: RESET [INITIAL] operand1

RESET INITIAL sets each specified field to the initial value as defined for the
field in the DEFINE DATA statement. If no initial value is defined for a field, it will be reset to a default initial value. If you apply RESET INITIAL to an array, it must be applied to the entire array, a RESET INITIAL of individual array occurrences is not possible. RESET INITIAL of fields resulting from a redefinition is not possible either. RESET INITIAL cannot be applied to database fields.

Copyright 2010 Accenture All Rights Reserved.

70

Example:

DEFINE DATA LOCAL 1 EMPLOY VIEW VIEW OF EMPLOYEES 2 NAME (A10) 1 #BINARY (B4) INIT <1> 1 #INTEGER (I4) INIT <5> 1 #NUMERIC (N2) INIT <25> END DEFINE LIMIT 1 READ EMPLOY VIEW WRITE NOTITLE VALUES BEFORE RESET STATEMENT: WRITE / = NAME = #BINARY = #INTEGER = #NUMERIC RESET NAME #BINARY #INTEGER #NUMERIC WRITE /// VALUES AFTER RESET STATEMENT: WRITE / = NAME = #BINARY = #INTEGER = #NUMERIC RESET INITIAL #BINARY #INTEGER #NUMERIC WRITE /// VALUES AFTER RESET INITIAL STATEMENT: WRITE / = NAME = #BINARY = #INTEGER = #NUMERIC END READ END
Copyright 2010 Accenture All Rights Reserved. 71

OUTPUT: VALUES BEFORE RESET STATEMENT: NAME: MORENO #BINARY: 00000001 #INTEGER: 5 #NUMERIC: 25 VALUES AFTER RESET STATEMENT: NAME: #BINARY: 00000000 #INTEGER: 0 #NUMERIC: 0 VALUES AFTER RESET INITIAL STATEMENT: NAME:MORENO #BINARY: 00000001 #INTEGER: 5 #NUMERIC: 25

Simple Reports
Topics Covered Display Statement Newpage, Skip and Write statements

Format options

Copyright 2010 Accenture All Rights Reserved.

72

DISPLAY Statement Displays field values in columns left-to-right across output line Separated by single space or by SF parameter Cannot output past line size (LS parameter) SYNTAX: DISPLAY (rep) options /... output-format output-element ... Options: NOTITLE NOHDR AND GIVE SYSTEM FUNCTIONS (statement-parameters) Specify fields to be output on report in column format. Column is created for each field, and fieldheader is placed over each column. Defaults are: Page width - value set when NATURAL installed (132 in batch mode; line length of terminal in TP mode); First physical print position - position 2; Spacing factor between elements - 1 position; Column width - greater length of field or field heading; Sign - one extra high-order print position reserved for a numeric field; Page overflow - checked before execution of DISPLAY statement.
Copyright 2010 Accenture All Rights Reserved. 73

Output-format override column heading/attribute assignment: '=' 'text' Field name is to be used as header. 'text' overrides column heading; '/' suppresses field header. If multiple text elements specified before field name, last element will be col. header, and others placed before value in column. 'c'(n) Display character 'c', 'n' times immediately before field value. attributes Display attributes: Color attributes: B (blinking) BL (blue) C (cursive/italic) GR (green) D (default) NE (neutral) I (intensified) PI (pink) U (underlined) TU (turquoise) V (reversed video) YE (yellow) SELECTED

Copyright 2010 Accenture All Rights Reserved.

74

Example: 1. DISPLAY NOTITLE 5X NAME 50T JOB-TITLE


2. DISPLAY GIVE SYSTEM FUNCTIONS PERSONNEL-ID NAME FIRST-NAME SALARY (1) CURR-CODE DISPLAY NOTITLE NAME CITY VERT AS `BIRTH/SALARY` BIRTH (EM=99-99-99) SALARY (1) DISPLAY NOTITLE `EMPLOYEE` NAME `LEAVE ACCUMULATED` LEAVE-DUE `*` (10) (I) /* DISPLAY 10 `*` INTENSIFIED

3.

4.

NEWPAGE Statement Causes a page advance based on user specified condition. Cause end-of-page and writetrailer conditions to be true. Default title containing date, time of day, and page number appears unless WRITE TITLE, WRITE NOTITLE, or DISPLAY NOTITLE specified

Copyright 2010 Accenture All Rights Reserved.

75

SYNTAX: NEWPAGE (rep) EVEN IF TOP OF PAGE WITH TITLE IF LESS THAN operand1 LINES LEFT WHEN Example: AT BREAK OF CITY SKIP 1 NEWPAGE WHEN LESS THAN 10 LINES LEFT WRITE `***********************************` / `SUMMARY FOR ` OLD(CITY) / `***********************************` NEWPAGE END-BREAK
76

Copyright 2010 Accenture All Rights Reserved.

SKIP Statement
Generates one or more blank lines in output SYNTAX: SKIP (rep) operand1 LINES operand 1 lies between 1 - 250 If skip exceeds PS parameter, a new page is forced and any remaining lines are ignored. Example:
READ EMPLOYEES BY CITY STARTING FROM `W` AT BREAK OF CITY SKIP 2 END-BREAK DISPLAY NOTITLE CITY COUNTRY NAME END-READ

Copyright 2010 Accenture All Rights Reserved.

77

WRITE Statement
Produces output horizontally from left-to-right. Separated by single space or by SF parameter No Column headers are produced

Differences of WRITE from DISPLAY

line overflow is supported no default column headers are created range of values/occurrences for array is output horizontally vs vertically
SYNTAX I: Dynamic Formatting: WRITE (rep) NOTITLE NOHDR

(statement-parameters) nX 'text'(attributes) ... nT 'c'(n)(attributes) x/y operand1 (parameters) T*field-name P*field-name '=' /...
Copyright 2010 Accenture All Rights Reserved. 78

SYNTAX II: Using a predefined map WRITE (rep) NOTITLE NOHDR USING FORM operand1 operand2 ... MAP Output format field positioning notation: nX Insert spaces between columns; must not be 0. nT Position (tabulation) to print position 'n'. x/y Place next element x lines below last output, on column y. T*field-name Position to specific print position of field used in previous DISPLAY statement. P*field-name Position to specific print position and line of field used in previous DISPLAY statement.

Copyright 2010 Accenture All Rights Reserved.

79

Example: 1. WRITE NOTITLE `=` NAME `=` FIRST-NAME `=` MIDDLE-I // `L O C A T I O N` / `CITY:` CITY / `COUNTRY:` COUNTRY // 2. WRITE NOTITLE 5X NAME 50T JOB-TITLE 3. WRITE / `CITY AVERAGE:` T*SALARY (1) AVER(SALARY(1)) // 4. WRITE / `CITY AVERAGE` P*SALARY (1) AVER(SALARY (1)) // 5. WRITE NOTITLE `=` PERSONNEL-ID `=` NAME `=` PHONE (EM=XXX-XXXXXXX) FORMAT options Sets values for NATURAL session parameters for both input and output statement during program execution. Overrides NATURAL session parameters and any GLOBALS

Copyright 2010 Accenture All Rights Reserved.

80

SYNTAX FORMAT (rep) parameter Example: FORMAT AL=7 FC=+ GC=* HC=L IC=<< IS=ON TC=>> UC== ZP=OFF PS=nn LS=nn /* ALPHANUMERIC FIELD OUTPUT LENGTH /* FILLER CHARACTER FOR FIELD HEADER /* FILLER CHARACTER FOR GROUP HEADER /* HEADER LEFT JUSTIFIED /* INSERT CHARACTERS /* IDENTICAL SUPPRESS ON /* TRAILING CHARACTER /* UNDERLINE CHARACTER /* ZERO PRINT OFF /* PAGE SIZE /* LINE SIZE
81

Copyright 2010 Accenture All Rights Reserved.

Arithmetic Processing
Topics Covered
Add and Subtract statements Multiply and Divide statements Compute statement Mathematical Functions

Copyright 2010 Accenture All Rights Reserved.

82

ADD Statement
Adds two or more operands: Operands can be numeric constants, data base fields, user-defined variables or numeric arrays (element by element)

SYNTAX: 1. ADD ROUNDED operand1 ... TO operand2 2. ADD ROUNDED operand1 ... GIVING operand2 Note: Each operand must contain a valid value at time ADD statement is executed. If keyword TO is used, operand2 will be included in the addition operation, and will contain the result of the addition.

If keyword GIVING is used, operand2 will be used to store result only.

Copyright 2010 Accenture All Rights Reserved.

83

Example: Statement: ADD +5 -2 -1 GIVING #A ADD .231 3.6 GIVING #B ADD ROUNDED 2.9 3.8 GIVING #C MOVE *DATX TO #DATE Result: #A: 2 #B: 3.8 #C: 7

ADD 7 TO #DATE

current date +7

SUBTRACT Statement Subtracts two or more operands from another operand: Operands can be numeric constants, data base fields, user-defined variables or numeric arrays (element by element) SYNTAX: 1. SUBTRACT ROUNDED operand1 ... FROM operand2 2. SUBTRACT ROUNDED operand1 ... FROM operand2 GIVING operand3 Note: If operand2 is constant, GIVING must be specified
Copyright 2010 Accenture All Rights Reserved. 84

MULTIPLY Statement Multiplies two operands Operands can be constants, data base fields, user-defined variables or numeric arrays (element by element) Result is stored in first operand SYNTAX:

1. MULTIPLY ROUNDED operand1 BY operand2 2. MULTIPLY ROUNDED operand1 BY operand2 GIVING operand3
Note: If operand1 is numeric constant, GIVING is required

Copyright 2010 Accenture All Rights Reserved.

85

Examples:
1.
2. 3.

MULTIPLY #A BY 3 MULTIPLY #A BY 3 GIVING #C MULTIPLY ROUNDED 3 BY 3.5 GIVING #C

DIVIDE Statement Divides one operand into another. Result field may be database field or user-defined variable. If database field is used, only value of field within program is changed; database field value is not changed. SYNTAX: 1. DIVIDE ROUNDED operand1 INTO operand2 GIVING operand3 2. DIVIDE operand1 INTO operand2 GIVING operand3 REMAINDER operand4

Copyright 2010 Accenture All Rights Reserved.

86

Note: If operand1 specified as `0`, either error message or result equal to `0` will be returned (depends on setting of parameter ZD). If REMAINDER specified, the remainder of the division will be placed into operand4. Example:

DIVIDE 5 INTO #A DIVIDE 5 INTO #A GIVING #B DIVIDE 3 INTO 3.1 GIVING #C DIVIDE 3 INTO 3.1 GIVING #D DIVIDE 2 INTO #E REMAINDER #F

Copyright 2010 Accenture All Rights Reserved.

87

COMPUTE FUNCTION: The COMPUTE statement is used to perform an Arithmetic or assignment operation.
SYNTAX: {Compute} [ rounded ] {operand 1 } = {Arithmetic expression /operand2} In structured mode, when the COMPUTE CLAUSE is omitted, the equal sign (=) must be preceded by a colon (:). In reporting mode, when the statement name is omitted, the equal sign (=) is equivalent to Compute clause.

When the ROUNDED option is used, the statement name must be specified. {operand1} :=
{operand2}:= ....... {arithmetic expression/operand}

If the option ROUNDED is specified, the last position of the result will be rounded up if the
first truncated decimal position of the value being assigned contains a value greater than or equal to 5.

The precision (number of decimal positions) of the result of a division in a COMPUTE


statement is determined by the precision of either the first operand (dividend) or the first result field, whichever is greater.
Copyright 2010 Accenture All Rights Reserved. 88

Example:
DEFINE DATA LOCAL 1 #I (P2) 1 EMPLOYVIEW VIEW OF EMPLOYEES 2 PERSONNELID 2 SALARY (1:2) 1 #A (P4) 1 #B (N3.4) 1 #C (N3.4) 1 #CUMSALARY (P10) ENDDEFINE COMPUTE #A = 3 * 2 + 4 / 2 1 WRITE NOTITLE COMPUTE #A = 3 * 2 + 4 / 2 1 10X = #A COMPUTE ROUNDED #B = 3 4 / 2 * .89 WRITE COMPUTE ROUNDED #B = 3 4 / 2 * .89 5X = #B COMPUTE #C = SQRT (#B) WRITE COMPUTE #C = SQRT (#B) 18X = #C

Copyright 2010 Accenture All Rights Reserved.

89

LIMIT 1 READ EMPLOYVIEW BY PERSONNELID STARTING FROM 20017000 WRITE / CURRENT SALARY: 4X SALARY (1) / PREVIOUS SALARY: 4X SALARY (2) FOR #I = 1 TO 2 COMPUTE #CUMSALARY = #CUMSALARY + SALARY (#I) ENDFOR WRITE CUMULATIVE SALARY: #CUMSALARY ENDREAD END OUTPUT: COMPUTE #A = 3 * 2 + 4 / 2 1 #A: 7 COMPUTE ROUNDED #B = 3 4 / 2 * .89 #B: 1.2200 COMPUTE #C = SQRT (#B) #C: 1.1045 CURRENT SALARY: 34000 PREVIOUS SALARY: 32300 CUMULATIVE SALARY: 66300

Copyright 2010 Accenture All Rights Reserved.

90

Array Processing
Arrays in Natural They are defined to a maximum of 3 level or dimensions. They are defined as follows: For One-level-Table 01 #A (A6 / 5) which shows that #A is a field of 6 byte alphanumeric and there will be 5 occurrences of this particular field. For Two-level-Table 01 #A (A6 / 1:5 , 1:7) which shows that #A is a field of 6 byte alphanumeric and there will be 5 occurrences at first level and 7 occurrences at second level. A total of 35 occurrences.

Copyright 2010 Accenture All Rights Reserved.

91

Database access and update stmts


READ FUNCTION: Reads and retrieves records from a database file in physical or logical sequence of records. The statement causes a processing loop to be initiated. View name is required for every READ.File name is only allowed in reporting mode. SYNTAX:
{READ/BROWSE} [(OPERAND1)] [RECORDS] [IN] [FILE] {filename/file number/view name}
[PASSWORD= {password/field}] [CIPHER= {CIPHERCODE/FIELD}] [WITH REPOSITION]

[sequence/range specification]
[IN PHYSICAL SEQUENCE/IN ISN SEQUENCE/IN LOGICAL SEQUENCE]

[WHERE logical-condition-criteria]
END-READ [LOOP] (structured mode only) (reporting mode only)
92

Copyright 2010 Accenture All Rights Reserved.

READ/BROWSE statement initiates a processing loop that tells NATURAL where to begin
the processing data base values.The loop terminates by 1. END of file

2. Reaching ENDING AT or THRU value


3. ESCAPE based on logical condition 4. LIMIT or (n) STATEMENTS

OPERAND1 is a numeric variable which is used to control the number of records.This


overrides the LIMIT stmt specifications.

If the value of OPERAND1 is changed within the READ loop,this does not affect the
number of records read.

PASSWORD must be supplied to access data under ADABAS


provided as a constant or a variable.

security.

CIPHER is used to decrypt the data that has been stored with cipher code.This can be

Copyright 2010 Accenture All Rights Reserved.

93

WITH REPOSITION can be applied to only VSAM databases. With this,you can reposition to another start value for the database read within the active READ loop .Repositioning is triggered by the value of the system variable *COUNTER being reset to 0 READ PHYSICAL Reads data in order as physically stored in DATA STORAGE. Used for processing file sequentially a large percentage of file. This can provide fastest access to data since neither the Inverted List nor Address Converter need to be accessed.
SYNTAX: {READ/BROWSE} [{(n)/(field)}] [RECORD[S]] [IN] [FILE] {filename/file number/view name} [ [IN] [PHYSICAL] [ASCENDING/DESCENDING/VARIABLE] [SEQUENCE] ] END-READ LOOP [(reference)]

Copyright 2010 Accenture All Rights Reserved.

94

EXAMPLE: READ (100) VEHICLES IN PHYSICAL SEQUENCE END-READ /* READ 100 AUTO RECORDS LIMIT 100 READ EMPLOYEES /* READ THE FIRST 100 RECORDS READ BY ISN: BY ISN returns data in sequence by Internal Sequence Number. SYNTAX: {READ/BROWSE} [{(n)/(field)}] [RECORD[S]] [IN][FILE] {filename/file number/view name} {BY/WITH} ISN [{=/EQ/EQUAL TO/STARTING FROM}] {file-name/variable/constant} [{THRU/ENDING AT} {file-name/variable/constant}]] END-READ [LOOP [reference]]

Copyright 2010 Accenture All Rights Reserved.

95

EXAMPLE:

LIMIT 100 READ (100) EMPLOYEES BY ISN STARTING FROM 500 THRU 1000 END-READ READ LOGICAL:

Returns data in sequence that descriptor values are ordered in an Inverted


List.

Descriptors,Subdescriptors,Superdescriptors, Hyperdescriptors are allowed.


If no descriptor is specified,uses default sequence field.

Copyright 2010 Accenture All Rights Reserved.

96

EXAMPLE:
READ EMPLOYEES BY NAME STARTING FROM H ENDING AT HZ

READ WHERE: WHERE clause is used to indicate additional criteria for record selection May specify a descriptor, non-descriptor or user-defined variable Logical criteria evaluated after record read and before any processing
SYNTAX: {READ} [WHERE logical-condition-criteria] EXAMPLE: READ VEHICLES BY MAKE STARTING FROM MERCEDES ENDING AT MERCEDES WHERE YEAR GT 79
Copyright 2010 Accenture All Rights Reserved. 97

READ NATURAL SYSTEM Variables : *COUNTER may be specified to count the number of passes through a READ loop.
*ISN returns the Internal Sequence Number of the current record in process when used in a READ loop. EXAMPLE: DEFINE DATA LOCAL USING WHOLDA END-DEFINE READ EMPLOYEES BY CITY = DETROIT THRU DETROIT WHERE MAR-STAT = D DISPLAY NOTITLE NOHDR NAME SEX MAR-STAT *ISN AT END OF DATA WRITE DETROIT RESIDENTS DIVORCED *COUNTER END-ENDDATA END-READ END

Copyright 2010 Accenture All Rights Reserved.

98

READ WORK FILE:

This is used to read data from a non-ADABAS physical sequential work file.
The data is read independent of how they are written to the work file. Automatic break processing may be performed within a READ WORK FILE loop. When END OF FILE condition occurs during the execution of the loop NATURAL
automatically closes the file.

Can READ/WRITE same file in same program. Option AT END OF FILE required with ONCE.

END-WORK/CLOSE LOOP are not permitted if ONCE is specified.

Copyright 2010 Accenture All Rights Reserved.

99

SYNTAX:
READ WORK [FILE] n [ONCE] {RECORD{field-name/constant/group/array[(1:v)]/viewname/FILLER nx} [AND] [SELECT] [{OFFSET n/FILLER nx}]} [GIVING LENGTH variable] [ AT [END] [OF] [FILE]{statement(s)/DO statement(s) DOEND} [END-ENDFILE] ] statement(s) [ [CLOSE] LOOP [(reference/label)] / END-WORK ] /* In reporting mode

Copyright 2010 Accenture All Rights Reserved.

100

RECORD option will be efficient with READ WORK FILE statement. SELECT causes each field to be moved and processed individually and checked for valid
contents whereas RECORD reads the data in one block (level 1) ARRAYS may be specified with variable indexes. FILLER nx skips n bytes of the input record. GIVING LENGTH identifies a variable which contains the actual length of the record read from a work file Specify OFFSET 0 to gain access to the first byte of the record.

EXAMPLE:

READ WORK FILE 1 RECORD #SOCIAL-SECURITY-RECORD WRITE #SOCIAL-SECURITY-NUMBER #TAXPAYER-NAME #DOB #REPORTED-WAGES END-WORK END

Copyright 2010 Accenture All Rights Reserved.

101

FIND FUNCTION:
The FIND stmt is used to select a set of records from the database based on a
search criterion of fields defined as descriptors. This stmt causes a processing to be initiated. Each FIND statement requires Basic Search criteria identifying which Inverted List(s) to search and what to look for which can be Used only with the WITH clause of FIND statement Only descriptors or descriptor type fields may be specified

Copyright 2010 Accenture All Rights Reserved.

102

SYNTAX:
FIND [ALL/ FIRST/ NUMBER/ UNIQUE] [RECORDS] [IN] [FILE] View-Name [PASSWORD = Operand2] [CIPHER = Operand3] [WITH [[LIMIT] (Operand4)] basic-search-criterion [COUPLED-Clause] [STARTING WITH ISN = Operand5] [SORTED-BY-Clause] [RETAIN- Clause] [WHERE- Clause] [IF-NO-RECORDS-FOUND- Clause] Statement. END-FIND (Structured Mode Only) [LOOP] (Reporting Mode Only)

Copyright 2010 Accenture All Rights Reserved.

103

ALL specifies that all selected records are to be processed. (n) indicates only n records are to be processed.It overrides any LIMIT
specifications.
statement

PASSWORD is used to provide a password when retrieving data from an ADABAS file
which is password protected.

CIPHER is used to decrypt the data that has been stored with cipher code.This can be
provided as a constant or a variable.

WITH is used to specify the basic-search-criterion consisting of key fields (descriptors)


defined in the database.

The COUPLED clause is used to specify a search which involves the use of ADABAS coupling facility.It permits database descriptors from different files to be specified in the search criterion of a single FIND stmt.

Copyright 2010 Accenture All Rights Reserved.

104

STARTING WITH ISN = Operand5 is used to specify as Operand5 an ADABAS ISN,which


is used as star value for the selection of records.The starting value used will be the next higher value of Operand5.

SORTED BY is used to sort the records selected.It must be with descriptors and cannot be
PE descriptor

WHERE clause is used to specify an additional selection criterion which is evaluated after
a record has been read and before any processing is performed.

RETAIN clause is used to retain the result of an extensive search in large files for further
processing.

IF NO RECORDS FOUND clause is used to cause a processing loop to be initiated with a


FIND statement to be entered in the event that no records meet the selection criteria specified in the WITH and WHERE clauses.

Copyright 2010 Accenture All Rights Reserved.

105

SYSTEM VARIABLES WITH THE FIND STMT:


*ISN contains the ADABAS Internal Sequence Number of the record currently being processed

*NUMBER contains the number of records which satisfied the basic search criterion specified in the WITH clause.
*COUNTER contains the number of times the processing loop has been entered.

EXAMPLE

FIND EMPLOY-VIEW WITH CITY = MADRID DISPLAY NOTITLE PERSONNEL-ID NAME *ISN *NUMBER *COUNTER END-FIND

Copyright 2010 Accenture All Rights Reserved.

106

Multiple FIND statements may be issued to create nested loops whereby an


inner loop is entered for each record selected in the outer loop. EXAMPLE
EMP. FIND EMPLOY VIEW WITH NAME = SMITH VEH. FIND VEHIC VIEW WITH PERSONNEL ID = EMP.PERSONNELID IF NO RECORDS FOUND MOVE *** NO CAR *** TO MAKE END NOREC DISPLAY NOTITLE EMP.NAME (IS=ON) EMP.FIRST NAME (IS=ON) VEH.MAKE END FIND END FIND

Copyright 2010 Accenture All Rights Reserved.

107

FIND FIRST: FUNCTION The FIND FIRST statement may be used to select and process the first record which meets the WITH and WHERE criteria.This statement doesnt initiate a processing loop. This statement can be used only in reporting mode. IF NO RECORDS FOUND clause cannot be used in this statement. System variables *ISN,*COUNTER,*NUMBER can be in this statement.

EXAMPLE:
FIND FIRST EMPLOY-VIEW WITH CITY = MADRID WHERE BIRTH LT 300101 WRITE NOTITLE RECORDS SELECTED END

Copyright 2010 Accenture All Rights Reserved.

108

FIND NUMBER: FUNCTION:

The FIND NUMBER statement is used determine the number of records which
satisfy the WITH/WHERE criteria specified.No processing loop is initiated. The SORTED BY and IF NO RECORDS FOUND clauses cannot be used in this statement. The WHERE clause cannot be used in structured mode. System variables *NUMBER,*COUNTER can be used in this statement.

EXAMPLE:
FIND NUMBER EMPLOY-VIEW WITH CITY = MADRID WHERE BIRTH LT 300101 WRITE NOTITLE TOT RECORDS SELECTED *NUMBER TOT BORN BEFORE 1 JAN 1930 *COUNTER END

Copyright 2010 Accenture All Rights Reserved.

109

FIND UNIQUE: FUNCTION

The FIND UNIQUE statement is used to ensure that only one record is selected for
processing.It does not initiate any processing loop This statement can be used in reporting mode only. The SORTED BY and IF NO RECORDS FOUND cannot be used with this statement.

HISTOGRAM
FUNCTION:
Reads the values of a database file, which is defined as descriptor, subdescriptor, or a superdescriptor. The values are read directly from the ADABAS Inverted Lists . The HISTOGRAM statement causes a processing loop to be initiated but does not provide access to any database fields other than the field specified in the HISTOGRAM statement. This statement returns the number of rows which have the same value in a specific column.

Copyright 2010 Accenture All Rights Reserved.

110

SYNTAX: Histogram [(operand1)] [Value] [In] [File] View-Name [Password = Operand2] [ [In] {Ascending / Descending /Variable Operand3} [Sequence] ] [Value] [For] [Field] Operand4 [Starting-Ending-Clause] [Where Logical-Condition] Statement End-Histogram (Structured Mode) [Loop] (Reporting Mode)

Copyright 2010 Accenture All Rights Reserved.

111

OPERAND1 is used to limit the number of descriptor values to be processed with the
HISTOGRAM statement.The specified limit has priority over a limit set with a LIMIT statement.If the value of OPERAND1 is changed in the loop,this does not affect the number of values read. A VIEW-NAME is defined with in a DEFINE DATA statement.The view must not contain any other fields apart from the field used in the HISTOGRAM statement.If the field in the view is a periodic-group field or multiple-value field that is defined with as index range ,only the first occurrence of that range is filled by the HISTOGRAM statement. PASSWORD clause is used to provide a password when retrieving data from an ADABAS file which is password protected. With SEQUENCE you can determine whether the values are to be read in ascending or descending sequence.The default sequence is ascending. As OPEARND4 a descriptor,subdescriptor,superdescriptor may be specified. Starting and ending values may be specified using the keywords STARTING and ENDING (or THRU) followed by a constant or a user-defined variable representing the value with which processing is to begin/end.

Copyright 2010 Accenture All Rights Reserved.

112

The WHERE clause may be used to specify an additional selection criterion


(logical-condition ) which is evaluated after a value has been read and before any processing is performed on the value (including AT BREAK evaluation). The descriptor specified in the WHERE clause must be the same descriptor referenced in the HISTOGRAM statement. No other fields from the selected file are available for processing with a HISTOGRAM statement. SYSTEM VARIABLES WITH HISTOGRAM STMT: *NUMBER Contains the number of database records that contain the last value read. *ISN Contains the number of the occurrence in which the descriptor value last read is contained. *ISN will contain 0 if the descriptor is not contained within a periodic group. *COUNTER Contains a count of the total number of values which have been read (after evaluation of the WHERE clause).

*NUMBER and *ISN are only set after the evaluation of the WHERE clause.
They must not be used in the logical condition of the WHERE clause
Copyright 2010 Accenture All Rights Reserved. 113

GET FUNCTION:

Reads a record with a given ISN.It does not cause any processing loop to be
initiated. SYNTAX GET [IN] [FILE] view-name [ PASSWORD = operand1 ] [ CIPHER = operand2 ] [RECORD] {operand3 *ISN [( r ) ] } operand4

Copyright 2010 Accenture All Rights Reserved.

114

VIEW-NAME is defined in a DEFINE-DATA statement. The PASSWORD clause is used to provide a password when retrieving data
from an ADABAS file which is password protected.

The CIPHER clause is used to provide a cipher key when retrieving data from
an ADABAS file which is enciphered

*ISN / operand3 must be provided either in the form of a numeric constant or


user-defined variable.

Copyright 2010 Accenture All Rights Reserved.

115

EXAMPLE: DEFINE DATA LOCAL 1 EMS-MAST VIEW OF EMS-MAST 2 EQ-ID 2 STATUS-CD 1 #ISN-ARRAY (N2/1:5) 1 #LINE-NR(N2) END-DEFINE LIMIT 5 READ EMS-MAST BY EQ-ID MOVE *COUNTER TO #LINE-NR MOVE *ISN TO #ISN-ARRAY(#LINE-NR) DISPLAY #LINE-NR EQ-ID AT END OF DATA INPUT / 'SELECT LINE-NR FOR STATUS-CD' #LINE-NR IF #LINE-NR = 1 THRU 5

Copyright 2010 Accenture All Rights Reserved.

116

GET EMS-MAST #ISN-ARRAY (#LINE-NR) WRITE 'EQ-ID' EQ-ID 'STATUS-CD' STATUS-CD END-IF END-ENDDATA END-READ END RESULT: #LINE-NR EQUIPMENT ID ------------------1 N00001 2 N00002 3 N00003 4 N00004 N00005 SELECT LINE-NR FOR STATUS-CD : 1 EQ-ID N00001 STATUS-CD 8

Copyright 2010 Accenture All Rights Reserved.

117

GET SAME FUNCTION: The GET SAME statement is used to re-read the record currently being processed It is frequently used to obtain database array values SYNTAX: Structured Mode GET SAME [ ( r) ]

Reporting Mode GET SAME [ (r) ] [ operand1.] The notation r is used to specify the statement which contains the FIND
or READ statement used to initially read the record. As OPERAND 1 we can specify the field(s) to be made available as a result of the GET SAME statement.OPERAND 1 cannot be specified if the field is defined in DEFINE DATA statement. An UPDATE or DELETE statement must not reference a GET statement

Copyright 2010 Accenture All Rights Reserved.

118

EXAMPLE READ POST ADDRESS BY NAME COMPRESS NAME FIRST NAME INTO #NAME WITH DELIMITER , WRITE // 12T #NAME WRITE / 12T ADDRESS LINE (I.1) IF C*ADDRESS LINE > 1 FOR I = 2 TO C*ADDRESS LINE GET SAME /* READ NEXT OCCURRENCE WRITE 12T ADDRESS LINE (I.1) END FOR END IF WRITE / POST CODE CITY SKIP 3 END READ

END

Copyright 2010 Accenture All Rights Reserved.

119

ACCEPT/REJECT
FUNCTION:

The statements ACCEPT/REJECT are used to accepting/rejecting a record


based on user-specified logical criterion.These statements can be used in conjunction with statements which read data records in a processing loop.

The criterion is evaluates after record has been selected/read When these statements are used in subroutines,in case of a record reject, the
subroutine entered in the processing loop will be terminated and processing will continue with the next record of the innermost currently active loop.

ACCEPT/REJECT statements allow you to specify logical conditions in


addition to those that were specified in WITH and WHERE clauses of the FIND/ READ statements

Copyright 2010 Accenture All Rights Reserved.

120

When ACCEPT/REJECT is used with a HISTOGRAM statement ,only database


field specified in HISTOGRAM statement may be used as logical criterion.

ACCEPT/REJECT processing does not cause a held record to be released


from hold status unless the profile parameter RI has been set to RI=ON

SYNTAX:
ACCEPT

[IF] logical-condition-criteria

REJECT [IF] logical-condition-criteria

Copyright 2010 Accenture All Rights Reserved.

121

EXAMPLE: DEFINE DATA LOCAL USING WHOLDA * Contains Personnel Id, First name, Name, City, * Country, Zip code, Marital status, sex & Birth date LOCAL 1 #CITY (A15) END-DEFINE FIND OWNERS WITH CITY = BOSTON ACCEPT IF COUNTRY = USA DISPLAY PERSONNEL ID NAME CITY COUNTRY END-FIND END

Copyright 2010 Accenture All Rights Reserved.

122

EXAMPLE: DEFINE DATA LOCAL USING WHOLDA * Contains Personnel Id, First name, Name, City, * Country, Zip code, Marital status, sex & Birth date LOCAL 1 #CITY (A15) END-DEFINE FIND OWNERS WITH CITY = BOSTON REJECT IF COUNTRY = USA DISPLAY PERSONNEL ID NAME CITY COUNTRY END-FIND END

Copyright 2010 Accenture All Rights Reserved.

123

LIMIT FUNCTION:

The LIMIT statement is used to limit the number of iterations of a processing


loop initiated with a FIND,READ, or HISTOGRAM statements.

The limit remains in effect for all subsequent processing loops in the program
until it is overridden with another LIMIT statement.

The LIMIT statement does not apply to individual statements in which limit
is explicitly specified.

If no LIMIT statement is specified, the default limit defined during NATURAL


installation will be used.

Copyright 2010 Accenture All Rights Reserved.

124

SYNTAX LIMIT n The LIMIT n must be specified as a numeric constant in the range from 0 to 99999999 (leading 0 are optional).The processing loop is not entered if the limit is set to 0. A record that is rejected because of criteria specified in a FIND or READ statement WHERE clause is not counted against the limit. A record that is rejected as a result of an ACCEPT/REJECT statement is counted against the limit. EXAMPLE READ EMPLOY-VIEW BY NAME STARTING FROM BAKER DISPLAY NOTITLE NAME PERSONNEL-ID CITY *COUNTER END-READ END

Copyright 2010 Accenture All Rights Reserved.

125

STORE FUNCTION: STORE statement adds a new record to the database

SYNTAX: STORE [RECORD] [IN] [FILE] view-name [PASSWORD = operand1] [CIPHER = operand2] [ [ USING/GIVING] NUMBER operand3 ] [ ( r ) ] IN REPORTING MODE: STORE [RECORD] [IN] [FILE] view-name [PASSWORD = operand1] [CIPHER = operand2] [ [ USING/GIVING] NUMBER operand3 ] [ ( r ) ] { [ USING ] SAME [RECORD] [AS] [STATEMENT [ ( r ) [SET/WITH ] [ operand4 - operand5] }

Copyright 2010 Accenture All Rights Reserved.

126

The PASSWORD clause is used to provide a password when updating data from
a file which is password protected.

The CIPHER clause is used to provide a cipher key when updating data from a
file which is enciphered

USING/GIVING NUMBER is used to store a record with a user-supplied


ADABAS ISN

SET/WITH can be used to specify the fields for which values are being provided
USING SAME is used to indicate that the same field values as read in the
statement referenced by the STORE statement (FIND,GET,READ) are to be used to add a new record

*ISN contains the ADABAS ISN assigned to the new record as a result of the
STORE statement execution.

Copyright 2010 Accenture All Rights Reserved.

127

UPDATE FUNCTION:

UPDATE statement updates a record in the database. The record to be updated must have been selected with a FIND,GET or READ
statement

The UPDATE statement must not be entered on the same line as the statement
used to select the record to be updated.

Copyright 2010 Accenture All Rights Reserved.

128

SYNATX: UPDATE [RECORD] [IN] [STATEMENT] [ ( r ) ] REPORTING MODE SYNTAX: UPDATE [RECORD] [IN] [STATEMENT] [ ( r ) ] [SET/WITH/USING] {SAME [RECORD] {operand1 - operand2 } }

The notation ( r ) is used to indicate the statement in which the record to be


modified was read.It can be specified as a source-code line number or as a statement label The USING SAME clause is used to indicate that the same fields as read in the statement referenced by the UPDATE statement are to be used for the update function. SET/WITH clause is used to specify the fields to be updated and the values to be used. The use of the UPDATE statement causes each record read for processing in the corresponding FIND or READ statement to be placed in hold status

Copyright 2010 Accenture All Rights Reserved.

129

EXAMPLE
FIND EMPLOY VIEW WITH NAME = #NAME IF NO RECORDS FOUND REINPUT WITH NO RECORDS FOUND MARK 1 END NOREC INPUT NAME: NAME (AD=O) / FIRST NAME: FIRST NAME (AD=M) / CITY: CITY (AD=M) UPDATE END TRANSACTION END FIND END

Copyright 2010 Accenture All Rights Reserved.

130

DELETE FUNCTION:

The DELETE clause deletes a record from the database.


SYNTAX:

DELETE [RECORD] [IN] [STATEMENT] [ ( r ) ]

The notation ( r ) is used to reference the statement which was used


to select /read the record to be deleted.

The use of DELETE statement causes each record selected in the


corresponding FIND or READ statement to be placed in hold status.

Copyright 2010 Accenture All Rights Reserved.

131

EXAMPLE: FIND EMPLOY VIEW WITH NAME = ALDEN DELETE END TRANSACTION AT END OF DATA WRITE NOTITLE *NUMBER RECORDS DELETED END ENDDATA END FIND END END TRANSACTION FUNCTION: The END TRANSACTION statement is used to indicate the end of a logical transaction. Successful execution of an END TRANSACTION statement ensures that all updates performed during the transaction have been or will be physically applied to the database. The END TRANSACTION statement also results in the release of all records placed in hold status during the transaction.

Copyright 2010 Accenture All Rights Reserved.

132

SYNTAX: END [OF] TRANSACTION [operand1] EXAMPLE: FIND EMPLOY VIEW WITH CITY = BOSTON ASSIGN COUNTRY = USA UPDATE END TRANSACTION

BACKOUT TRANSACTION FUNCTION: The BACKOUT TRANSACTION statement back out all database updates performed during the current logical transaction . This statement releases all records held during the transaction. SYNTAX: BACKOUT [TRANSACTION]

Copyright 2010 Accenture All Rights Reserved.

133

EXAMPLE: INPUT UPDATE TO BE PERFORMED YES/NO: #RESP DECIDE ON FIRST #RESP VALUE YES END TRANSACTION VALUE NO BACKOUT TRANSACTION NONE REINPUT PLEASE ENTER YES OR NO END DECIDE END

Copyright 2010 Accenture All Rights Reserved.

134

AT START OF DATA FUNCTION: The statement AT START OF DATA is used to perform processing immediately after the first set of records is read for a processing loop that has been initiated by READ/FIND/HISTOGRAM/SORT/READ WORK FILE.

If the statement contains a WHERE clause, the AT START OF DATA condition


will be true when the first record is read which meets both basic search and the WHERE criteria.

The statement is non-procedural.

The statement must be positioned within a processing loop and it must be used
only once per processing loop

Copyright 2010 Accenture All Rights Reserved.

135

SYNTAX: Structured Mode Syntax : [AT] START [OF] DATA [(r)] Statement(s) END-START Reporting Mode Syntax : [AT] START [OF] DATA [(r)] { DO statement(s).. DOEND} An AT START OF DATA statement may be related to a specific outer processing loop by using the ( r ) notation. EXAMPLE: DEFINE DATA LOCAL 1 EMS-REPAIR-HIST VIEW OF EMS-REPAIR-HIST 2 EQ-ID 2 WO-NO 2 TYPE-REPAIR-CD END-DEFINE
Copyright 2010 Accenture All Rights Reserved. 136

READ (5) EMS-REPAIR-HIST BY EQ-ID AT START OF DATA DISPLAY 'AT START' DISPLAY EMS-REPAIR-HIST DISPLAY 'HOLDS THE FIRST RECORD VALUES' END-START DISPLAY EMS-REPAIR-HIST END-READ

END
OUTPUT: AT START A03456 49462C 00001 HOLDS THE FIRST RECORD VALUES A03456 49462C 00001 A03456 49462D 96205 A06566 53493A A45735 12612A A45735 12612B 95430

Copyright 2010 Accenture All Rights Reserved.

137

AT END OF DATA FUNCTION:

The AT END OF DATA statement is used to specify processing too be performed when all
records selected for a database processing loop have been processed.

This statement is non-procedural.

This statement can only be used in a processing loop that has been initiated with one of
the following statements FIND/READ/READ WORK FILE/HISTOGRAM/SORT.It may be used only once per processing loop.

Copyright 2010 Accenture All Rights Reserved.

138

SYNTAX: Structured Mode Syntax [AT] END [OF] DATA [(r)] Statement END-ENDDATA Reporting Mode Syntax [AT] END [OF] DATA [(r)] {Statement} {DO statement DOEND} An AT END OF DATA statement may be related to a specific active processing loop by using the ( r ) notation When the AT END OF DATA condition for the processing loop occurs, all database fields contain the data from the last record processed. EXAMPLE: DEFINE DATA LOCAL 1 EMS-MAST VIEW OF EMS-MAST 2 EQ-ID 2 STATUS-CD END-DEFINE
Copyright 2010 Accenture All Rights Reserved. 139

LIMIT 5 R1. READ EMS-MAST WITH EQ-ID STARTING FROM 'R' DISPLAY EQ-ID AT END OF DATA DISPLAY 'End of Data:' DISPLAY EQ-ID END-ENDDATA END-READ END Output: EQUIPMENT ID R00001 R00002 R00003 R00004 R00005 End of Data: R00005
Copyright 2010 Accenture All Rights Reserved. 140

AT BREAK FUNCTION:

The AT BREAK statement performs control break processing executing the coded
statement where there is a change in the control field. Valid for FIND, READ, SORT, HISTOGRAM and READ WORK FILE Loops. This statement is non-Procedural. SYNTAX: [AT] BREAK [reference/label] [OF] { Field name/ Variable } [/n] { Statement(s)/ DO statement (s) DOEND } { END-BREAK/ [LOOP [(reference/label)]]}

Copyright 2010 Accenture All Rights Reserved.

141

/n indicates select number of positions to be evaluated ,left to right a byte at a time. [(Reference/label)] refers to loop initiating statement other than the main loop for control break
processing during final break evaluation. EXAMPLE: DEFINE DATA LOCAL 1 EMS-MAST VIEW OF EMS-MAST 2 EQ-ID 2 STATUS-CD 2 LOC 2 PRICE-PURCH END-DEFINE READ EMS-MAST BY LOC-EQ-ID IF LOC = ' ' ESCAPE TOP END-IF DISPLAY LOC EQ-ID PRICE-PURCH AT BREAK OF LOC WRITE "SUM" OLD(LOC) SUM(PRICE-PURCH) END-BREAK END-READ END
Copyright 2010 Accenture All Rights Reserved. 142

Output === for Sum LOC EQUIPMENT ID PURCH PRICE A00001 N10567 43865.00 SUM A00001 43865.00 A00002 N00306 6167.93 A00002 N00831 4249.00 A00002 N00977 7900.00 A00002 N01116 25594.00 A00002 N01335 1199.68 A00002 N04979 3700.00 A00002 N05393 17900.00 A00002 N08502 12158.33 A00002 N12329 2466.54 A00002 N12956 2489.00 A00002 N14027 2795.00 A00002 N34139 960.94 A00002 N47759 211.00

SUM
Copyright 2010 Accenture All Rights Reserved. 143

BEFORE BREAK PROCESSING FUNCTION:

The BEFORE BREAK PROCESSING is used to initialize or compute values of userdefined variables which are to be used in break processing. You can specify statements that are to be executed immediately before a control break. If no break processing is to be performed (that is, no AT BREAK statement is specified for the processing loop), any statements specified with a BEFORE BREAK PROCESSING statement will NOT be executed. The BEFORE BREAK PROCESSING statement may only be used with a processing loop that has been initiated with one of the following statements: FIND, READ, HISTOGRAM, SORT or READ WORK FILE. It may be placed anywhere within the processing loop and is always related to the processing loop in which it is contained. Only ONE before break processing statement may be specified per processing loop.

Copyright 2010 Accenture All Rights Reserved.

144

EXAMPLE:
DEFINE DATA LOCAL 1 JOBS VIEW OF EMPLOYEES 2 NAME 2 JOB-TITLE 2 SALARY (1) 2 BONUS (1,1) 1 #TOT-SALARY (N10) END-DEFINE LIMIT 6 READ JOBS BY JOB-TITLE STARTING FROM 'A' THRU 'D' ACCEPT IF SALARY (1) GT 0 COMPUTE #TOT-SALARY = SALARY (1) + BONUS (1,1) DISPLAY NOTITLE (SG = OFF) NAME SALARY (1) BONUS (1,1) 'TOTAL/SALARY' #TOT-SALARY

Copyright 2010 Accenture All Rights Reserved.

145

BEFORE BREAK PROCESSING ACCEPT IF SALARY (1) GT 0 END-BEFORE AT BREAK OF JOB-TITLE PRINT 'POSITIONS OF ' JOB-TITLE COUNT (JOB-TITLE) SUM (#TOT-SALARY) END-BREAK END-READ END OUTPUT: OUTPUT: NAME ANNUAL BONUS TOTAL SALARY SALARY ------------------------------- --------------- ----------- -----------SUMMERSCALE 5400 0 5400 PRINCE 4850 0 4850 GERMAN 4550 0 4550 PREAKNESS 5500 200 5700 KELLEWAY 5450 100 5550 CRUIKSHANKS 4500 0 4500 POSITIONS OF AGENT DE MAITRISE 6 30550

Copyright 2010 Accenture All Rights Reserved.

146

PERFORM BREAK PROCESSING FUNCTION:

Used to invoke user-initiated break processing. Executes statements specified by AT BREAK when change in control field occurs. Used for data access loops and FOR,REPEAT,CALL LOOP and CALL FILE loops. Executed as it is encountered in normal logic flow. Immediately after the PERFORM BREAK PROCESSING, you specify one or more AT BREAK statement blocks. When a PERFORM BREAK PROCESSING is executed, NATURAL checks if a break has occurred; that is, if the value of the specified control field has changed; and if it has, the specified statements are executed. SYNTAX: PERFORM [BREAK] [PROCESSING] [AT] BREAK [OF] field [/n/] { statement (s) DO statement (s) DOEND } END-BREAK

Copyright 2010 Accenture All Rights Reserved.

147

DEFINE DATA LOCAL 1 SALARY-HISTORY VIEW OF EMPLOYEES 2 PERSONNEL-ID 2 NAME 2 FIRST-NAME 2 DEPT 2 JOB-TITLE 2 SALARY (1) END-DEFINE READ SALARY-HISTORY BY DEPT = 'TECH00' THRU 'TECH99' END-ALL SORT DEPT JOB-TITLE SALARY (1) USING NAME IF DEPT = 'TECH10' PERFORM BREAK PROCESSING AT BREAK OF JOB-TITLE WRITE 'SALES DATA FOR JOB:' OLD(JOB-TITLE) 59T SUM(SALARY(1)) END-BREAK DISPLAY DEPT JOB-TITLE NAME SALARY (1) END-IF AT BREAK OF DEPT DISPLAY OLD(DEPT) COUNT(DEPT) T*SALARY(1) SUM(SALARY(1)) END-BREAK END-SORT

END
Copyright 2010 Accenture All Rights Reserved. 148

OUTPUT : DEPARTMENT CURRENT CODE POSITION -------------------- ------------------------TECH01 13 TECH02 19 TECH03 2 TECH04 1 TECH05 18 TECH08 1 TECH10 ANALYST TECH10 ANALYST TECH10 ANALYST TECH10 ANALYST TECH10 ANALYST TECH10 ANALYST TECH10 ANALYST SALES DATA FOR JOB: ANALYST

NAME ----------------

WEINBERG BIRKHOF RUSCONI SMITH BONNER ATHERTON MARON

ANNUAL SALARY -------------4525700 8897700 389250 193450 1358100 175800 34000 34000 34000 43000 43000 43000 43000 1091000

Copyright 2010 Accenture All Rights Reserved.

149

CALLNAT , FETCH , FETCH RETURN , CALL


CALLNAT : The statement provides the capability to invoke a NATURAL subprogram. Parameters can be described as read-only (AD=O) or can be modified by the Subprogram (AD=M) . The position of the parameters is important because the corresponding elements In the parameter data area of the subprogram must agree in type,format and length.If you pass a group name,natural replaces it with the group items. Example : CALLNAT PROGRAM-1 #VAR-1 #VAR-2 #VAR-3 CALLNAT PROGRAM-2 #PARM1 (AD=O) #PARM2 (AD=M)

Copyright 2010 Accenture All Rights Reserved.

150

FETCH / FETCH RETURN : This statement allows for a NATURAL Program to be loaded and executed.The program is written like a main program,however the RETURN option allows for the program to be handled like a combination of a subprogram and a subroutine it can be passed parameters and it has access to the GDA.The FETCH RETURN mechanism increments the level in which you are processing .Control is released to the fetching program when an END or ESCAPE ROUTINE is encountered. A FETCHed object does not change the level at which programs execute.Data is available to the FETCHed module either via the NATURAL stack or thru GLOBAL data area.Any parameters listed with the fetch statement are placed on the top of the stack.They are accepted by the first INPUT statement encountered in the FETCHed module. CALL : This call statement invokes a non-NATURAL external routine.The parameter list may have upto 40 items.Standard linkage conventions are used.After successfully returning from the called routine ,the calling program returns control to the next statement after the CALL statement.

Copyright 2010 Accenture All Rights Reserved.

151

DECIDE FOR (FIRST/EVERY ) : This statement is used to execute one or more actions depending on multiple conditions.

This is similar to CASE statement in other programming language.


DECIDE FOR FIRST CONDITION WHEN #ORDER-AMT >= 1000 COMPUTE #DISCOUNT = PRICE * .25 WHEN #ORDER-AMT >= 100 COMPUTE #DISCOUNT = PRICE * .15 WHEN #ORDER-AMT >= 10 COMPUTE #DISCOUNT = PRICE * .05 WHEN NONE COMPUTE #DISCOUNT = 0 END-DECIDE

Copyright 2010 Accenture All Rights Reserved.

152

DECIDE FOR EVERY


DECIDE FOR EVERY CONDITION WHEN #ORDER-AMT > 1000 COMPUTE #DISCOUNT = PRICE * .25 WHEN #DATE-PAID > #DUE-DATE COMPUTE #LATE-CHARGE = #ORDER-AMT * .10 WHEN #DATE-PAID <= #EARLY-PAYMENT-DATE COMPUTE #QUICK-PMT-DISC = *ORDER-AMT * .05 WHEN NONE IGNORE END-DECIDE When EVERY is used in a DECIDE FOR statement one or all of the following conditions can be used : - WHEN WHEN ALL WHEN ANY WHEN NONE When FIRST is used , every condition statement, except for WHEN ALL, may be used.

Copyright 2010 Accenture All Rights Reserved.

153

DECIDE ON
It used to perform a single or multiple action depending on the value of a specified variable. DECIDE ON FIRST VALUE OF *PF-KEY VALUE PF1 PERFORM ADD-PART VALUE PF2 PERFORM DEL-PART NONE VALUR IGNORE END-DECIDE

Copyright 2010 Accenture All Rights Reserved.

154

QUESTIONS ?

Copyright 2010 Accenture All Rights Reserved.

155

THANK YOU

Copyright 2010 Accenture All Rights Reserved.

156

You might also like