Вы находитесь на странице: 1из 40

NATURAL Programming

Version 1.1

February 19, 2009

Banking & Financial Services


shobana.patchai@tcs.com

Page 1 of 40

DOCUMENT RELEASE NOTICE

Version Draft

Author Shobana Patchai

Date 19/02/2009

Changes Done Initial Draft

Page 2 of 40

DOCUMENT RELEASE NOTICE TABLE OF CONTENTS INTRODUCTION-----------------------------------------------------------4 NATURAL OVERVIEW-------------------------------------------------------5 NATURAL COMMANDS-------------------------------------------------------7
OVERVIEW-----------------------------------------------------------------------7 CHANGING LIBRARIES------------------------------------------------------7 PROGRAM EDITOR----------------------------------------------------------7 EDITOR COMMANDS---------------------------------------------------------8 LINE COMMANDS-----------------------------------------------------------9 CLONING A NATURL PROGRAM------------------------------------------------9

NATURAL LANGUAGE AN OVERVIEW ON CORE CONCEPTS-----------------------10


PROGRAMMING MODES-------------------------------------------------------10 VIEW DEFINITION---------------------------------------------------------13

GROUP VARIABLES--------------------------------------------------14
SYSTEM VARIABLES--------------------------------------------------------15

DATABASE ACCESS------------------------------------------------------- 15 DATABASE MAINTENANCE-------------------------------------------------- 17 LOOP EXECUTUING STATEMENTS---------------------------------------------20 PROGRAM AND SESSION TERMINATION----------------------------------------22 NATURAL REPORT FUNCTIONS-----------------------------------------------23 SEQUENTIAL FILE PROCESSING---------------------------------------------26
READ WORKFILE------------------------------------------------------------26 WRITE WORKFILE-----------------------------------------------------------27 CLOSE WORKFILE-----------------------------------------------------------27 JCL CONSIDERATIONS-------------------------------------------------------28

INTERACTIVE PROGRAMMING------------------------------------------------29 SYSTEM CONSTRUCTS------------------------------------------------------34

Page 3 of 40

INTRODUCTION
ABOUT THIS MANUAL
This manual is intended as a training document, especially for beginners NATURAL, which will pave the way for learning advanced Natural Concepts. in

This is an evolving and live document. There will be updates to this during the course of the support, if necessary.

Page 4 of 40

NATURAL OVERVIEW
Procedural / Non- Procedural Free Format Online / Batch ADABAS/ Sequential/ DB2 Structured / Reporting

TYPES OF PROGRAMMING OBJECTS


Within a Natural application, several types of objects can be used to achieve an efficient application structure. There are the different types of Natural objects:

Program Class SubProgram SubRoutine Copycode HelpRoutine Text Maps Local Data Area Global Data Area Parameter Data Area

Page 5 of 40

The Natural Main Menu looks similar to the example shown below:

Page 6 of 40

NATURAL COMMANDS

OVERVIEW CHANGING LIBRARIES PROGRAM EDITOR EDITOR COMMANDS LINE COMMANDS CLONING A NATURL PROGRAM

OVERVIEW

Natural Commands are used to maintain program objects. When programs are saved, a copy is placed in an ADABAS file (FUSER)

CHANGING LIBRARIES
Change Libraries by entering the LOGON command All sources are uniquely identified by the program name / library name combination.

Page 7 of 40

PROGRAM EDITOR

The program Editor screen contains the following items (From top to bottom):

Editor Command Line Top Information Line Editing Area Bottom Information Line

EDITOR COMMANDS CLEAR


-

Erases the contents of the Program. No effects on the contents of FUSER.

READ
-

Reads the specified source from FUSER file and places in the Edit Work Area. Current contents of Edit Work Area are overlaid. Page 8 of 40

CHECK
-

Errors pointed out one at a time. Does not save source. Issue CHECK command often. Sometimes the editor points to the line which contains the error.

RUN
- Performs a syntax check and, if no errors will execute the program - Does not save source. - Run often to test the program as u built it.

STOW
- Performs a syntax check of the source in the editor work area. - If no errors, saves the source and object I n FUSER. - If an error is found, the error is pointed out and the STOW process is terminated. - STOW often to ensure the source and the object match.

EXECUTE
- Executes the OBJECT module from FUSER. - Executing is faster than Running.

