Beruflich Dokumente
Kultur Dokumente
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.
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.
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 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.
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
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
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
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
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
Types of Variables and Data Areas Defining Database Views Defining User Variables Redefinition Of Variables
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
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
15
Ease of access
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
18
Example : Data definition using a GDA DEFINE DATA GLOBAL USING INVDATA /* GDA FOR INVOICING APPLICATION LOCAL USING INVREDEF /* LDA REDEFINING INVOICING GDA . END-DEFINE .
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.
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
* 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
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
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 .
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)
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
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
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
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.
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
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
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.
35
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
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.
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.
38
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.
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
40
41
42
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
43
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
P5 P10 A4
A10 N3 A8
45
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
46
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)
47
*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
48
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
50
as field
All the above functions except TOTAL are automatically reset after its evaluating condition criteria are met (BREAK,GIVE FUNCTIONS..)
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
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
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)
55
Simple Statements
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
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.
57
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.
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.
62
SYNTAX:
EXAMINE [FULL[VALUE[OF]]] [SUBSTRING] Constant Field-Name Variable Array
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.
64
EXAMINE #TEXT FOR #A WITH DELIMITER REPLACE WITH * GIVING NUMBER #NMBEX2
WRITE = #TEXT = #NMBEX2 WRITE / Example 3 (REPLACE, GIVING NUMBER) WRITE = #TEXT
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
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.
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
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
74
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
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
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
77
WRITE Statement
Produces output horizontally from left-to-right. Separated by single space or by SF parameter No Column headers are produced
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.
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
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
Arithmetic Processing
Topics Covered
Add and Subtract statements Multiply and Divide statements Compute statement Mathematical Functions
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.
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
85
Examples:
1.
2. 3.
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
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
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.
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
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
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.
91
[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
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
If the value of OPERAND1 is changed within the READ loop,this does not affect the
number of records read.
security.
CIPHER is used to decrypt the data that has been stored with cipher code.This can be
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)]
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]]
95
EXAMPLE:
LIMIT 100 READ (100) EMPLOYEES BY ISN STARTING FROM 500 THRU 1000 END-READ READ LOGICAL:
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
98
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.
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
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
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
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)
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.
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.
104
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.
105
*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
106
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
108
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
109
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.
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)
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.
112
*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
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
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
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
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
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
119
ACCEPT/REJECT
FUNCTION:
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.
120
SYNTAX:
ACCEPT
[IF] logical-condition-criteria
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
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
123
LIMIT FUNCTION:
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.
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
125
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] }
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
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.
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.
128
SYNATX: UPDATE [RECORD] [IN] [STATEMENT] [ ( r ) ] REPORTING MODE SYNTAX: UPDATE [RECORD] [IN] [STATEMENT] [ ( r ) ] [SET/WITH/USING] {SAME [RECORD] {operand1 - operand2 } }
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
130
DELETE FUNCTION:
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.
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]
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
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.
The statement must be positioned within a processing loop and it must be used
only once per processing loop
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
137
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 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.
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)]]}
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
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.
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
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
146
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
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 ----------------
ANNUAL SALARY -------------4525700 8897700 389250 193450 1358100 175800 34000 34000 34000 43000 43000 43000 43000 1091000
149
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.
151
DECIDE FOR (FIRST/EVERY ) : This statement is used to execute one or more actions depending on multiple conditions.
152
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
154
QUESTIONS ?
155
THANK YOU
156