NATURAL Programming Version 1.1
February 19, 2009
Banking & Financial Services
[email protected]
Page 1 of 40
DOCUMENT RELEASE NOTICE
Version
Dr af t
Author
Shobana Pat cha chai
Date
19/ 02/ 2009
Changes Done
I ni t i al Dr af t
Page 2 of 40
DOCUMENT RELEASE NOTICE
Version
Dr af t
Author
Shobana Pat cha chai
Date
19/ 02/ 2009
Changes Done
I ni t i al Dr af t
Page 2 of 40
DOCUMENT RELEASE NOTICE TABLE OF CONTENTS INTRODUCTION------------------INTRODUCTION------------------------------------------------------------------------------------------4 -------4 NATURAL OVERVIEW OVERVIEW - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -5 NATURAL COMMANDS COMMANDS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -7 OVERVIEW----------------------------------------------------------------------- 7 CHANGING LIBRARIES------------------------------------------------------7 PROGRAM EDITOR----------------------------------------------------------7 EDITOR COMMANDS---------------------------------------------------------8 LINE COMMANDS-----------------------------------------------------------9 CLONING A NATURL PROGRAM------------------------------------------------9
NATURAL LANGUAGE LANGUAGE – AN OVERVIEW ON CORE CONCEPTS----------------CONCEPTS-----------------------10 ------10 PROGRAMMING MODES-------------------------------------------------------10 VIEW DEFINITION DEFINITION-------------------------------------------------------------------------------------------------------13 ----13
GROUP VA VARI ABL ES- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 14 SYSTEM VARIABLES--------------------------------------------------------15
DATABASE ACCESS------------------------ACCESS----------------------------------------------------------------------------------- 15 DATABASE MAINTENANCE-------------------MAINTENANCE------------------------------------------------------------------------------ 17 LOOP EXECUTUING STATEMENTS---------------------STATEMENTS------------------------------------------------------------20 -------20 PROGRAM AND SESSION TERMINATION------------------TERMINATION--------------------------------------------------------22 ----22 NATURAL REPORT FUNCTIONS------FUNCTIONS------------------------------------------------------------------------------23 -------23 SEQUENTIAL FILE PROCESSING---------------------PROCESSING------------------------------------------------------------26 -------26 READ WORKFILE------------------------------------------------------------26 WRITE WORKFILEWORKFILE---------------------------------------------------------------------------------------------------------27 -----27 CLOSE WORKFILE-----------------------------------------------------------27 JCL CONSIDERATIONS-------------------------------------------------------28
INTERACTIVE PROGRAMMING------------------PROGRAMMING---------------------------------------------------------------29 -------------29 SYSTEM CONSTRUCTS-----CONSTRUCTS-------------------------------------------------------------------------------------3 ---------------34 4
Page 3 of 40
INTRODUCTION ABOUT THIS MANUAL MANUAL Thi s manual anual i s i nt ended ended as a t r ai ni ng document , especi al l y f or begi begi nner nner s NATUR TURAL, whi ch wi l l pave pave t he way f or l ear ear ni ng adva advance nced d Nat ur al Concep onceptt s. Thi s i s an evol vi ng and l i ve document . cou cour se of t he sup suppor t , i f necessa cessarr y.
Ther Ther e wi l l
in
be updat updat es t o t hi s dur dur i ng t he
Page 4 of 40
NATURAL – OVERVIEW •
Procedural / Non- Procedural
•
Free Format
•
Online / Batch
•
•
ADABAS/ Sequential/ DB2 Structured
/ Reporting
TYPES OF PROGRAMMING OBJECTS Wi t hi n a Nat ur al appl i cat i on, several t ypes of obj ect s can be used t o achi eve an ef f i c i ent appl i c at i on s t r uc t ur e . Ther e ar e t he di f f er ent t ypes of Nat ur al obj ect s:
•
Progr am
•
Cl ass
•
SubPr ogr am
•
SubRout i ne
•
Copycode
•
Hel pRout i ne
•
Text
•
Maps
•
Local Dat a Ar ea
•
Gl obal Dat a Ar ea
•
Par amet er Dat a Ar ea
Page 5 of 40
The Nat ur al Main Menu l ooks si mi l ar t o t he exampl e shown bel ow:
Page 6 of 40
NATURAL COMMANDS
•
OVERVIEW
•
CHANGING LIBRARIES
•
PROGRAM EDITOR
•
EDITOR COMMANDS
•
LINE COMMANDS
•
CLONING A NATURL PROGRAM
OVERVIEW
•
Nat ur al Commands ar e used t o mai nt ai n pr ogr am obj ect s.
•
When pr ogr ams ar e saved, a copy i s pl aced i n an ADABAS f i l e ( FUSER)
CHANGING LIBRARIES •
•
Change Li br ar i es by ent er i ng t he LOGON command Al l sour ces ar e uni quel y i dent i f i ed by t he pr ogr am name / l i br ar y name combi nat i on.
Page 7 of 40
PROGRAM EDITOR
The pr ogr am Edi t or sc r een cont ai ns t he f ol l owi ng i t ems ( Fr om t op t o bot t om) :
•
•
Edi t or Command Li ne Top I nf or mat i on Li ne
•
Edi t i ng Ar ea
•
Bot t om I nf or mat i on Li ne
EDITOR COMMANDS CLEAR
-
Er ases t he cont ent s of t he Pr ogr am.
-
No ef f ect s on t he cont ent s of FUSER.
-
Reads t he speci f i ed sour ce f r om FUSER f i l e and pl aces i n t he Edi t Work Ar ea.
-
Cur r ent cont ent s of Edi t Work Ar ea ar e over l ai d.
READ
Page 8 of 40
CHECK
-
Er r ors poi nt ed out one at a t i me.
-
Does not save sour ce.
-
I ssue CHECK command of t en.
-
Somet i mes t he edi t or poi nt s t o t he l i ne whi ch cont ai ns t he er r or.
RUN
- Per f orms a synt ax check and, i f no er r ors wi l l execut e t he pr ogr am - Does not save sour ce. - Run of t en t o t est t he pr ogr am as u bui l t i t . STOW
- Per f orms a synt ax check of t he sour ce i n t he edi t or work ar ea. - I f no er r ors , saves t he sour ce and obj ect I n FUSER. - I f an er r or i s f ound, t he er r or i s poi nt ed out and t he STOW pr ocess i s t er mi nat ed. - STOW of t en t o ensur e t he sour ce and t he obj ect mat ch. EXECUTE
- Execut es t he OBJ ECT modul e f r om FUSER. - Execut i ng i s f ast er t han Runni ng. FIN
- Ter mi nat es t he NATURAL Sessi on. SCAN
- Thi s command sc ans t he sour ce code f or a char act er st r i ng ( sc anval ue) . - I f t he suppl i ed scan- val ue i s ent er ed wi t hout del i mi t er char act er s, f or exampl e, SCAN ABC D, t he ent i r e char act er st r i ng whi ch f ol l ows t he keywor d SCAN i s used as t he scan val ue. - I f you ent er SCAN wi t hout any par amet er , t he SCAN/ REPLACE wi ndow i s i nvoked, wher e we can r epl ace wi t h some ot her val ues.
Page 9 of 40
LINE COMMANDS
. C ( nnn)
- Copi es t he l i ne i n whi ch t he command was ent er ed.
. CX –Y mar ker s.
- Copi es t he bl ock of l i nes del i mi t ed by t he X and Y
•
. D ( nnn)
- Del et es l i ne or l i nes. The def aul t i s 1 l i ne.
•
. MX- Y
- Moves t he bl ock of l i nes del i mi t ed by t he X and Y marker s.
•
.P
- Posi t i ons t he l i ne mar ked wi t h t hi s command t o t he t op of t he Scr een.
•
.S
- Spl i t s t he l i ne at t he posi t i on mar ked wi t h t he cur sor .
•
•
CLONING A NATURL PROGRAM
•
Edi t t he pr ogr am t o be copi ed.
•
SAVE t he sour ce speci f yi ng t he new name.
•
READ t he new name.
Page 10 of 40
NATURAL LANGUAGE – AN OVERVIEW ON CORE CONCEPTS
•
Pr ogr ammi ng Modes
•
Vi ew Def i ni t i on
•
Gr oup Fi el ds, Redef i ni t i ons, I ni t i al Val ues
•
Syst em Var i abl es
PROGRAMMING MODES Nat ur al of f er s t wo ways of pr ogr ammi ng: •
Repor t i ng Mode
•
St r uct ur ed Mode
Gener al l y, i t i s r ecommended t o use st r uct ur ed mode excl usi vel y, because i t pr ovi des f or mor e cl ear l y str uct ur ed appl i cat i ons.
REPORTING MODE Report i ng mode i s pr ogr ams whi ch do ( I f you deci de t o pr ogr ams may easi l
onl y usef ul f or t he cr eat i on of adhoc report s and smal l not i nvol ve compl ex dat a and/ or pr ogr ammi ng const r uct s. wr i t e a pr ogr am i n r eport i ng mode, be aware t hat smal l y become l ar ger and mor e compl ex. )
STRUCTURED MODE St r uct ur ed mode i s i nt ended f or t he i mpl ement at i on of compl ex appl i cat i ons wi t h a cl ear and wel l - def i ned pr ogr am st r uct ur e. The maj or benef i t s of st r uct ur ed mode ar e: •
•
The pr ogr ams have t o be wr i t t en i n a mor e st r uct ur ed way and ar e t her ef or e easi er t o read and consequent l y easi er t o mai nt ai n. As al l f i el ds t o be used i n a pr ogr am have t o be def i ned i n one cent r al l ocat i on ( i nst ead of bei ng scat t er ed al l over t he pr ogr am, as i s possi bl e i n r epor t i ng mode) , over al l cont r ol of t he dat a used i s much easi er .
Page 11 of 40
Wi t h st r uct ur ed mode, you al so have t o make mor e det ai l pl anni ng bef or e t he act ual pr ogr ams c an be coded, t her eby avoi di ng many pr ogr ammi ng er r or s and i nef f i c i enc i es .
SETTING OR CHANGING THE PROGRAMMING MODE
•
To swi t ch t o St r uct ur ed Mode :
GLOBALS SM=ON
•
To swi t ch t o Repor t i ng Mode :
GLOBALS SM=OFF
REPORTING MODE EXAMPLE The r epor t i ng mode exampl e uses t he st at ement s DO and DOEND t o mar k t he begi nni ng and end of t he st at ement bl ock t hat i s based on t he AT END OF DATA condi t i on. The END st at ement cl oses al l act i ve pr ocessi ng l oops. READ EMPLOYEES BY PERSONNEL- I D DI SPLAY NAME BI RTH AT END OF DATA DO SKI P 2 WRI TE / ' LAST SELECTED: ' OLD( NAME) DOEND END
STRUCTURED MODE EXAMPLE The st r uct ur ed mode exampl e uses an END- ENDDATA st at ement t o cl ose t he AT END OF DATA condi t i on, and an END- READ st at ement t o cl ose t he READ l oop. The r esul t i s a mor e cl ear l y st r uct ur ed pr ogr am i n whi ch you can see i mmedi at el y where each const r uct begi ns and ends: DEFI NE DATA LOCAL 1 MYVI EW VI EW OF EMPLOYEES 2 PERSONNEL- I D 2 NAME 2 BI RTH END- DEFI NE READ MYVI EW BY PERSONNEL- I D DI SPLAY NAME BI RTH AT END OF DATA SKI P 2 WRI TE / ' LAST SELECTED: ' OLD( NAME) END- ENDDATA END- READ END
Page 12 of 40
DATABASE REFERENCE
REPORTING MODE I n r epor t i ng mode, dat abase f i el ds and DDMs may be r ef er enced wi t hout havi ng been def i ned i n dat a ar ea.
STRUCTURED MODE I n st r uct ur ed mode, each dat abase f i el d t o be used must be speci f i ed i n a DEFI NE STATEMENT st at ement as descr i bed i n Def i ni ng Fi el ds and Accessi ng Dat a i n a dat a base.
Page 13 of 40
VIEW DEFINITION
•
•
•
•
We must decl ar e al l ADABAS f i l es and Fi el ds i n t he DEFI NE DATA st at ement . The Vi ew Name may be upt o 32 char act er s. Vi ews ar e al ways def i ned at Level 1 and t he f i el ds t he vi ew i s compr i sed of must be on Level 2. For mat s and Lengt hs need not be speci f i ed – NATURAL obt ai ns f r om DDM.
EXAMPLE OF VIEW DEFINITION DEFI NE DATA LOCAL 1 VI EWEMP VI EW OF EMPLOYEES 2 NAME 2 FI RST- NAME 2 BI RTH ... END- DEFI NE
Page 14 of 40
USER FIELDS
•
We may al so decl are non dat abase f i el ds t hat you wi sh t o use i n your pr ogr am assi gned wi t h Level - Number , Name, For mat and Lengt h.
Example :
1
#NAME
( A30)
•
User def i ned var i abl es shoul d begi n wi t h #.
•
Decl ar ed i n t he DEFI NE DATA st at ement .
VARIABLE FORMATS AND LENGTHS •
Al phanumer i c
- max 253
•
Numeri c
- max 29 di gi t s ( 7 deci mal )
•
Packed Number s
- max 29 di gi t s ( 7 deci mal )
•
Logi cal Var i abl es
- TRUE or FALSE
GROUP FIELDS, VARIABLE REDEFINITIONS AND INITIAL VALUES •
I f you r edef i ne a f i el d, t he REDEFI NE opt i on must be on t he same l evel as t he or i gi nal f i el d, and t he f i el ds resul t i ng f r om t he r edef i ni t i on must be one l evel l ower . For det ai l s on r edef i ni t i ons, see Redef i ni ng Fi el ds .
DEFI NE DATA LOCAL 1 VI EWEMP VI EW OF STAFFDDM 2 BI RTH 2 REDEFINE BIRTH 3 #YEAR-OF-BIRTH (N4) 3 #MONTH-OF-BIRTH (N2) 3 #DAY-OF-BIRTH (N2)
1 #FI ELDA ( A20) 1 REDEFINE #FIELDA 2 #SUBFIELD1 (N5) 2 #SUBFIELD2 (A10) 2 #SUBFIELD3 (N5)
... END- DEFI NE Page 15 of 40
•
Level number s must be consecut i ve and may not exceed 9.
•
I ni t i al Val ues ar e speci f i ed usi ng t he I NI T Keywor d as f ol l ows : 1
Example
•
#NAME
( A30)
I NI T <’ RAM’ >
I f no i ni t i al val ue i s s peci f i ed, al l var i abl es ar e i ni t i al i z ed t o appr opr i at e nul l val ues.
SYSTEM VARIABLES
Some of t he commonl y used Syst em var i abl es are l i st ed bel ow: *DATN – Cur r ent dat e i s YYYYMMDD For mat . •
•
*NUMBER
–
Number of r ecor ds sel ect ed wi t h a FI ND.
•
*COUNTER
–
Number of i t er at i ons t hr ough a dat a l oop.
•
*ISN
–
I nt er nal Sequence Number of an ADABAS r ecor d.
•
*PROGRAM
–
Cur r ent l y Execut i ng Progr am
•
*DATU
–
Cur r ent dat e i n MM/ D/ YY For mat .
•
*TIME
–
Cur r ent t i me i n HH: MM: SS: T For mat
Syst em var i abl es can be used i n I NI T cl auses:
Example
1
#NAME
( A30)
I NI T <*DATU>
STATEMENTS GROUPED BY FUNCTIONS DATABASE ACCESS •
FIND
•
READ
•
HISTOGRAM
•
GET
•
GET SAME
•
•
ACCEPT / REJECT LIMIT
Page 16 of 40
FIND
- Sel ect s a set of r ecor ds f r om an ADABAS Fi l e based on user - speci f i ed cr i t er i a
READ
- Reads a dat abase f i l e i n physi cal or l ogi cal sequence of r ecor ds.
HISTOGRAM
- Reads t he val ues of t he dat abase Fi el ds . - Sequent i al Process s i mi l ar t o READ LOGI CAL. - Ver y usef ul f or Code val i dat i on, Summar y Repor t s. - Ver y Ef f i c i ent .
GET
- Reads a r ecor d wi t h a gi ven I SN( I nt er nal Sequence Number ) or RNO ( Recor d Number )
GETSAME
- Re- r eads t he r ecor d cur r ent l y bei ng pr ocessed.
ACCEPT / REJECT
LIMIT
- Accept s or r ej ect s t he recor ds based on t he User - Speci f i ed cri t er i a.
- Li mi t s t he number of execut i ons of a READ, FI ND or HI STOGRAM Pr ocessi ng Loop.
Page 17 of 40
DATABASE MAINTENANCE
•
RECORD HOLDING
•
END TRANSACTION
•
UPDATE
•
STORE
•
DELETE
RECORD HOLDING •
•
•
•
Recor ds must be “HELD” bef or e t hey can be updat ed. Recor ds aut omat i cal l y hel d i f an UPDATE or DELETE r ef er ences t he access st at ement . Pur pose i s t o ensur e t hat t wo pr ogr ams ar e not per mi t t ed t o updat e t he same r ecor d at t he same t i me. Recor ds hel d can be r ead by ot her pr ogr ams but not f or updat e/ del et e.
END TRANSACTION
The END TRANSACTI ON st at ement i s used t o i ndi cat e t he end of a l ogi cal t r ansacti on. A l ogi cal t r ansacti on i s t he smal l est l ogi cal uni t of wor k (as def i ned by t he user) whi ch must be perf ormed i n i t s ent i r et y t o ensur e t hat t he i nf or mat i on cont ai ned i n t he dat abase i s l ogi cal l y consi st ent . Successf ul execut i on of an END TRANSACTI ON st at ement ensur es t hat al l updat es per f ormed dur i ng t he t r ansact i on have been or wi l l be physi cal l y appl i ed t o t he dat abase r egardl ess of subsequent user, Nat ur al , dat abase or oper at i ng syst em i nt err upt i on. Updat es per f or med wi t hi n a t r ansact i on f or whi ch t he END TRANSACTI ON st at ement has not been successf ul l y compl et ed wi l l be backed out aut omat i cal l y. The END TRANSACTI ON st at ement al so r esul t s i n t he r el ease of al l r ecor ds pl aced i n hol d st at us dur i ng t he tr ansact i on. The END TRANSACTI ON st at ement can be execut ed based upon a l ogi cal condi t i on.
Page 18 of 40
UPDATE •
Used t o change t he cont ent s of one or mor e f i el ds i n an Exi st i ng ADABAS Recor d.
•
Must f i r st r ead r ecor d bef or e updat i ng i t .
•
Any f i el d can be updat ed.
RESTRICTIONS •
•
The UPDATE st at ement must not be ent er ed on t he same l i ne as t he st at ement used t o sel ect t he recor d t o be updat ed. The UPDATE st at ement cannot be appl i ed t o Ent i r e Syst em Ser ver vi ews.
EXAMPLE
** Exampl e ' UPDEX1S' : UPDATE ( st r uct ur ed mode) ** ** CAUTI ON: Execut i ng t hi s exampl e wi l l modi f y t he dat abase r ecor ds! ************************************************************************ DEFI NE DATA LOCAL 1 EMPLOY- VI EW VI EW OF EMPLOYEES 2 NAME 2 FI RST- NAME 2 CI TY * 1 #NAME ( A20) END- DEFI NE * I NPUT ' ENTER A NAME: ' #NAME ( AD=M) I F #NAME = ' ' STOP END- I F * FI ND EMPL OY- VI EW WI TH NAME = #NAME I F NO RECORDS FOUND REI NPUT WI TH ' NO RECORDS FOUND' MARK 1 END- NOREC I NPUT ' NAME: ' NAME ( AD=O) / ' FI RST NAME: ' FI RST- NAME ( AD=M) / ' CI TY: ' CI TY ( AD=M) UPDATE END TRANSACTION
END- FI ND *
Page 19 of 40
STORE
Adds a new r ecor d t o t he ADABAS f i l e and pl aces t he r ecor d i n a hol d st at us.
•
The Nat ur al syst em var i abl e * I SN cont ai ns t he Adabas I SN assi gned t o t he new r ecor d as a r esul t of t he STORE st at ement execut i on. A subsequent r ef er ence t o *I SN must i ncl ude t he st at ement number of t he r el at ed STORE st at ement . DELETE •
•
The DELETE st at ement i s used t o del et e a r ecor d f r om a dat abase.
A DELETE st at ement cannot be speci f i ed i n t he same st at ement l i ne as FI ND, READ or GET st at ement .
EXAMPLE
** Exampl e ' DELEX1' : DELETE **CAUTION: Executing this example will modify the database records!
************************************************************************ DEFI NE DATA LOCAL 1 EMPLOY- VI EW VI EW OF EMPLOYEES 2 NAME END- DEFI NE * FIND EMPLOY-VIEW WITH NAME = 'ALDEN' /* DELETE END TRANSACTION
/* AT END OF DATA WRI TE NOTI TLE * NUMBER ' RECORDS DELETED' END- ENDDATA END- FI ND
Page 20 of 40
LOOP EXECUTION STATEMENTS
•
REPEAT
•
FOR
•
ESCAPE
•
SORT
REPEAT •
Set s a user - def i nes pr ogr am l oop
•
Code an ESCAPE BOTTOM t o avoi d an endl ess l oop.
Example
REPEAT I F condi t i on ESCAPE BOTTOM
END- I F
…. . …. . END- REPEAT
An UNTI L or WHI LE condi t i on may be speci f i ed at t he bot t om of t he l oop FOR •
The FOR st at ement i s used t o i ni t i at e a pr ocessi ng l oop and t o cont r ol t he number of t i mes t he l oop i s processed.
CONSISTENCY CHECK •
Bef or e t he FOR l oop i s ent ered, t he val ues of t he operands ar e checked t o ensur e that t hey ar e consi st ent .
Page 21 of 40
EXAMPLE
** Exampl e ' FOREX1S' : FOR ( st r uct ur ed mode) ************************************************************************ DEFI NE DATA LOCAL 1 #I NDEX ( I 1) 1 #ROOT ( N2. 7) END- DEFI NE * FOR #I NDEX 1 TO 5 COMPUTE #ROOT = SQRT ( #I NDEX) WRI TE NOTI TLE ' =' #I NDEX 3X ' =' #ROOT END- FOR * SKI P 1 FOR #I NDEX 1 TO 5 STEP 2 COMPUTE #ROOT = SQRT ( #I NDEX) WRI TE ' =' #I NDEX 3X ' =' #ROOT END- FOR * END
OUTPUT OF PROGRAM FOREX1S:
#I #I #I #I #I
NDEX: NDEX: NDEX: NDEX: NDEX:
1 2 3 4 5
#ROOT: #ROOT: #ROOT: #ROOT: #ROOT:
1. 0000000 1. 4142135 1. 7320508 2. 0000000 2. 2360679
#I NDEX: #I NDEX: #I NDEX:
1 3 5
#ROOT: #ROOT: #ROOT:
1. 0000000 1. 7320508 2. 2360679
ESCAPE •
•
•
•
The ESCAPE st at ement i s used t o i nt er r upt t he l i near f l ow of execut i on of a pr ocessi ng l oop or a r out i ne. Wi t h t he keywor ds TOP, BOTTOM and ROUTI NE you i ndi cat e wher e pr ocessi ng i s t o cont i nue when t he ESCAPE st at ement i s encount er ed. An ESCAPE TOP/ BOTTOM st at ement , when encount er ed f or pr ocess i ng, wi l l i nt er nal l y r ef er t o t he i nner most act i ve pr ocessi ng l oop. The ESCAPE st at ement need not be physi cal l y pl aced wi t hi n t he pr ocessi ng l oop. I f an ESCAPE TOP/ BOTTOM st at ement i s pl aced i n a r out i ne ( subr out i ne, subpr ogr am, or pr ogr am i nvoked wi t h FETCH RETURN, t he r out i ne( s) ent er ed dur i ng execut i on of t he pr ocessi ng l oop wi l l be ter mi nat ed aut omat i cal l y.
Page 22 of 40
SORT
The SORT st at ement i s used t o per f or m a sor t oper at i on, sor t i ng t he r ecor ds f r om al l pr ocessi ng l oops t hat ar e act i ve when t he SORT st at ement i s execut ed. For t he sor t oper at i on, Nat ur al ' s i nt er nal sor t pr ogr am i s used. I t i s al so possi bl e t o use anot her , ext er nal sor t pr ogr am. RESTRICTIONS •
•
The SORT st at ement must be cont ai ned i n t he same obj ect as t he pr ocessi ng l oops whose r ecor ds i t sor t s. Nest ed SORT st at ement s ar e not al l owed.
•
The t ot al l engt h of a r ecor d t o be sor t ed must not exceed 10240 byt es.
•
The number of sor t cr i t er i a must not exceed 10.
Page 23 of 40
PROGRAM AND SESSION TERMINATION
•
STOP
•
TERMINATE
STOP
The STOP st at ement i s used t o t er mi nat e t he execut i on of a pr ogr am and r et ur n t o t he command i nput pr ompt . One or mor e STOP st at ement s may be i nser t ed anywher e wi t hi n a Nat ur al pr ogr am. The STOP st at ement wi l l t er mi nat e t he execut i on of t he pr ogr am i mmedi at el y. I ndependent of t he posi t i oni ng of a STOP st at ement i n a subr out i ne, any end- page condi t i on speci f i ed i n t he mai n pr ogr am wi l l be i nvoked f or f i nal end- page pr ocessi ng duri ng execut i on of t he STOP st at ement .
TERMINATE
The TERMI NATE st at ement i s used t o t er mi nat e a Nat ur al sess i on. A TERMI NATE st at ement may be pl aced anywher e wi t hi n a Nat ur al pr ogr am. When a TERMI NATE st at ement i s execut ed, no end- of - page or end- l oop pr ocessi ng wi l l be per f ormed. The behavi or of t he TERMI NATE st at ement mat ches t hat of t he STOP st at ement . Pr ocessi ng of r et ur n val ues i s not suppor t ed.
Page 24 of 40
NATURAL REPORT FUNCTIONS Bat ch Report s are an i nt egr al part of any appl i cat i on. Nat ur al pr ovi des a number of bui l t - i n f unct i ons whi ch si gni f i cant l y reduce pr ogr ammi ng ef f or t . Some of t he commonl y used Repor t f unct i ons of NATURAL ar e: •
FORMAT
•
DISPLAY
•
AT TOP OF PAGE
•
WRITE
•
AT BREAK
•
AT END OF DATA SKIP
•
•
NEWPAGE
FORMAT • •
The FORMAT st at ement i s used t o speci f y i nput and out put par amet er set t i ngs. Mul t i pl e FORMAT st at ement s ar e per mi t t ed wi t hi n a pr ogr am, but onl y one per r e por t .
DISPLAY •
The DI SPLAY st at ement i s used t o speci f y t he f i el ds t o be out put on a r epor t i n col umn f ormat . A col umn i s cr eat ed f or each f i el d and a f i el d header i s pl aced over t he col umn.
DISPLAY – FORMATTING PARAMETERS • • • • • • • • • • • • •
AL – Al phanumer i c Lengt h EM – Edi t Mask ES – Empt y Li ne Suppr ess FC – Fi l l er Char act er HC – Header Cent er i ng HW – Header Wi dt h I C – I nser t i on Char act er I S – I dent i cal Suppr ess LC – Leadi ng Char act er LS – Li ne Si ze NL – Numer i c Lengt h PS – Page Si ze SF – Spaci ng Fact or Page 25 of 40
• •
SG – Si gn Posi t i on ZP – Zer o Poi nt
Report Level:
FORMAT PS=50 LS=132 SF=3 Statement Level:
DI SPLAY ( SG=OFF ES=ON) Field Level:
DI SPLAY LAST- NAME ( I S=T) AT TOP OF PAGE
The st at ement AT TOP OF PAGE i s used t o speci f y pr ocessi ng whi ch i s t o be per f or med when a new page i s s t ar t ed. WRITE
The WRI TE st at ement i s used t o pr oduce out put i n f r ee f or mat . The WRI TE st at ement di f f er s f r om t he DI SPLAY st at ement i n t he f ol l owi ng r espect s: •
Li ne over f l ow i s suppor t ed. I f t he l i ne wi dt h i s exceeded f or a l i ne, t he next f i el d ( or t ext ) i s wr i t t en on t he next l i ne. Fi el ds or t ext el ement s ar e not spl i t bet ween l i nes. No def aul t col umn headers are cr eat ed. The l engt h of t he dat a det ermi nes t he number of posi t i ons pr i nt ed f or each f i el d. A r ange of val ues/ occur r ences f or an ar r ay i s out put hor i zont al l y rat her t han ver t i c al l y.
AT BREAK
A speci al AT cl ause al l ows s t at ement s t o be execut ed when a change i n vari abl e val ue occur s. AT END OF DATA
St at ement s wi l l be execut ed once, t he l ast t i me t hr ough a dat a pr ocessi ng l oop. Dat a f r om t he l ast r ecor d i s avai l abl e. Page 26 of 40
SKIP
The SKI P st at ement i s used t o gener at e one or mor e bl ank l i nes i n an out put r e por t . •
•
I f t he execut i on exceeded, exceedi st at ement ) . A SKI P st at ement t he page ( out put her e) .
of a SKI P st at ement woul d cause t he page si ze t o be ng l i nes wi l l be i gnor ed ( except i n an AT TOP OF PAGE i s onl y execut ed i f somet hi ng has al r eady been out put on f r om an AT TOP OF PAGE st at ement i s not t aken i nt o account
NEWPAGE
The NEWPAGE st at ement i s used t o cause an advance t o a new page. NEWPAGE al so causes any AT END OF PAGE and WRI TE TRAI LOR st at ement s t o be execut ed. A def aul t t i t l e cont ai ni ng t he dat e, t i me of day, and page number wi l l appear on each new page unl ess a WRI TE TI TLE, WRI TE NOTI TLE, or DI SPLAY NOTI TLE st at ement i s s pec i f i ed t o def i ne s pec i f i c t i t l e pr oc es s i ng. 1. The advance t o a new page i s not per f or med at t he t i me when t he NEWPAGE st at ement i s execut ed. I t i s per f or med onl y when a subsequent st at ement whi ch pr oduces out put i s execut ed. 2. I f t he NEWPAGE st at ement i s not used, page advance i s cont r ol l ed aut omat i cal l y based on t he Nat ur al pr of i l e/ sessi on par amet er PS.
Page 27 of 40
SEQUENTI AL FI LE PROCESSI NG • • •
Physi cal , sequent i al f i l es may be wr i t t en/ r ead i n a Nat ur al Pr ogr am Pr ogr am must r un i n bat ch. Tot al of 32 f i l es i n a si ngl e Nat ur al Pr ogr am.
RELEVANT STATEMENTS •
READ WORK FILE
•
WRITE WORK FILE
•
CLOSE WORK FILE
•
JCL Considerations
READ WORK FILE • • •
Used t o read r ecor ds i n physi cal sequent i al f i l es i nt o a Nat ur al Pr ogr am. Fi el ds may be gr oup or el ement ar y f i el ds. Br eak Pr ocessi ng and syst em f unct i ons avai l abl e f or wor k f i l e f i el ds.
EXAMPLE
** Exampl e ' RWFEX1' : READ WORK FI LE ************************************************************************ DEFI NE DATA LOCAL 1 EMPLOY- VI EW VI EW OF EMPLOYEES 2 PERSONNEL- I D 2 NAME * 1 #RECORD 2 #PERS- I D ( A8) 2 #NAME ( A20) END- DEFI NE * FI ND EMPLOY- VI EW WI TH CI TY = ' STUTTGART' WRI TE WORK FI LE 1 PERSONNEL- I D NAME END- FI ND * * .. . * READ WORK FILE 1 RECORD #RECORD
DI SPLAY NOTI TLE #PERS- I D #NAME END-WORK
* END
Page 28 of 40
OUTPUT OF PROGRAM RWFEX1:
#PERS- I D #NAME -------- -------------------11100328 BERGHAUS 11100329 BARTHEL 11300313 AECKERLE 11300316 KANTE 11500304 KLUGE 11500308 DI ETRI CH 11500318 GASSNER 11500343 ROEHM 11600303 BERGER 11600320 BLAETTEL 11500336 J ASPER 11100330 BUSH 11500328 EGGERT WRITE WORK FILE
The WRI TE WORK FI LE st at ement i s used t o wr i t e r ecor ds t o a physi cal sequent i al wor k f i l e. Example
** Exampl e ' WWFEX1' : WRI TE WORK FI LE ************************************************************************ DEFI NE DATA LOCAL 1 EMPLOY- VI EW VI EW OF EMPLOYEES 2 PERSONNEL- I D 2 NAME END- DEFI NE * FI ND EMPLOY- VI EW WI TH CI TY = ' LONDON' WRITE WORK FILE 1 PERSONNEL-ID NAME
END- FI ND * END CLOSE WORK FILE
The st at ement CLOSE WORK FI LE i s used t o cl ose a speci f i c wor k f i l e. I t al l ows you t o expl i ci t l y speci f y i n a pr ogr am t hat a wor k f i l e i s t o be cl osed. A wor k f i l e i s cl osed aut omat i cal l y: •
•
When command mode i s r eached. When an end- of - f i l e condi t i on occur s dur i ng t he execut i on of a READ WORK FI LE st at ement .
Page 29 of 40
•
•
Bef or e a DEFI NE WORK FI LE st at ement i s execut ed whi ch ass i gns anot her dat aset t o t he wor k f i l e number concer ned. Accor di ng t o sub- par amet er CLOSE of pr of i l e par amet er WORK.
CLOSE WORK FI LE i s i gnor ed f or wor k f i l es f or whi ch CLOSE=FI N i s speci f i ed i n pr of i l e par amet er WORK.
Example
** Exampl e ' CWFEX1' : CLOSE WORK FI LE ************************************************************************ DEFI NE DATA LOCAL 1 W- DAT ( A20) 1 REC- NUM ( N3) 1 I ( P3) END- DEFI NE REPEAT READ WORK FI LE 1 ONCE W- DAT / * READ MASTER RECORD /* AT END OF FI LE ESCAPE BOTTOM END- ENDFI LE I NPUT ' PROCESSI NG FI LE' W- DAT ( AD=O) / ' ENTER RECORDNUMBER TO DI SPLAY' REC- NUM I F REC- NUM = 0 STOP END- I F FOR I = 1 TO REC- NUM /* READ WORK FI LE 1 ONCE W- DAT /* AT END OF FI LE WRI TE ' RECORD- NUMBER TOO HI GH, LAST RECORD I S' ESCAPE BOTTOM END- ENDFI LE END- FOR I := I - 1 WRI TE ' RECORD' I ' : ' W- DAT /* CLOSE WORK FILE 1
/* END- REPEAT END JCL Considerations
Wor k Fi l es ar e r el at ed t o physi cal f i l es vi a DD st at ement s wi t h DDNAMES CMWKFnn, wher e nn i s t he wor k f i l e number :
Page 30 of 40
Example Code in NATURAL
READ WORK FI LE 2 RECORD #W- WORK- FI LE Corresponding code in the JCL
/ / CMWKF02 DD DI SP=SHR, DSN=xxxxxx
Page 31 of 40
INTERACTIVE PROGRAMMING •
INSTREAM INPUT STATEMENTS
•
THE MAP EDITOR
•
INPUT USING MAP
•
REINPUT
INSTREAM INPUT STATEMENTS
The I NPUT st at ement i s used i n i nt er act i ve mode t o cr eat e a f or mat t ed sc r een. EXAMPLE
** Exampl e ‘ I NPUT STATEMENT’ ************************* DEFI NE DATA LOCAL 1 #NAME ( A30) 1 # AGE ( N2) * I NPUT ‘ ENTER YOUR NAME : ‘ #NAME I NPUT ‘ ENTER YOUR AGE : ‘ #AGE DI SPLAY #NAME #AGE END
THE MAP EDITOR
A map i s a scr een l ayout t hat can be r ef er enced i n a Nat ur al obj ect such as a pr ogr am by usi ng ei t her an I NPUT USI NG MAP st at ement ( f or i nput maps) or a WRI TE USI NG MAP st at ement ( f or out put maps) . Once a map has been cr eat ed, i t can be st or ed as a sour ce obj ect and a cat al oged obj ec t i n a l i br a r y i n a Nat ur a l s ys t e m f i l e.
Page 32 of 40
Once we i ni t i al i ze t he map, t he f ol l owi ng Map set t i ng scr een appear usi ng whi ch set t i ngs of a map can be cust omi zed.
Page 33 of 40
Shown bel ow i s t he map edi t i ng scr een.
Page 34 of 40
INPUT USING MAPS
** Exampl e ' PROG002' : Exampl e pr ogr am f or t he Map Tut or i al ********************************************************************* DEFI NE DATA LOCAL 01 PERS- VI EW VI EW OF EMPLOYEES 02 NAME 02 FI RST- NAME 02 CI TY * 01 #NAME ( A20) 01 #CI TY ( A20) END- DEFI NE * REPEAT /* I NPUT USI NG MAP ' MAP001' /*
Page 35 of 40
REINPUT
The REI NPUT st at ement i s used t o r et ur n t o and r e- execut e an I NPUT st at ement . I t i s gener al l y used to di spl ay a message i ndi cat i ng t hat t he dat a i nput as a r esul t of t he pr evi ous I NPUT st at ement wer e i nval i d.
EXAMPLE
DEFI NE DATA LOCAL 1 #FI RSTNAME ( A20) 1 #AGE ( N2) END- DEFI NE ** I NPUT USI NG MAP ‘ MAP01’ I F FI RSTNAME=’ ‘ REI NPUT ‘ A FI RSTNAME I S REQUI RED’ NAME #FI RSTNAME END- I F I F AGE=’ ‘ OR AGE GE 100 REI NPUT ‘ ENTER A VALI D AGE’ AGE #AGE END- I F END
Page 36 of 40
SYSTEM CONSTRUCTS •
MAIN PROGRAMS ( FETCH / FETCH RETURN)
•
SUB PROGRAMS (CALLNAT)
•
SUBROUTINES (PERFORM)
•
COPYCODE (INCLUDE)
•
GLOBAL DATA AREA
•
PARAMETER DATA AREA
•
LOCAL DATA AREA
•
AIVs
MAIN PROGRAMS
The FETCH st at ement i s used t o execut e a Nat ur al obj ect pr ogr am wr i t t en as a mai n pr ogr am. The pr ogr am t o be l oaded must have been pr evi ousl y st or ed i n t he Nat ur al sys t em f i l e wi t h a CATALOG or STOW command. Execut i on of t he FETCH st at ement does not over wr i t e any sour ce pr ogr am i n t he Nat ur al sour ce wor k ar ea.
SUB PROGRAMS
The CALLNAT st at ement i s used t o i nvoke a Nat ur al subpr ogr am f or execut i on. ( A Nat ur al subpr ogr am can onl y be i nvoked vi a a CALLNAT st at ement ; i t cannot be execut ed by i t sel f . ) When t he CALLNAT st at ement i s execut ed, t he execut i on of t he i nvoki ng obj ect ( t hat i s, t he obj ect cont ai ni ng t he CALLNAT st at ement ) wi l l be suspended and t he i nvoked subpr ogr am wi l l be execut ed. The execut i on of t he subpr ogr am cont i nues unt i l ei t her i t s END st at ement i s r eached or pr ocessi ng of t he subpr ogr am i s st opped by an ESCAPE ROUTI NE st at ement bei ng execut ed. I n ei t her case, pr ocess i ng of t he i nvoki ng obj ect wi l l t hen cont i nue wi t h t he st at ement f ol l owi ng t he CALLNAT st at ement . A subpr ogr am can i n t urn i nvoke ot her subprogr ams. A subpr ogr am has no access t o t he gl obal dat a ar ea used by t he i nvoki ng obj ect . I f a subpr ogr am i n t ur n i nvokes a subr out i ne or hel pr out i ne, i t can est abl i sh i t s own gl obal dat a area t o be shar ed wi t h t he subr out i ne/ hel pr out i ne.
Page 37 of 40
SUBROUTINES
Subr out i ne may be I nt ernal or Ext er nal . A subr out i ne may be def i ned wi t hi n t he obj ect whi ch cont ai ns t he PERFORM st at ement t hat i nvokes t he subr out i ne ( i nl i ne s ubr out i ne) ; or i t may be def i ned ext er nal t o t he obj ect t hat cont ai ns t he PERFORM st at ement ( exter nal subr out i ne) . An i nl i ne subr out i ne may be def i ned bef or e or af t er t he f i r st PERFORM st at ement whi ch r e f er e nc es i t . Any pr ocessi ng l oop i ni t i at ed wi t hi n a subr out i ne must be cl osed bef ore ENDSUBROUTI NE i s i ss ued. An i nl i ne subr out i ne must not cont ai n anot her DEFI NE SUBROUTI NE st at ement An exter nal subr out i ne ( t hat i s, an obj ect of t ype subr out i ne) must not cont ai n mor e t han one DEFI NE SUBROUTI NE st at ement bl ock. However , an ext er nal DEFI NE SUBROUTI NE bl ock may cont ai n f ur t her i nl i ne subr out i nes. COPYCODE
Copycode i s a por t i on of sour ce code whi ch can be i ncl uded i n anot her obj ect vi a an I NCLUDE st at ement . So, i f you have a st at ement bl ock whi ch i s t o appear i n i dent i cal f or m i n sever al obj ect s, you may use copycode i nst ead of codi ng t he st at ement bl ock sever al t i mes. Thi s r educes t he codi ng ef f or t and al so ensur es t hat t he bl ocks ar e r eal l y i dent i cal . The copycode i s i ncl uded at compi l at i on; t hat i s, t he sour ce- code l i nes f r om t he copycode ar e not physi cal l y i nsert ed i nt o t he obj ect t hat cont ai ns t he I NCLUDE st at ement , but t hey wi l l be i ncl uded i n t he compi l at i on pr ocess and ar e t hus par t of t he r esul t i ng obj ect modul e. Copycode cannot be execut ed on i t s own. I t cannot be st owed, but onl y saved. An END st at ement must not be pl aced wi t hi n a copycode.
DATA AREAS
The f i el ds can be def i ned wi t hi n t he DEFI NE DATA st at ement i t sel f ; or t hey can be def i ned out si de t he pr ogr am i n a separ at e dat a ar ea, wi t h t he DEFI NE DATA st at ement r ef er enci ng t hat dat a ar ea. A separ at e dat a ar ea i s a Nat ur al obj ect t hat can be used by mul t i pl e Nat ur al pr ogr ams, subpr ogr ams, subr out i nes, hel pr out i nes or cl asses. A dat a ar ea cont ai ns dat a el ement def i ni t i ons, such as user- def i ned var i abl es, const ant s and dat abase f i el ds f r om a dat a def i ni t i on modul e ( DDM) . Al l dat a ar eas ar e cr eat ed and edi t ed wi t h t he dat a ar ea edi t or.
Page 38 of 40
Nat ur al support s t hr ee t ypes of dat a ar ea: •
Local Data Area
•
Global Data Area
•
Parameter Data Area
LOCAL DATA AREA
Var i abl es def i ned as l ocal ar e used onl y wi t hi n a si ngl e Nat ur al pr ogr ammi ng obj ect . Ther e ar e two opt i ons f or def i ni ng l ocal dat a: •
•
You can def i ne l ocal dat a wi t hi n a pr ogr am. You can def i ne l ocal dat a out si de a pr ogr am i n a separ at e Nat ur al pr ogr ammi ng obj ect .
A l ocal dat a ar ea i s i ni t i al i zed when a pr ogr am, subpr ogr am or ext er nal subr out i ne t hat uses t hi s l ocal dat a ar ea st ar t s t o execut e.
GLOBAL DATA AREA
GDAs ar e creat ed and modi f i ed wi t h t he Nat ur al dat a ar ea edi t or . A GDA t hat i s r ef er enced by a Nat ur al pr ogr ammi ng obj ect must be st or ed i n t he same Nat ur al l i br ary wher e t he obj ect t hat r ef erences t hi s GDA i s st ored. I f a GDA named COMMON exi st s i n a l i br ar y, t he pr ogr am named ACOMMON i s i nvoked aut omat i cal l y when you LOGON t o t hat l i br ar y.
PARAMETER DATA AREA
A subpr ogr am i s i nvoked wi t h a CALLNAT s t at ement . Wi t h t he CALLNAT st at ement , par amet ers can be passed f r om t he i nvoki ng obj ect t o t he subpr ogr am. These par amet er s must be def i ned wi t h a DEFI NE DATA PARAMETER st at ement i n t he subpr ogr am: They can be def i ned i n t he PARAMETER cl ause of t hehttp://documentation.softwareag.com/natural/nat424mf/sm/defineda.htm DEFI NE DATA st at ement i t s el f ; or They can be def i ned i n a separ at e par amet er dat a ar ea, wi t h t he DEFI NE DATA PARAMETER st at ement r ef er enci ng t hat PDA.
Page 39 of 40