FIN
- Terminates the NATURAL Session.

SCAN
- This command scans the source code for a character string (scanvalue). - If the supplied scan-value is entered without delimiter characters, for example, SCAN ABC D, the entire character string which follows the keyword SCAN is used as the scan value. - If you enter SCAN without any parameter, the SCAN/REPLACE window is invoked, where we can replace with some other values.

Page 9 of 40

LINE COMMANDS

.C (nnn) .CX Y markers. .D (nnn) .MX-Y .P

- Copies the line in which the command was entered. - Copies the block of lines delimited by the X and Y

- Deletes line or lines. The default is 1 line. - Moves the block of lines delimited by the X and Y markers. - Positions the line marked with this command to the top of the Screen. - Splits the line at the position marked with the cursor.

.S

CLONING A NATURL PROGRAM

Edit the program to be copied. SAVE the source specifying the new name. READ the new name.

Page 10 of 40

NATURAL LANGUAGE AN OVERVIEW ON CORE CONCEPTS

Programming Modes View Definition Group Fields, Redefinitions, Initial Values System Variables

PROGRAMMING MODES
Natural offers two ways of programming: Reporting Mode Structured Mode

Generally, it is recommended to use structured mode exclusively, because it provides for more clearly structured applications.

REPORTING MODE
Reporting mode is only useful for the creation of adhoc reports and small programs which do not involve complex data and/or programming constructs. (If you decide to write a program in reporting mode, be aware that small programs may easily become larger and more complex.)

STRUCTURED MODE
Structured mode is intended for the implementation of complex applications with a clear and well-defined program structure. The major benefits of structured mode are: The programs have to be written in a more structured way and are therefore easier to read and consequently easier to maintain. As all fields to be used in a program have to be defined in one central location (instead of being scattered all over the program, as is possible in reporting mode), overall control of the data used is much easier.

Page 11 of 40

With structured mode, you also have to make more detail planning before the actual programs can be coded, thereby avoiding many programming errors and inefficiencies.

SETTING OR CHANGING THE PROGRAMMING MODE

To switch to Structured Mode : To switch to Reporting Mode :

GLOBALS SM=ON GLOBALS SM=OFF

REPORTING MODE EXAMPLE


The reporting mode example uses the statements DO and DOEND to mark the beginning and end of the statement block that is based on the AT END OF DATA condition. The END statement closes all active processing loops. READ EMPLOYEES BY PERSONNEL-ID DISPLAY NAME BIRTH AT END OF DATA DO SKIP 2 WRITE / 'LAST SELECTED:' OLD(NAME) DOEND END

STRUCTURED MODE EXAMPLE


The structured mode example uses an END-ENDDATA statement to close the AT END OF DATA condition, and an END-READ statement to close the READ loop. The result is a more clearly structured program in which you can see immediately where each construct begins and ends: DEFINE DATA LOCAL 1 MYVIEW VIEW OF EMPLOYEES 2 PERSONNEL-ID 2 NAME 2 BIRTH END-DEFINE READ MYVIEW BY PERSONNEL-ID DISPLAY NAME BIRTH AT END OF DATA SKIP 2 WRITE / 'LAST SELECTED:' OLD(NAME) END-ENDDATA END-READ END

Page 12 of 40

DATABASE REFERENCE

REPORTING MODE
In reporting mode, database fields and DDMs may be referenced without having been defined in data area.

STRUCTURED MODE
In structured mode, each database field to be used must be specified in a DEFINE STATEMENT statement as described in Defining Fields and Accessing Data in a data base.

Page 13 of 40

VIEW DEFINITION

We must declare all ADABAS files and Fields in the DEFINE DATA statement. The View Name may be upto 32 characters. Views are always defined at Level 1 and the fields the view is comprised of must be on Level 2. Formats and Lengths need not be specified NATURAL obtains from DDM.

EXAMPLE OF VIEW DEFINITION


DEFINE DATA LOCAL 1 VIEWEMP VIEW OF EMPLOYEES 2 NAME 2 FIRST-NAME 2 BIRTH ... END-DEFINE

Page 14 of 40

USER FIELDS

We may also declare non database fields that you wish to use in your program assigned with Level-Number, Name, Format and Length.

Example:

#NAME

(A30)

User defined variables should begin with #. Declared in the DEFINE DATA statement.

VARIABLE FORMATS AND LENGTHS Alphanumeric Numeric Packed Numbers Logical Variables - max 253 - max 29 digits (7 decimal) - max 29 digits (7 decimal) - TRUE or FALSE

GROUP FIELDS, VARIABLE REDEFINITIONS AND INITIAL VALUES If you redefine a field, the REDEFINE option must be on the same level as the original field, and the fields resulting from the redefinition must be one level lower. For details on redefinitions, see Redefining Fields.

DEFINE DATA LOCAL 1 VIEWEMP VIEW OF STAFFDDM 2 BIRTH 2 REDEFINE BIRTH 3 #YEAR-OF-BIRTH (N4) 3 #MONTH-OF-BIRTH (N2) 3 #DAY-OF-BIRTH (N2) 1 #FIELDA (A20) 1 REDEFINE #FIELDA 2 #SUBFIELD1 (N5) 2 #SUBFIELD2 (A10) 2 #SUBFIELD3 (N5) ... END-DEFINE Page 15 of 40

Level numbers must be consecutive and may not exceed 9. Initial Values are specified using the INIT Keyword as follows : Example 1 #NAME (A30) INIT <RAM>

If no initial value is specified, all variables are initialized to appropriate null values.

SYSTEM VARIABLES Some of the commonly used System variables are listed below: *DATN Current date is YYYYMMDD Format. *NUMBER *COUNTER *ISN *PROGRAM *DATU *TIME Number of records selected with a FIND. Number of iterations through a data loop. Internal Sequence Number of an ADABAS record. Currently Executing Program Current date in MM/D/YY Format. Current time in HH:MM:SS:T Format

System variables can be used in INIT clauses:

Example

#NAME

(A30)

INIT <*DATU>

STATEMENTS GROUPED BY FUNCTIONS DATABASE ACCESS FIND READ HISTOGRAM GET GET SAME ACCEPT / REJECT LIMIT Page 16 of 40

FIND

- Selects a set of records from an ADABAS File based on user-specified criteria

READ

- Reads a database file in physical or logical sequence of records.

HISTOGRAM

- Reads the values of the database Fields. - Sequential Process similar to READ LOGICAL. - Very useful for Code validation, Summary Reports. - Very Efficient.

GET

- Reads a record with a given ISN(Internal Sequence Number) or RNO (Record Number)

GETSAME

- Re-reads the record currently being processed.

ACCEPT / REJECT

- Accepts or rejects the records based on the User-Specified criteria.

LIMIT

- Limits the number of executions of a READ, FIND or HISTOGRAM Processing Loop.

Page 17 of 40

DATABASE MAINTENANCE

RECORD HOLDING END TRANSACTION UPDATE STORE DELETE

RECORD HOLDING Records must be HELD before they can be updated. Records automatically held if an UPDATE or DELETE references the access statement. Purpose is to ensure that two programs are not permitted to update the same record at the same time. Records held can be read by other programs but not for update/delete.

END TRANSACTION The END TRANSACTION statement is used to indicate the end of a logical transaction. A logical transaction is the smallest logical unit of work (as defined by the user) which must be performed in its entirety to ensure that the information contained in the database is logically consistent. 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 regardless of subsequent user, Natural, database or operating system interruption. Updates performed within a transaction for which the END TRANSACTION statement has not been successfully completed will be backed out automatically. The END TRANSACTION statement also results in the release of all records placed in hold status during the transaction. The END TRANSACTION statement can be executed based upon a logical condition.

Page 18 of 40

UPDATE Used to change the contents of one or more fields in an Existing ADABAS Record. Must first read record before updating it. Any field can be updated.

RESTRICTIONS The UPDATE statement must not be entered on the same line as the statement used to select the record to be updated. The UPDATE statement cannot be applied to Entire System Server views.

EXAMPLE ** Example 'UPDEX1S': UPDATE (structured mode) ** ** CAUTION: Executing this example will modify the database records! ************************************************************************ DEFINE DATA LOCAL 1 EMPLOY-VIEW VIEW OF EMPLOYEES 2 NAME 2 FIRST-NAME 2 CITY * 1 #NAME (A20) END-DEFINE * INPUT 'ENTER A NAME:' #NAME (AD=M) IF #NAME = ' ' STOP END-IF * 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 *

Page 19 of 40

STORE Adds a new record to the ADABAS file and places the record in a hold status.

The Natural system variable *ISN contains the Adabas ISN assigned to the new record as a result of the STORE statement execution. A subsequent reference to *ISN must include the statement number of the related STORE statement. DELETE The DELETE statement is used to delete a record from a database.

A DELETE statement cannot be specified in the same statement line as FIND, READ or GET statement.

EXAMPLE ** Example 'DELEX1': DELETE **CAUTION: Executing this example will modify the database records! ************************************************************************ DEFINE DATA LOCAL 1 EMPLOY-VIEW VIEW OF EMPLOYEES 2 NAME END-DEFINE * FIND EMPLOY-VIEW WITH NAME = 'ALDEN' /* DELETE END TRANSACTION /* AT END OF DATA WRITE NOTITLE *NUMBER 'RECORDS DELETED' END-ENDDATA END-FIND

Page 20 of 40

LOOP EXECUTION STATEMENTS

REPEAT FOR ESCAPE SORT

REPEAT Sets a user-defines program loop Code an ESCAPE BOTTOM to avoid an endless loop.

Example

REPEAT IF condition ESCAPE BOTTOM END-IF .. .. END-REPEAT

An UNTIL or WHILE condition may be specified at the bottom of the loop FOR

The FOR statement is used to initiate a processing loop and to control the number of times the loop is processed.

CONSISTENCY CHECK Before the FOR loop is entered, the values of the operands are checked to ensure that they are consistent.

Page 21 of 40

EXAMPLE ** Example 'FOREX1S': FOR (structured mode) ************************************************************************ DEFINE DATA LOCAL 1 #INDEX (I1) 1 #ROOT (N2.7) END-DEFINE * FOR #INDEX 1 TO 5 COMPUTE #ROOT = SQRT (#INDEX) WRITE NOTITLE '=' #INDEX 3X '=' #ROOT END-FOR * SKIP 1 FOR #INDEX 1 TO 5 STEP 2 COMPUTE #ROOT = SQRT (#INDEX) WRITE '=' #INDEX 3X '=' #ROOT END-FOR * END

OUTPUT OF PROGRAM FOREX1S: #INDEX: #INDEX: #INDEX: #INDEX: #INDEX: #INDEX: #INDEX: #INDEX: 1 2 3 4 5 1 3 5 #ROOT: #ROOT: #ROOT: #ROOT: #ROOT: #ROOT: #ROOT: #ROOT: 1.0000000 1.4142135 1.7320508 2.0000000 2.2360679 1.0000000 1.7320508 2.2360679

ESCAPE The ESCAPE statement is used to interrupt the linear flow of execution of a processing loop or a routine. With the keywords TOP, BOTTOM and ROUTINE you indicate where processing is to continue when the ESCAPE statement is encountered. An ESCAPE TOP/BOTTOM statement, when encountered for processing, will internally refer to the innermost active processing loop. The ESCAPE statement need not be physically placed within the processing loop. If an ESCAPE TOP/BOTTOM statement is placed in a routine (subroutine, subprogram, or program invoked with FETCH RETURN, the routine(s) entered during execution of the processing loop will be terminated automatically.

Page 22 of 40

SORT The SORT statement is used to perform a sort operation, sorting the records from all processing loops that are active when the SORT statement is executed. For the sort operation, Natural's internal sort program is used. It is also possible to use another, external sort program. RESTRICTIONS The SORT statement must be contained in the same object as the processing loops whose records it sorts. Nested SORT statements are not allowed. The total length of a record to be sorted must not exceed 10240 bytes. The number of sort criteria must not exceed 10.

Page 23 of 40

PROGRAM AND SESSION TERMINATION

STOP TERMINATE

STOP The STOP statement is used to terminate the execution of a program and return to the command input prompt. One or more STOP statements may be inserted anywhere within a Natural program. The STOP statement will terminate the execution of the program immediately. Independent of the positioning of a STOP statement in a subroutine, any end-page condition specified in the main program will be invoked for final end-page processing during execution of the STOP statement.

TERMINATE The TERMINATE statement is used to terminate a Natural session. A TERMINATE statement may be placed anywhere within a Natural program. When a TERMINATE statement is executed, no end-of-page or end-loop processing will be performed. The behavior of the TERMINATE statement matches that of the STOP statement. Processing of return values is not supported.

Page 24 of 40

NATURAL REPORT FUNCTIONS


Batch Reports are an integral part of any application. Natural provides a number of built-in functions which significantly reduce programming effort. Some of the commonly used Report functions of NATURAL are: FORMAT DISPLAY AT TOP OF PAGE WRITE AT BREAK AT END OF DATA SKIP NEWPAGE

FORMAT The FORMAT statement is used to specify input and output parameter settings. Multiple FORMAT statements are permitted within a program, but only one per report.

DISPLAY The DISPLAY statement is used to specify the fields to be output on a report in column format. A column is created for each field and a field header is placed over the column.

DISPLAY FORMATTING PARAMETERS AL EM ES FC HC HW IC IS LC LS NL PS SF Alphanumeric Length Edit Mask Empty Line Suppress Filler Character Header Centering Header Width Insertion Character Identical Suppress Leading Character Line Size Numeric Length Page Size Spacing Factor Page 25 of 40

SG Sign Position ZP Zero Point

Report Level: FORMAT PS=50 LS=132 SF=3 Statement Level: DISPLAY (SG=OFF ES=ON) Field Level: DISPLAY LAST-NAME (IS=T) AT TOP OF PAGE The statement AT TOP OF PAGE is used to specify processing which is to be performed when a new page is started. WRITE

The WRITE statement is used to produce output in free format.


The WRITE statement differs from the DISPLAY statement in the following respects: Line overflow is supported. If the line width is exceeded for a line, the next field (or text) is written on the next line. Fields or text elements are not split between lines. No default column headers are created. The length of the data determines the number of positions printed for each field. A range of values/occurrences for an array is output horizontally rather than vertically. AT BREAK A special AT clause allows statements to be executed when a change in variable value occurs. AT END OF DATA Statements will be executed once, the last time through a data processing loop. Data from the last record is available. Page 26 of 40

SKIP The SKIP statement is used to generate one or more blank lines in an output report. If the execution of a SKIP statement would cause the page size to be exceeded, exceeding lines will be ignored (except in an AT TOP OF PAGE statement). A SKIP statement is only executed if something has already been output on the page (output from an AT TOP OF PAGE statement is not taken into account here).

NEWPAGE The NEWPAGE statement is used to cause an advance to a new page. NEWPAGE also causes any AT END OF PAGE and WRITE TRAILOR statements to be executed. A default title containing the date, time of day, and page number will appear on each new page unless a WRITE TITLE, WRITE NOTITLE, or DISPLAY NOTITLE statement is specified to define specific title processing. 1. The advance to a new page is not performed at the time when the NEWPAGE statement is executed. It is performed only when a subsequent statement which produces output is executed. 2. If the NEWPAGE statement is not used, page advance is controlled automatically based on the Natural profile/session parameter PS.

Page 27 of 40

SEQUENTIAL FILE PROCESSING Physical, sequential files may be written/ read in a Natural Program Program must run in batch. Total of 32 files in a single Natural Program.

RELEVANT STATEMENTS READ WORK FILE WRITE WORK FILE CLOSE WORK FILE JCL Considerations

READ WORK FILE Used to read records in physical sequential files into a Natural Program. Fields may be group or elementary fields. Break Processing and system functions available for work file fields.

EXAMPLE ** Example 'RWFEX1': READ WORK FILE ************************************************************************ DEFINE DATA LOCAL 1 EMPLOY-VIEW VIEW OF EMPLOYEES 2 PERSONNEL-ID 2 NAME * 1 #RECORD 2 #PERS-ID (A8) 2 #NAME (A20) END-DEFINE * FIND EMPLOY-VIEW WITH CITY = 'STUTTGART' WRITE WORK FILE 1 PERSONNEL-ID NAME END-FIND * * ... * READ WORK FILE 1 RECORD #RECORD DISPLAY NOTITLE #PERS-ID #NAME END-WORK * END

Page 28 of 40

OUTPUT OF PROGRAM RWFEX1:

#PERS-ID #NAME -------- -------------------11100328 11100329 11300313 11300316 11500304 11500308 11500318 11500343 11600303 11600320 11500336 11100330 11500328 BERGHAUS BARTHEL AECKERLE KANTE KLUGE DIETRICH GASSNER ROEHM BERGER BLAETTEL JASPER BUSH EGGERT

WRITE WORK FILE The WRITE WORK FILE statement is used to write records to a physical sequential work file. Example ** Example 'WWFEX1': WRITE WORK FILE ************************************************************************ DEFINE DATA LOCAL 1 EMPLOY-VIEW VIEW OF EMPLOYEES 2 PERSONNEL-ID 2 NAME END-DEFINE * FIND EMPLOY-VIEW WITH CITY = 'LONDON' WRITE WORK FILE 1 PERSONNEL-ID NAME END-FIND * END CLOSE WORK FILE The statement CLOSE WORK FILE is used to close a specific work file. It allows you to explicitly specify in a program that a work file is to be closed. A work file is closed automatically: When command mode is reached. When an end-of-file condition occurs during the execution of a READ WORK FILE statement.

Page 29 of 40

Before a DEFINE WORK FILE statement is executed which assigns another dataset to the work file number concerned. According to sub-parameter CLOSE of profile parameter WORK.

CLOSE WORK FILE is ignored for work files for which CLOSE=FIN is specified in profile parameter WORK.

Example ** Example 'CWFEX1': CLOSE WORK FILE ************************************************************************ DEFINE DATA LOCAL 1 W-DAT (A20) 1 REC-NUM (N3) 1 I (P3) END-DEFINE REPEAT READ WORK FILE 1 ONCE W-DAT /* READ MASTER RECORD /* AT END OF FILE ESCAPE BOTTOM END-ENDFILE INPUT 'PROCESSING FILE' W-DAT (AD=O) / 'ENTER RECORDNUMBER TO DISPLAY' REC-NUM IF REC-NUM = 0 STOP END-IF FOR I = 1 TO REC-NUM /* READ WORK FILE 1 ONCE W-DAT /* AT END OF FILE WRITE 'RECORD-NUMBER TOO HIGH, LAST RECORD IS' ESCAPE BOTTOM END-ENDFILE END-FOR I := I - 1 WRITE 'RECORD' I ':' W-DAT /* CLOSE WORK FILE 1 /* END-REPEAT END JCL Considerations Work Files are related to physical files via DD statements with DDNAMES CMWKFnn, where nn is the work file number:

Page 30 of 40

Example Code in NATURAL READ WORK FILE 2 RECORD #W-WORK-FILE Corresponding code in the JCL //CMWKF02 DD DISP=SHR,DSN=xxxxxx

Page 31 of 40

INTERACTIVE PROGRAMMING
INSTREAM INPUT STATEMENTS THE MAP EDITOR INPUT USING MAP REINPUT

INSTREAM INPUT STATEMENTS The INPUT statement is used in interactive mode to create a formatted screen. EXAMPLE ** Example INPUT STATEMENT ************************* DEFINE DATA LOCAL 1 #NAME (A30) 1 # AGE (N2) * INPUT ENTER YOUR NAME : #NAME INPUT ENTER YOUR AGE : #AGE DISPLAY #NAME #AGE END

THE MAP EDITOR A map is a screen layout that can be referenced in a Natural object such as a program by using either an INPUT USING MAP statement (for input maps) or a WRITE USING MAP statement (for output maps). Once a map has been created, it can be stored as a source object and a cataloged object in a library in a Natural system file.

Page 32 of 40

Once we initialize the map, the following Map setting screen appear using which settings of a map can be customized.

Page 33 of 40

Shown below is the map editing screen.

Page 34 of 40

INPUT USING MAPS ** Example 'PROG002': Example program for the Map Tutorial ********************************************************************* DEFINE DATA LOCAL 01 PERS-VIEW VIEW OF EMPLOYEES 02 NAME 02 FIRST-NAME 02 CITY * 01 #NAME (A20) 01 #CITY (A20) END-DEFINE * REPEAT /* INPUT USING MAP 'MAP001' /*

Page 35 of 40

REINPUT The REINPUT statement is used to return to and re-execute an INPUT statement. It is generally used to display a message indicating that the data input as a result of the previous INPUT statement were invalid.

EXAMPLE DEFINE DATA LOCAL 1 #FIRSTNAME (A20) 1 #AGE (N2) END-DEFINE ** INPUT USING MAP MAP01 IF FIRSTNAME= REINPUT A FIRSTNAME IS REQUIRED NAME #FIRSTNAME END-IF IF AGE= OR AGE GE 100 REINPUT ENTER A VALID AGE AGE #AGE END-IF 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 statement is used to execute a Natural object program written as a main program. The program to be loaded must have been previously stored in the Natural system file with a CATALOG or STOW command. Execution of the FETCH statement does not overwrite any source program in the Natural source work area.

SUB PROGRAMS The CALLNAT statement is used to invoke a Natural subprogram for execution. (A Natural subprogram can only be invoked via a CALLNAT statement; it cannot be executed by itself.) When the CALLNAT statement is executed, the execution of the invoking object (that is, the object containing the CALLNAT statement) will be suspended and the invoked subprogram will be executed. The execution of the subprogram continues until either its END statement is reached or processing of the subprogram is stopped by an ESCAPE ROUTINE statement being executed. In either case, processing of the invoking object will then continue with the statement following the CALLNAT statement. A subprogram can in turn invoke other subprograms. A subprogram has no access to the global data area used by the invoking object. If a subprogram in turn invokes a subroutine or helproutine, it can establish its own global data area to be shared with the subroutine/helproutine.

Page 37 of 40

SUBROUTINES Subroutine may be Internal or External. A subroutine may be defined within the object which contains the PERFORM statement that invokes the subroutine (inline subroutine); or it may be defined external to the object that contains the PERFORM statement (external subroutine). An inline subroutine may be defined before or after the first PERFORM statement which references it. Any processing loop initiated within a subroutine must be closed before ENDSUBROUTINE is issued. An inline subroutine must not contain another DEFINE SUBROUTINE statement An external subroutine (that is, an object of type subroutine) must not contain more than one DEFINE SUBROUTINE statement block. However, an external DEFINE SUBROUTINE block may contain further inline subroutines. COPYCODE Copycode is a portion of source code which can be included in another object via an INCLUDE statement. So, if you have a statement block which is to appear in identical form in several objects, you may use copycode instead of coding the statement block several times. This reduces the coding effort and also ensures that the blocks are really identical. The copycode is included at compilation; that is, the source-code lines from the copycode are not physically inserted into the object that contains the INCLUDE statement, but they will be included in the compilation process and are thus part of the resulting object module. Copycode cannot be executed on its own. It cannot be stowed, but only saved. An END statement must not be placed within a copycode.

DATA AREAS The fields can be defined within the DEFINE DATA statement itself; or they can be defined outside the program in a separate data area, with the DEFINE DATA statement referencing that data area. A separate data area is a Natural object that can be used by multiple Natural programs, subprograms, subroutines, helproutines or classes. A data area contains data element definitions, such as user-defined variables, constants and database fields from a data definition module (DDM). All data areas are created and edited with the data area editor.

Page 38 of 40

Natural supports three types of data area: Local Data Area Global Data Area Parameter Data Area

LOCAL DATA AREA Variables defined as local are used only within a single Natural programming object. There are two options for defining local data: You can define local data within a program. You can define local data outside a program in a separate Natural programming object.

A local data area is initialized when a program, subprogram or external subroutine that uses this local data area starts to execute.

GLOBAL DATA AREA GDAs are created and modified with the Natural data area editor. A GDA that is referenced by a Natural programming object must be stored in the same Natural library where the object that references this GDA is stored. If a GDA named COMMON exists in a library, the program named ACOMMON is invoked automatically when you LOGON to that library.

PARAMETER DATA AREA A subprogram is invoked with a CALLNAT statement. With the CALLNAT statement, parameters can be passed from the invoking object to the subprogram. These parameters must be defined with a DEFINE DATA PARAMETER statement in the subprogram: They can be defined in the PARAMETER clause of thehttp://documentation.softwareag.com/natural/nat424mf/sm/defineda.htm DEFINE DATA statement itself; or They can be defined in a separate parameter data area, with the DEFINE DATA PARAMETER statement referencing that PDA.

Page 39 of 40

AIV

This command is used to display all application-independent variables (AIVs) which are currently active. On the list displayed, you can mark an AIV with the command DI to display the content of the AIV.

Page 40 of 40

Вам также может понравиться