You are on page 1of 49

Mainframe & Natural Training Documentation

Mainframe & Natural Training Documentation


Version 1.5 6 August, 1999 Document Written and Compiled By Jane Candlin Nicola Danson Tristan Gaffney Daniel Hapgood

Mainframe & Natural Documentation.doc

Page 1 / 49e

Mainframe & Natural Training Documentation

Contents
Reporting Structured ................................................................................9 DEFINE DATA...........................................................................................................................10 END-DEFINE..............................................................................................................................10 END.............................................................................................................................................10 Define Data..........................................................................................................................................10 Global...................................................................................................................................................10 In this section you define data and variables that is to be accessible to all parts of your program and its objects..............................................................................................................................................10 Parameter.............................................................................................................................................10 Local.....................................................................................................................................................10 DEFINE DATA ..........................................................................................................................10 Example...................................................................................................................................................11 British Steel Standards.........................................................................................................................12 Multi-dimensional arrays.............................................................................................13 Two Dimensional Array Example...............................................................................13 Date..........................................................................................................................................................28 Variable....................................................................................................................................................28 Explanation..............................................................................................................................................28 Timestamp................................................................................................................................................29 Format......................................................................................................................................................29 Example...................................................................................................................................................29 MOVE EDITED .................................................................................................................................29 Example 1................................................................................................................................................30 Example 2................................................................................................................................................30 British Steel Standards.........................................................................................................................32 Good.........................................................................................................................................................36 Bad...........................................................................................................................................................36 Delimiters ................................................................................................................................................42 Layout .....................................................................................................................................................43 Program syntax ......................................................................................................................................44 PF keys in the map editor ........................................................................................................................44 Incorporating data ...................................................................................................................................44 Field commands ......................................................................................................45 Extended Field Editing.............................................................................................................................45 Stowing and Saving.................................................................................................................................46 Attaching to a program............................................................................................................................46 REMEMBER...........................................................................................................................................47

Mainframe & Natural Documentation.doc

Page 2 / 49e

Mainframe & Natural Training Documentation

Introduction to the Environment


You will be using an IBM 3090 mainframe running the MVS operating system. The environments you are going to be using are supplied by IBM, for use with the British Steel Mainframe. There are many environments that provide different facilities through tailored menus. Some are used for the development of programs or applications, while others provide end users with access to these applications. Below are the environments that you are likely to come in contact with : 1.


2. 3.

Commercial CICSO Strategic Services Development CICSS QA CICSU Production Manufacturing CICSG Manufacturing Development CICSD Production Tinplate CICSE CICS6 Tinplate Development Production

On the menu you will see other non-CICS environments which you may be required to use in the future, such as:

CICS4 OPCHG ESFA/ESFB TSOA/TSOB

Cap Gemini time recording Used for transferring programs between production and development Checking jobs (programs running in production) and print queues Used to develop, run and monitor JCL (job control language) jobs

These will be discussed in the Mainframe Utilities booklet. Development is used for writing and developing programs, and users have no access to this environment. QA is a development/testing environment that is accessible to the users. New programs or changes can be demonstrated here without the possibility of affecting production data. Production is where the programs are accessible to the user and run with live data. (Procedures must be followed for transferring programs between environments)

Mainframe & Natural Documentation.doc

Page 3 / 49e

Mainframe & Natural Training Documentation

Introduction To Natural
Natural is a production-oriented-fourth-generation language. Fourth generation languages (4GLs) were designed to make programming more accessible and quicker by making the commands more "English like" in there structure. Examples of other 4GL's include Microsoft Access and Microsoft FoxPro. The idea was to make learning the language as easy as possible so that you didnt require specially trained staff to write your systems. British steel uses a number of different products alongside Natural, which create a complete information system. ADABAS DB2 ENTIRE CONSTRUCT PREDICT SUPER NATURAL Relational-like database management system Relational database management system Link between the mainframe and personal computers Natural code generator (talked about later) Integrated, active data dictionary End user component that allows database inquiries

While training you will be using DB2, which is a fully relational database. Some of you however, will be working with ADABAS, which has more restrictions, but you will be shown any differences when you come to use it. Natural can operate in two modes, Online or Batch. ONLINE Processes actions as they occur

BATCHProcesses actions at scheduled times (applications with high hit rates)

Mainframe & Natural Documentation.doc

Page 4 / 49e

Mainframe & Natural Training Documentation

Getting Started
To get into the Natural Editor Go into CICS (session depends on department) You can either do this through super-session (option 1) or from option 3 on the main menu. Choose Development Log in (depends on session) Choose option D - Development You are now in the Natural Editor Once in the Natural Editor you have a number of options

Available Codes C E R D X T B L G ? . Create Object Edit Object Rename Object Delete Object Execute Program DB Command Log Facility Debugging Facility List Objects, X-Ref Global Environment Development Facilities Help Exit Development Facilities Create a new program Edit an existing program Rename an existing program or change type Delete an existing program Run program Starts NATURAL debugging facility Lists NATURAL objects or X-Ref Displays current global environment profile Help on prompts Exit Screen

M G L A P N S H C K T Z D V .

You also have a "Type" field, this is because you can create and maintain a number of different types of programs. The types are : Map Global Local Parameter Program Subprogram Subroutine Helproutine Copycode Server Text Recording Description View Exit Screen design Global data area Local data area Parameter data area Program Subprogram Subroutine Help Routine Used to include set code (setting keys)

View of a table Exit screen

So if you wanted to create a program called IZY003P you would type in :

Code .. C

Type .. P

Name .. IZY003P

Mainframe & Natural Documentation.doc

Page 5 / 49e


Changing Library

Mainframe & Natural Training Documentation

Type LOGON <library-name> and press ENTER or Move the cursor to the top right hand corner where the current library is displayed. Enter the required library name and press ENTER Create a program

Enter a code of C - Create


Enter the program type (see standards document), to create a program, the program type is P Enter the name of the required program (remembering the standards) Press ENTER This gives you a blank screen where you can add and modify code for your program. Edit an existing program From the main menu

Enter a code of E - Edit


The program type is optional, if you do enter it, make sure you enter the correct program type for the program you wish to edit. Enter the program name Press ENTER This will then bring the program into the program editor where you can modify it as required. From the command line - this can mean the command line of the NATURAL editor or the command line (at the top) of the program editor

Type E <program name> and press ENTER,


alternatively E <program-type> <program-name> and press ENTER If the program is already in the edit buffer (look at the top right hand corner, after the Library and the Mode it says what is currently in the buffer) Type E on the command line or in the code field and press ENTER

Mainframe & Natural Documentation.doc

Page 6 / 49e

Mainframe & Natural Training Documentation

The Program Editor

Command Line The program editor is the editor, which you use to modify programs. At the top of the editor is the command line. The left-hand side of the command line is available for you to use to edit the program or run other programs. At the top right hand side of the command line are three fields: Direction indicator Modifiable Program Name Not modifiable Library Not modifiable The Direction Indicator can contain values + or - and these show the direction that commands will be processed. Therefore, if the direction indicator is + and you try inserting a line. Then the line(s) will be inserted AFTER the line which you have entered the command. If the direction indicator is - and you try inserting a line, then the line(s) will be inserted BEFORE the line. The Direction indicators affect all of the editing commands in the same way. The default is + The Ruler Line The Ruler Line is the line immediately after the command line and before the actual editor. This line contains three pieces of information: Position in the program - contains TOP, ALL, or BOTTOM which show where in the program the editor is showing.

Mainframe & Natural Documentation.doc

Page 7 / 49e


Mode

Mainframe & Natural Training Documentation

This shows the mode of NATURAL which the program is written in. Two types of NATURAL exist. These are : STRUCTURED and REPORTING. Only legacy systems are written in REPORTING mode. All new programs must be written in STRUCTURED mode. If the Mode says REPORTING and you wish to change it to STRUCTURED, then on the command line type GLOBALS SM=ON Program Editor The actual program editor on the screen contains the program line numbers on the left-hand side and then the editor which contains the program code. Before the Line Number To the left of the program line numbers, there are a few blank characters. You cannot type anything into this column. This is used to mark lines. It is also used to show that a line is too long for the editor. In this case the line will appear like this

0772

IF #COUNT = 1 THEN

/* in the first instance do something differe

The Line Number The next four characters show the program line number. Initially, the program editor marks all fields in steps of 10 and then when it inserts lines it uses the trailing character. Therefore a program has four lines: 0010 0020 0030 0040 If you then insert lines between 0010 and 0020, they will be called 0011, 0012 and so on. When you then stow the program, the line numbers are recalculated so that 0011 becomes 0020 and so on. If there are more lines in the program than can be stored in steps of 10, then the editor will automatically start storing them in steps of 5 (then 4, 3, 2 and finally 1). In which case, you will only be allowed to insert 4 lines at a time. The program editor line number exists to allow line numbers to be identified in error messages, or alternatively to allow movement of the program within the editor. Between the line number and the program code A character exists between the line number and program code which merely separates the two parts. No editing can be done here. If you try to enter anything in this field the screen will lock and you will have to reset the screen using the RESET key (different on each keyboard). With the Rumba default profile this is <CTRL+R>.

Mainframe & Natural Documentation.doc

Page 8 / 49e

Mainframe & Natural Training Documentation

Libraries
Libraries are directories, they are where you store your work when you have created or modified an object. It holds both the source and/or the object code. Examples of libraries are IZ BW System General

Programming Modes
There are two styles of programming available to users of Natural : REPORTING STRUCTURED Reporting Original programming mode, easy to use not able to cope with complex applications. Has more syntax rules for more complex applications Structured

FIND CAR-FILE WITH CAR-MAKE = VOLVO DEFINE DATA SORTED BY NAME LOCAL DISPLAY NAME CAR-MAKE 01 CAR VIEW OF CAR-FILE CAR-MODEL YEAR 02 NAME LOOP 02 CAR-MAKE END 02 CAR-MODEL 02 YEAR END-DEFINE FIND CAR WITH CARE-MAKE = VOLVO SORTED BY NAME DISPLAY NAME CAR-MAKE CAR-MODEL YEAR END-FIND END

Natural Objects
There are three major groups of object types within Natural : Programmatic Objects Data Areas Screen Layouts Programs, Sub-programs Global, Parameter, Local Maps

Each group performs different functions, and has its own editor. Programmatic and data objects contain the statements/instructions for the computer about what it should do execution. Data objects also define the data that the programs are operating on. Map objects define the screen, and the report layouts, as well as holding validation rules.

Mainframe & Natural Documentation.doc

Page 9 / 49e

Mainframe & Natural Training Documentation

Program Structure
When writing programs in Natural, you must follow a pre-defined structure : DEFINE DATA Global Parameter Local END-DEFINE < Program logic > END Define Data At the start of the program you must define all data going to be used within the program. There are three levels of data that can be used. Global In this section you define data and variables that is to be accessible to all parts of your program and its objects. Parameter This data area is used within sub-programs and external sub-routines, it is used to define data that is to be passed into the current object when it is called. Local Data defined here is accessible only to the program it is defined in. Data can either be created internally (defined within the code), or externally (located outside of program and imported by your program) Predefined sets of data that can be imported are named as follows Parameter Data Area - You can have multiple PDAs Local Data Area - You can have multiple LDAs Global Data Area - You can have only one GDA { This imports a GDA named MAINGLOB } { This imports a LDA named LDA1 }

DEFINE DATA GLOBAL USING MAINGLOB PARAMETER 01 #PARAM1 (A10) LOCAL USING LDA1 LOCAL 01 EMP VIEW OF EMPLOYEES 02 EMP-NUMBER 02 NAME 01 #DATE (A6) 01 REDEFINE #DATE 02 #YY (A2) 02 #MM (A2) 02 #DD (A2) END-DEFINE

Mainframe & Natural Documentation.doc 49e

Page 10 /

Mainframe & Natural Training Documentation

Natural Syntax Program Layout


This is the basic structure of a NATURAL program, variables are declared in the DEFINE DATA LOCAL section, which is closed with the END-DEFINE statement. Followed by the program logic then the END statement. DEFINE DATA LOCAL < Declarations > END-DEFINE < Program Logic > END

Defining Variables
01 #POSTCODE (A8) This is a standard variable declaration which declares a variable named #POSTCODE to be data type A8. A8 is an Alphanumeric with a length of 8, basically a string of 8 in length. It is also possible to REDEFINE variables into sub variables as follows. 01 #POSTCODE (A8) 01 REDEFINE #POSTCODE 02 #CITY-CODE 02 #STREET-CODE

(A4) (A4)

Defined as above it allows us individual access to the separate parts of the postcode. While the entire string remains accessible as #POSTCODE, the first 4 can be accessed as #CITY-CODE and the last 4 as #STREET-CODE.
#POSTCODE

#CITY-CODE

#STREET-CODE

If you wish to assign a value to a variable when you define it you can use the INIT statement to initialise it. Example 01 #AUTHOR 01 #BOOK-NUMBER (A20) INIT <Fred Bloggs> (N6) INIT <123456 >

Mainframe & Natural Documentation.doc 49e

Page 11 /

Mainframe & Natural Training Documentation

British Steel Standards Although not required within the NATURAL language and therefore not syntactically necessary, it is part of the British Steel standards to precede variable names with a hash (#). Therefore you should make this common practice.

Control Variables
A control variable allows a variables attributes to be altered during the program execution. Control variables can be assigned values in the same format as INPUT statements. These can also be used to decide whether the field has been modified by the user. You use IF <control-field> is MODIFIED, to check to see whether a field has been modified. The control variable, is normally called the same as the field name, but with -CV as a suffix. A control variable is attached to a field in the input statement. Therefore, it is either attached on the map (within the CV field), or within the INPUT: Definition Example 01 #FIELD-CV (C) INPUT Example INPUT A Number (AD=O CD=NE) #NUMBER (CV=#NUMBER-CV) MAP Examples { This will change the attributes of the field to Underlined and Turquoise } #ACTION-CV := (AD=U CD=TU) INPUT USING MAP EXAMPLE

Logical Variables (Boolean)


A logical variable has two values TRUE and FALSE. A logical variable can be used within an IF statement in two ways: IF #LOGIC = TRUE < statements > END-IF IF #LOGIC < statements > END-IF This becomes useful when you call logical variables interesting names. Definition Example 01 #LOGIC (L) Example 01 #ERROR (L) IF #ERROR THEN <process error routine> END-IF

Mainframe & Natural Documentation.doc 49e

Page 12 /

Mainframe & Natural Training Documentation

Arrays
Arrays are defined using the following format: 01 #TEMP (A5/1:10) This will define a 1 dimensional array with 10 occurrences of type A5. This can be accessed using #TEMP(1) which looks at occurrence 1 or #TEMP(*) which looks at all occurrences of #TEMP. Multi-dimensional arrays Two dimensional and three dimensional arrays are also possible and are defined as follows. Two Dimensional Array Example 01 #TWO-DIM-ARRAY (A5/1:10,1:10) This will define a 2 dimensional array with 10x10 occurrences of type A5. Accessing the first item in the array can be done using #TWO-DIM-ARRAY (1,1), or to access the whole array use #TWO-DIM-ARRAY(*,*) Three Dimensional Array Example 01 #THREE-DIM-ARRAY (A5/1:10,1:10,1:10) This will define a 3 dimensional array with 10x10x10 occurrences of type A5. Accessing the first item in the array can be done using #THREE-DIM-ARRAY (1,1,1), or to access the whole array use #THREE-DIM-ARRAY(*,*,*).

Variable Levels
Within a data area you may have many levels of variables. Example 01 #TEMP 02 #A (A1) 02 #B (A1) 01 #TEMP2 (A5) 01 REDEFINE #TEMP2 02 #C (N5) This says that #A and #B can be grouped together and referred to group #TEMP. Or that #TEMP2 is an alpha 5 character field but which can be redefined and accessed using #C which is numeric 5. Therefore if #TEMP2 = 12345 then #C := 12345.

Mainframe & Natural Documentation.doc 49e

Page 13 /

Mainframe & Natural Training Documentation

Defining Views
Views are similar to queries, they are collections of data from database tables. When you manipulate data it is usually through a view. The closest data structure to a view is a an array of records, however only sequential access is possible. Views must be defined in the DEFINE DATA section. Example 1 { This example will define a local version of the view CUSTOMER as MY-VIEW } DEFINE DATA LOCAL 01 MY-VIEW VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME 02 CUSTOMER_ADDRESS END-DEFINE It is not necessary to always include all of the fields from a view when you define a local version. If a view has three fields for example as above, it could also be defined as below, but if it were CUSTOMER_ADDRESS would not be defined in the program and therefore not accessible. This would not be a concern however if CUSTOMER_ADDRESS was not needed by the code. Example 2 { This example will define a local version of the view CUSTOMER as MY-VIEW, but will not define the CUSTOMER_ADDRESS field of the view } DEFINE DATA LOCAL 01 MY-VIEW VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME END-DEFINE Defining Views The quickest way of defining views is with the .g(view,) command. If you type this at the beginning of a line in the NATURAL editor, it will import the entire view into the editor. This is much quicker when using views that have hundreds of fields!

0010 DEFINE DATA LOCAL 0020 .g( view, < viewname > ) 0030 0040 0050 END-DEFINE 0060 END 0070 0080

Listing the Definitions of a View On the command line type L V <view-name>, this will then list all fields on <view-name> with their descriptions, formats and status (i.e. descriptors or not)

Mainframe & Natural Documentation.doc 49e

Page 14 /

Mainframe & Natural Training Documentation

INPUT
The input statement allows the displaying of and input of data. The data can also be formatted with colours and properties. Example 1 { This will take the input of the variable #NUM } DEFINE DATA LOCAL 01 #NUM (N5) END-DEFINE INPUT #NUM END Example 2 { This will display a prompt and take the input of the variable #NUM } DEFINE DATA LOCAL 01 #NUM (N5) END-DEFINE INPUT Enter number (AD=O) #NUM END

Properties can be defined in brackets after the variable/value to be displayed/inputted. AD is the attribute definition and is used to assign basic attributes. You can also use this command to input external maps. INPUT USING MAP IZIN18M IF #ERROR THEN REINPUT Error END-IF This will re-input #ERROR and show at the bottom of the screen, the error message Error. If you use a REINPUT statement, it is often useful to show the user the exact location of the error. For example, if the error was that the user did not enter a value into a mandatory field then the user should be directed to the field they must enter. To do this you can use MARK and ALARM statements. Example REINPUT Please enter a valid code MARK *#CODE (AD=V CD=RE) ALARM MARK *#CODE places the cursor at the beginning of the field #CODE. *#CODE contains the position on the screen of the field #CODE. Therefore to mark any field you must use *<field-name> (AD=V CD=RE) highlights the field #CODE in red reverse video. The statement ALARM, will sound a beep when the error message is displayed. This further directs the users attention to an error.

Mainframe & Natural Documentation.doc 49e

Page 15 /

Mainframe & Natural Training Documentation

INPUT Attributes
You can set the attributes for the displaying of text or variables within an INPUT statement. You can set the attributes of individual components within the INPUT by setting them after each component, or you can set the attributes for the entire statement at the beginning.. Attributes (AD) U Underlined M Modifiable P Protected O Output T Translates text into upper case Colours (CD) BL Blue GR Green NE Neutral RE Red TU Turquoise YE Yellow Example 1 { This will display #COUNT with attribute O } INPUT #COUNT(AD=O) Example 2 { This will display Enter a number with attribute O and ask for the input of #COUNT as it has the attribute U, displaying it as green (GR). } INPUT Enter a number(AD=O) #COUNT(AD=U CD=GR) Example 3 { This will display all of the INPUT statement with the attribute O } INPUT (AD=O) The current date is #DATE. Standards exist at this site which must be used. See the Standards document.

Mainframe & Natural Documentation.doc 49e

Page 16 /

Mainframe & Natural Training Documentation

Edit masks
Edit masks can be used to ensure data input to a field are of the correct format. They can be used with either alphanumeric or numeric fields. IF NOT (#DATEFIELD =MASK(YYYYMMDD)) REINPUT 'Invalid date format ' (CD=RE) MARK *#DATEFIELD END-IF Where #DATEFIELD is an (A8), this edit mask will ensure that #DATEFIELD has the correct format of year, month, day, if it doesnt the user will be prompted to enter it again. There are a number of values which can be checked Character . A c C DD H L MM N n n1-n2 P S U X YY YYYY Position not to be checked. Position to be checked for alphabetical characters (upper or lower case). One or more positions to be checked for characters bounded by apostrophes (a double apostrophe indicates that a single apostrophe is the value . Position to be checked for alphanumeric content . Two positions to be checked for a valid day notation(01-31) dependent on the values of MM and YY/YYYY, if specified. Position to be checked for hexadecimal content (A-F,0-9). Position to be checked for lowercase alphabetical content. Positions to be checked for valid month (01-12). Position to be checked for a numeric digit. Position(s) to be checked for a numeric value (in the range 0 n). Positions to be checked for numeric value in the range n1<= value n2. Position to be checked for a printable character (U,N,L or S). Position to be checked for special characters. Position to be checked for uppercase alphabetical content (A-Z). Position to be checked against the equivalent position in the value following the MASK definition. Two positions to be checked for a valid year (00-99). Four positions to be checked for a valid year (0000-2099) Meaning

Mainframe & Natural Documentation.doc 49e

Page 17 /

Mainframe & Natural Training Documentation

WRITE
Write is a basic screen display command to output text or variables to the screen. Write statements wait for either the specified page size to fill up or the end of the program to display data. Example 1 { This example would not as you would expect display Hello then display world, but would display both at the same time, when the program terminates. If the program remained running, the page would need to be filled up before the data was displayed. } DEFINE DATA LOCAL END-DEFINE WRITE HELLO WRITE WORLD! END Example 2 { This example will not display data to the screen until the page buffer fills up, therefore if the page buffer was 25 and no headings were being displayed, the program would display data when #X reached the value 25. You would then need to press enter to continue. } DEFINE DATA LOCAL 01 #X (N5) END-DEFINE FOR #X = 1 to 100 WRITE #X END-FOR END

IF
The IF statement is a standard iteration statement that allows a set of statements to be performed only if a given set of logical expressions are true. IF < logical expression > < statements > ELSE < statements > END-IF ELSE is an optional part of the statement, if not required it is not necessary to use it. The IGNORE statement can also be used if you wish part of the IF statement to perform no function. Example1 IF #CURRENT-YEAR = 2000 MILLENIUM := TRUE ELSE MILLENIUM := FALSE END-IF Example2 MILLENIUM := TRUE IF #CURRENT-YEAR = 2000 IGNORE ELSE MILLENIUM := FALSE END-IF Page 18 /

Mainframe & Natural Documentation.doc 49e

Mainframe & Natural Training Documentation

Logical Conditions
NATURAL uses Boolean Algebra in its Logical Conditions. Keywords are: AND OR NOT TRUE FALSE Other predicates are: Letters EQ NE GT LT GE LE Symbols = = > < >= <= Means Equal To Not Equal To Greater Than Less Than Greater Than or Equal To Less Than or Equal To

The Letters and Symbols can be used in your code interchangeably. It is always a good idea to use brackets in your logical conditions to remove any ambiguity and make your code more readable.

DECIDE FOR
A decide statement negates the need for multiple IF statements. DECIDE FOR { FIRST/EVERY } CONDITION WHEN < logical expression > < statements > WHEN ANY < statements > WHEN ALL < statements > WHEN NONE < statements >/IGNORE END-DECIDE This method of iteration can be used if there are many conditions that can result in different actions. Example ( #VARIABLE defined as N1 and #VARIABLESTRING defined as A5 ) DECIDE FOR FIRST CONDITION WHEN #VARIABLE = 1 #VARIABLESTRING := ONE WHEN #VARIABLE = 2 #VARIABLESTRING := TWO WHEN #VARIABLE = 3 #VARIABLESTRING := THREE WHEN NONE #VARIABLESTRING := ZERO END-DECIDE Mainframe & Natural Documentation.doc 49e Page 19 /

Mainframe & Natural Training Documentation

DECIDE ON
Another version of the decide statement allows expressions on specified variables only as shown below. DECIDE ON { FIRST/EVERY } VALUES OF operand1 VALUE < condition > < statements > ANY VALUES < statements > ALL VALUES < statements > NONE VALUES < statements >/IGNORE END-DECIDE Example ( #VARIABLE defined as N1 and #VARIABLESTRING defined as A5 ) DECIDE ON FIRST VALUE OF #VARIABLE VALUE 1 #VARIABLESTRING := ONE VALUE 2 #VARIABLESTRING := TWO VALUE 3 #VARIABLESTRING := THREE NONE VALUES #VARIABLESTRING := ZERO END-DECIDE

Loops
There are three versions of loops :- FOR, REPEAT and FIND Each of these loops are covered below. Any loop can be given a label to identify it precede the loops first statement with a label name followed by a full stop and a space. REPEAT Label Example MYLABEL. REPEAT END-REPEAT FOR Label Example MYLABEL. FOR #COUNT = 1 to 10 END-FOR

FOR Loop
A FOR loop will allow you to repeat a set of statements x amount of times. FOR #COUNT = 1 to 10 < statements > END-FOR Mainframe & Natural Documentation.doc 49e Page 20 /

Mainframe & Natural Training Documentation

As the loop processes, each parse will increment the #COUNT variable by 1, ending the loop with a final parse where #COUNT equals 10.

REPEAT Loop
REPEAT Loops allow the looping of a set of statements UNTIL a given logical expression is true or WHILE a given logical expression is true. REPEAT < statements > END-REPEAT A basic REPEAT loop like the one above will simply loop infinitely, the UNTIL or WHILE command can be used as a means of exiting. The statements can either be immediately after the REPEAT statement or immediately before the END-REPEAT statement, depending upon when the check is needed. WHILE Example #X := 1 REPEAT #X := #X + 1 WHILE #X < 10 END-REPEAT UNTIL Example #X := 1 REPEAT #X := #X + 1 UNTIL #X = 10 END-REPEAT

FIND Loop
A FIND loop is used to query a database table or view in order to find specific records. FIND < viewname > WITH < search criteria > < statements > END-FIND A find loop will scan the specified view for a record matching the search criteria. Every time a record is found, the statements inside the loop will be executed. When no more matching records can be found the loop will exit. Example { If we wished to find a record in the view COLD-STOCK with the field AA12CIDN = 12345 then we would format the find as follows } FIND COLD-STOCK WITH AA12CIDN = 12345 END-FIND We can also limit the amount of record that we look for, i.e. if we were only interested in finding one record we could specify it, which would stop the program searching the rest of the view or table and increasing wasted processor usage. We can specify the amount of records to find by placing it in brackets after the FIND statement. Limited Example FIND(1) COLD-STOCK WITH AA12CIDN = 12345 END-FIND Mainframe & Natural Documentation.doc 49e Page 21 /

Mainframe & Natural Training Documentation

If we give the FIND loop a label and use the command NUMBER in the statement then we can return the amount of matching records within a table or view. A END-FIND is not required if we use the command in this way. The number found can then be utilised with the *NUMBER statement. Count Example { #AMOUNT defined as N5 } MYLABEL. FIND NUMBER COLD-STOCK WITH AA12CIDN = 12345 #AMOUNT := *NUMBER( MYLABEL. ) The sorted by statement can be used to return records matching the criteria sorted by a specific field. The statement can be used to sort ascending or descending. Ascending Sorting Example FIND CUSTOMER WITH CUSTOMER_ID NE SORTED BY CUSTOMER_NAME END-FIND Descending Sorting Example FIND CUSTOMER WITH CUSTOMER_ID NE SORTED BY CUSTOMER_NAME DESCENDING END-FIND

IF NO RECORDS FOUND
A FIND statement is a loop around all the records on the database matching the given search criteria. If no records are found, then the loop collapses and no statements within the FIND - END-FIND are processed. There are some cases when it is useful to carry out some processing if no records match the search criteria. In this case we can use a NO RECORDS clause: Example FIND-AN-ORDER. FIND GW-VGW03351 WITH SUPPLY_ORDER_NUMBR = 123456789 IF NO RECORDS FOUND INPUT Error, order does not exist ESCAPE BOTTOM (FIND-AN-ORDER.) IMMEDIATE END-NOREC <process-order> END-FIND In this example, if the order number does not exist, then an error message is displayed and the loop is escaped. If you have an IF NO RECORDS FOUND clause, you should always have an ESCAPE BOTTOM (LABEL.) IMMEDIATE, since you have now entered within the FIND - END-FIND loop and therefore the statements before the END-FIND will be carried out. The same functionality is used when using a FIND (1). If you use a FIND NUMBER, then checking for no records is slightly different. CHECK-EXISTENCE. FIND NUMBER GW-VGW03351 WITH SUPPLY_ORDER_NUMBR = 123456789 IF *NUMBER(CHECK-EXISTENCE) = 0 INPUT Order does not exist Mainframe & Natural Documentation.doc 49e Page 22 /


END-IF

Mainframe & Natural Training Documentation

Notice that the FIND NUMBER has no END-FIND (since it is not a loop) but the IF *NUMBER(CHECK-EXISTENCE) = 0 requires an END-IF because it is just a simple IF statement.

ESCAPE
The escape statement is used to escape from any loop. Placed inside a loop there are four variations of the statement. ESCAPE BOTTOM Exits the current loop continuing from bottom. ESCAPE TOP Exits the current loop continuing from top, therefore re-entering the loop. ESCAPE ROUTINE Exits the current Sub Routine. ESCAPE Same as ESCAPE BOTTOM. STOP This could be used instead of ESCAPE ROUTINE in a program. The STOP command stops processing any more Natural. Any of the statements can be succeeded with a label name to specify which loop to escape. Normal Example REPEAT IF #OPTION = EXIT ESCAPE BOTTOM END-IF END-REPEAT Label Example MYLABEL. REPEAT IF #OPTION = EXIT ESCAPE( MYLABEL. ) END-IF END-REPEAT

MOVE
There are many different statements which cause the value of one field to be moved to another. The main ones are: MOVE <operand1> to <operand2> Example { which will move the value of 5 into #COUNT } MOVE 5 TO #COUNT

ASSIGN
ASSIGN <operand1> = <operand2> <operand1> := <operand2> Example 1 { This will assign the value of 5 to #COUNT } Mainframe & Natural Documentation.doc 49e Page 23 /


ASSIGN #COUNT = 5

Mainframe & Natural Training Documentation

Example 2 { Assignments can also be made with the following syntax } #COUNT := 5

COMPRESS
Compress is used to construct a string from various components. COMPRESS <String 1> <String 2> <String X> INTO <Destination String> Example { This example will COMPRESS #FIRST-NAME #MIDDLE-NAME and #LAST-NAME into the variable #FULL-NAME } DEFINE DATA LOCAL 01 #FIRST-NAME (A10) INIT <Billy> 01 #MIDDLE-NAME (A10) INIT <Jo> 01 #LAST-NAME (A10) INIT <Jones> 01 #FULL-NAME (A30) END-DEFINE COMPRESS #FIRST-NAME #MIDDLE-NAME #LAST-NAME INTO #FULL-NAME WRITE #FULL-NAME END

COMPUTE
Compute will solve a mathematical equation on the right and store the result in the variable given on the left. COMPUTE <operand 1> = <operand2> Example { This will calculate the value of #VARIABLE-ONE plus #VARIABLE-TWO and store the result in #TOTAL } COMPUTE #TOTAL = #VARIABLE-ONE + #VARIABLE-TWO

UPDATE
When a change has been assigned to a view the UPDATE command must be used to actually make the changes to the view. Example 1 { This example would not actually change the CUSTOMER_NAME as UPDATE has not been used } DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME END-DEFINE

Mainframe & Natural Documentation.doc 49e

Page 24 /

Mainframe & Natural Training Documentation

LABEL. FIND (1) CUSTOMER WITH CUSTOMER_ID = 00001 CUSTOMER_NAME := Jeffs Solid Structures END-FIND END Example 2 { This example would make the changes to the view } DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME END-DEFINE LABEL. FIND (1) CUSTOMER WITH CUSTOMER = 00001 CUSTOMER_NAME := Jeffs Solid Structures UPDATE (LABEL.) END-FIND END You cannot UPDATE the value in a primary key field. As the primary key is the unique identifier of a record, updating it is actually creating a new record .

STORE
The store command will create a new record containing the current records details. STORE < view name > Example { This example will search for the record with CUSTOMER_ID = 12345 and change the ID to 11111, it will not actually change in the tables because an UPDATE has not been issued. The STORE statement will then create a new record with the same details as this record including any that have been changed. } FIND(1) CUSTOMER WITH CUSTOMER_ID = 12345 CUSTOMER_ID := 11111 STORE CUSTOMER END-FIND

DELETE
The delete command removes the current record from the specified find label. DELETE < label name > Label name is optional, but keeps your program more readable, therefore more easily maintainable. The label also makes it obvious what records are to be deleted. Example { This example will delete the record with CUSTOMER_ID = 00000 }

Mainframe & Natural Documentation.doc 49e

Page 25 /

Mainframe & Natural Training Documentation

MYLABEL. FIND(1) CUSTOMER WITH CUSTOMER_ID = 00000 DELETE ( MYLABEL. ) END-FIND

END TRANSACTION
This statement will make all changes made to views since the last end transaction permanent. They will be updated in the database tables. In the above programs ( Examples for Update, Store and delete ), the end of the program is reached and this has the same effect as end transaction. Once an end transaction has been reached the data can not be backed out with backout transaction. Example { This example would make the changes to the view as above } DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME END-DEFINE LABEL. FIND (1) CUSTOMER WITH CUSTOMER_ID = 00001 CUSTOMER_NAME := Jeffs Solid Structures UPDATE(LABEL.) END-FIND END TRANSACTION END The END TRANSACTION must appear outside the FIND loop. If screen I/O occurs, it has the same effect as an End Transaction being issued.

BACKOUT TRANSACTION
This statement allows all data that has been altered on views to be reverted to its previous values unless an end transaction has already been issued. Example { This example would make the changes to the view but then revert them to their previous values } DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME END-DEFINE LABEL. FIND (1) CUSTOMER WITH CUSTOMER_ID = 00001 CUSTOMER_NAME := Jeffs Solid Structures UPDATE (LABEL.) END-FIND Mainframe & Natural Documentation.doc 49e Page 26 /

Mainframe & Natural Training Documentation

BACKOUT TRANSACTION END

PERFORM
The perform statement is used to call sub routines Example { This example will call the sub routine MY-SUBROUTINE with #MY-PARAMETER1 and #MY-PARAMETER2 as parameters. } PERFORM MY-SUBROUTINE #MY-PARAMETER1 #MY-PARAMETER2

Subroutines
External and Internal subroutines can exist. If you call an internal subroutine then you dont pass any parameters because it immediately has access to all the variables defined within the calling routine. But external subroutines must be passed parameters: Internal Syntax DEFINE SUBROUTINE <subroutine-name> <subroutine-logic> END-SUBROUTINE External Syntax DEFINE DATA PARAMETER <parameter-list> LOCAL <local list> END-DEFINE DEFINE SUBROUTINE <subroutine-name> <program logic> END-SUBROUTINE END The <subroutine-name> as defined within the DEFINE SUBROUTINE statement must match exactly the name called in the PERFORM. This becomes an issue in external subroutines which have the code name as, say, IZSUB1S, but are defined as DEFINE SUBROUTINE PROCESS-RECORD, in which case, to PERFORM the subroutine you would Example PERFORM PROCESS-RECORD

FETCH RETURN
The Fetch Return statement is used to call programs. FETCH RETURN <program-name> <parameter-list> Mainframe & Natural Documentation.doc 49e Page 27 /

Mainframe & Natural Training Documentation

The program being called is a standard natural program. To receive parameters in a program you must check the stack to see whether and exist and then process them. This is done in the receiving/called program. IF *DATA GT 0 INPUT <parameter-list > END-IF Example { This example will call the program STUD1 with #MY-PARAMETER as a parameter } FETCH RETURN STUD1 #MY-PARAMETER

CALLNAT
The CALLNAT statement is used to call sub programs. CALLNAT <subprogram-name> <parameter-list> The subprogram layout is : DEFINE DATA PARAMETER <parameter list> LOCAL <local data list> END-DEFINE <program logic> END Example { This example will call the sub program STUDSUB with #MY-PARAM as a parameter } CALLNAT STUDSUB #MY-PARAM

Date and Time system variables


The following date and time system variables may be specified in an ASSIGN, COMPUTE, DISPLAY, MOVE, WRITE statement and in logical criteria: Date Variable *DATD *DATE *DATG *DATI A8 A8 A15 A8 Format/ Length Explanation Current date in format DD.MM.YY. Current date in format DD/MM/YY. Current date in format DdmonthnameYYYY (Gregorian format). Current date in format YY-MM-DD. Page 28 /

Mainframe & Natural Documentation.doc 49e

Mainframe & Natural Training Documentation

*DATJ *DATN *DATU *DATX

A5 N8 A8 D

Current Julian date in format YYDDD. Current date in format YYYYMMDD. Current date in format MM/DD/YY. Current date in internal date format.

Time Variable *TIMD(r) N7

Format/ Length

Explanation May only be used in conjunction with a previous SETTIME statement and contains the elapsed time difference between the time base established by SETTIME and the current time (in format HHMMSST). Time of day in format HH:MM:SS.T. Specifies the number of seconds remaining before the current transaction will be timed out (only available with NATURAL SECURITY). *TIME-OUT is reset to zero with the execution of an END TRANSACTION or BACKOUT TRANSACTION statement. Machine internal store clock value. Time of day in format HHMMSST Time of day in internal format

*TIME *TIME-OUT

A10 N5

*TIMESTMP *TIMN *TIMX

B8 N7 T

Timestamp There is a British steel subroutine called BSSTMPS which will return the current timestamp, a field of A26 must be used when calling this routine. Format YYYY-MM-DD-HH.MM.SS.TTTTTT Example { To move the current timestamp into #TIMESTAMP(A26) } PERFORM BSSTMPS #TIMESTAMP

MOVE EDITED When processing date and time fields it may be necessary to use the MOVE EDITED command along with an edit mask (EM)

Mainframe & Natural Documentation.doc 49e

Page 29 /

Mainframe & Natural Training Documentation

Example 1 { This example moves a date from a date field in the format YYYYMMDD to another field in the format DDMMYYYY. } 01 #DATE (D) 02 #DATE2 (A8) MOVE EDITED #DATE(EM=DDMMYYYY) TO #DATE2 Example 2 { This example will move the contents from #DATE2 to #DATE in format YYYYMMDD } MOVE EDITED #DATE2 TO #DATE(EM=YYYYMMDD)

Windows
Sometimes a program calls for a window to be used for error or warning messages. To do this you first of all need to define the window at the start of the program, then you need to input the window with the required information at the required point in the code. Definition DEFINE WINDOW < window-name > SIZE {AUTO | QUARTER | operand1 * operand2} BASE {CURSOR | {TOP | BOTTOM} {LEFT | RIGHT} | operand3 / operand4 } TITLE <title-text> FRAMED ON | OFF Example 1 { This defines the window called ERROR, which when it appears will have the title Error at the top of it. Its size adjusts to the size of the information contained in it and the base appears at row 8 column 15. The frame is switched on } DEFINE WINDOW ERROR SIZE AUTO BASE 8/15 TITLE Error FRAMED ON To use the window which has been defined: INPUT WINDOW = <window-name> You then use the statement like an ordinary INPUT statement and use input attributes as before. Example 2 { This example will display the window and display the text inside it } INPUT WINDOW = ERROR // Error, you do not have security to this function (CD=NE)

British Steel Standards The window frame should always be set on

Mainframe & Natural Documentation.doc 49e

Page 30 /

Mainframe & Natural Training Documentation

Comments
As you know it is good practice to put comments in your programs. There are three ways you can use these in Natural: * ** /* An asterisks with a space after it Two asterisks, there is no need for a space on this one. Use this one when the comment starts after some Natural code and appears in the middle of the screen.

Example { The following is a code listing containing valid comments }

0010 DEFINE DATA LOCAL 0020 * This is a comment 0030 END-DEFINE 0040 ** This is a comment 0050 END /* This is a comment 0060 0070

PF-Keys
PF-Keys must be set so that they display the correct data at the bottom of the screen and so they are available for use. To enable key naming use the FORMAT KD. This will display the PF-Key bar at the bottom of the screen. Example 1 { This will display the PF-Key bar at the bottom of the screen with Exit underneath the PF3 key, PF3 will also be available for use. } FORMAT KD=ON SET KEY PF3 NAMED EXIT Although we have set the key name and made it visible on the screen, PF3 will still perform no function until we check which key has been pressed and perform a function for that key. Example 2 { This will allow a specific function to be performed after a PF-Key has been pressed } FORMAT KD=ON SET KEY PF3 NAMED Exit SET KEY PF7 NAMED Up SET KEY PF8 NAMED Down DECIDE ON FIRST VALUE OF *PF-KEY VALUE PF3 STOP VALUE PF7 PERFORM SCROLL-UP VALUE PF8 Mainframe & Natural Documentation.doc 49e Page 31 /


PERFORM SCROLL-DOWN NONE VALUES REINPUT Invalid Key END-DECIDE

Mainframe & Natural Training Documentation

British Steel Standards British Steel have standards regarding the use of PF-Keys and their functions and these standards need to be followed.

Log Counter
All views in DB2 which can be updated have a field called LOG_COUNTER. This is used to stop corruption of the information. Example User A, who works in New York, retrieves a record of Coating Code AA and displays it to the screen. He notes that the description is Coating AA. He then goes to lunch. Meanwhile, User B, who lives in Sydney, retrieves Coating Code AA and modifies the description to be Another Coating Type. User B updates the record and continues with his job. User A then returns from lunch and looks at his screen where Coating Code AA is still displayed as it was before lunch with description Coating AA. He remembers what he was doing before lunch and modifies the description to be Coating AA Description, presses ENTER, updates the record and goes about his afternoons work. Now who has created the right description? User A or User B? To stop cases of this occurring the LOG_COUNTER is used. When you display a record, a note is made of the LOG_COUNTER. When you then try to update the record a check is made to see that the LOG_COUNTER on the file is the same as the one you have noted. If it isnt then the update is not allowed. Therefore in our example, User A displays Coating AA and the LOG_COUNTER is 1. User B updates the LOG_COUNTER to 2. User A comes back from lunch and tries to modify the record but the LOG_COUNTER is now different. He must redisplay the record to be allowed to then modify it. The LOG_COUNTER exists on all views in DB2 which can be updated but the checking and updating of it is done within the program. You are therefore responsible to check and update it within your own program.

Mainframe & Natural Documentation.doc 49e

Page 32 /

Mainframe & Natural Training Documentation

Program editing commands


To use any of the editing commands described below, you must start the command on the first character of the line. The . in the first character then tells the editor that this is a command and not simply text or part of the program. Insert a line .i on the line you wish to insert lines at. This inserts 9 lines at the cursor position. If you do not use all 9 lines then the program editor will simply collapse all of the blank lines. If you require less than 9 lines inserted then either type .i(n) where n is the number of lines to be inserted. Inserting lines from another program The program which you wish to copy lines from, must exist in the same library and also be in Development. At the place in the code where you wish to copy the lines, type .i( <program-name>, <starting-line>, <number-of-lines> ) < program-name > must be in capitals. < starting-line > is the first line of the program which you wish to copy. This is not the line which appears at the left of the program editor (0010,0020). It is the LINE NUMBER. Therefore, the line marked 0010 in the program editor, is actually line 1. The line marked 0530 is actually line 53, and so on. The complication comes when the program editor marks line s in multiples of 5 or less, then you have to work out that the line marked as 0005 is line 1 and the line marked 0010 is line 2, and so on. < number-of-lines > is the number of lines (including the first line) which you want to copy. If you type .i(< program-name >), then the whole of <program-name> will be inserted. Mark a line .x on the line to be marked with a X .y on the line to be marked with a Y Delete a line .d on the line to be deleted. This command can be used on many lines at once if more than one line is required for deletion. To delete a number of lines type .d(X) where X is the number of lines you wish to delete. To delete a block of lines then mark the first line to be deleted with an X and the last line to be deleted with a Y and then on the command line type dx-y Mainframe & Natural Documentation.doc 49e Page 33 /

Mainframe & Natural Training Documentation

Copy a line .c on the line to be copied. To copy a line to another place within the program. Mark the line with an X and then on the line where you wish the line to be copied to and then type .cx To copy a block of lines, then mark the first line to be copied with an X and the last line to be copied with a Y and then move the cursor to the line you wish the lines to be copied to and type .cx-y Move a line .mx on the line where you wish the line marked with an X to be moved to. To move a block of lines, then mark the first line of the block with an X and the last line of the block with a Y and then move the cursor to the line you wish the lines to be moved to and type .mx-y Split a line .s on the line to be split and the WITHOUT PRESSING ENTER move the cursor to the position the line is to be split at and then press ENTER. Join two lines .j on the line and press ENTER and this will join the line with the one immediately below it. Scroll through code PF7 scrolls up. PF8 scrolls down Reposition screen at a particular point Either type a line number on the command line to move that line to the top of the program editor. Alternatively, type .p on the line which is to be moved to the top of the program editor and press ENTER. Scan for a particular value Type sc on the command line and a window appears which allows you to scan and replace information. Leave the replace value field blank if you just want to scan. Remember that scanning is case sensitive. The scan looks at all words and checks them exactly for the scan value. If you require a scan which looks at part of words then check the Absolute scan field in the scan window. Alternatively, on the command line, you can type sc < scan-value > and press ENTER. This will not bring up the scan window. When the program has found a match for < scan-value >, press PF11 to scroll back to the previous match and PF12 to find the next match.

Mainframe & Natural Documentation.doc 49e

Page 34 /

Mainframe & Natural Training Documentation

Standards
Variable Naming All user defined variables within a program should begin within a #. Therefore a variable used to represent a year should be #YEAR. Program Naming XX_ _ _ _ _ _ Project Code Example IZ _ _XXXX_ _ _ _ _ _ _ _X_ Program Code Example MCSM/T004 Program Type P Program N Subprogram S Subroutine M Map A Parameter Data Area (PDA) L Local data area G Global Data Area C Copy code T Text H Help Routine Unique Suffix 1 Unique suffix, can be blank, 0-9 or A-Z

_ _ _ _ _ _ _X Screens PF-Key PF1 PF3 PF6 PF7 PF8 PF12 PF19 PF20 PF24

Function Help Exit Confirm Scroll Backwards Scroll Forwards Cancel Page Left Page Right Main Menu

Text Type Optional Modifiable Mandatory Modifiable Text Output Only

Colour Yellow and Underlined Green and Underlined White Turquoise

Screen Text Instruction on a screen or prompts for input are classed as text and should be displayed with standard attributes.

Mainframe & Natural Documentation.doc 49e

Page 35 /

Mainframe & Natural Training Documentation

Modifiable Fields All modifiable fields should be underlined. A modifiable field is one which you want a user to enter a value into. Mandatory Modifiable Fields A field is mandatory when it is compulsory for the user to enter a value. Output Fields If a field is to display information to the user then it is an output field. These are fields which the user has no ability to modify. All text must be correctly punctuated. All fields on a screen must line up with each other. The only exception to this rule is that the action field must be left in the default position.

Action: Code..: Description:

Standards say that if there is space for the full description then it should be used, otherwise replaced with a sensible alternative: Good

Coating Code: Coating Description..: Full field descriptors and correctly aligned. Bad

Or

Coating Code....: Coating Desc: Coating Description shortened but still understandable and fields remain correctly Aligned.

Code: Coating Description: On the left we can see that Coating Code has been shortened but there was space for the full field descriptor.

Or

C..: D..: Not very descriptive!

For modifiable fields there should be no colon (:), these should only appear for output fields.

Mainframe & Natural Documentation.doc 49e

Page 36 /

Mainframe & Natural Training Documentation

DB2 Query Efficiency Issues


You should always make DB2 do the work rather than NATURAL. When coding FINDs and loops which interrogate views you should be very careful about how they are coded. It is always better to get DB2 to do as much of the work as possible. When DB2 is accessed SQL code is generated to perform the query, This code is only generated once for Options 2 & 3 whilst being generated on each parse for Option 1. Example Consider a time when you may wish to interrogate all orders from Toyota (A1234). You could do this in three ways. Option 1 - All NATURAL FIND GW-VGW03351 WITH SUPPLY_ORDER_NUMBR NE IF CUSTOMER NE A1234 THEN ESCAPE TOP IMMEDIATE END-IF END-FIND This will find all the orders on the order file and then NATURAL (or the program) will disregard all the orders not belonging to TOYOTA. THIS OPTION IS HIGHLY INEFFICIENT AND IS NOT RECOMMENDED OR SUPPORTED BY CAP GEMINI. Option 2 - Some NATURAL and some DB2 FIND GW-VGW03351 WITH CUSTOMER = A1234 END-FIND This will find all the orders on the order file belonging to TOYOTA. In this example, DB2 is doing the work, since the search only finds TOYOTA orders. This is usually the most efficient method of searching for data, but on occasion where a specific view exists it is more efficient to use Option 3. Option 3 - All DB2 FIND GW-VGW0335EG WITH SUPPLY_ORDER_NUMBR NE END-FIND This will find all the orders on the view of the order file GW-VGW0335EG which has been previously been set up to show only TOYOTA orders.

Mainframe & Natural Documentation.doc 49e

Page 37 /

Mainframe & Natural Training Documentation

This option is highly efficient when TOYOTA orders are treated differently many times. It is not usually the case to create new views for occasions when the view will only be used once. However, this is sometimes the case. It is best to seek advice on this matter. Normally the analyst will tell you which view to use and the decision in the matter of new views being created has already been taken. An official CAP GEMINI document has been created as to DB2 and SQL best practices

Example Code
For the examples, I have used the following views. These views are fictional, so dont try and use them! ORDER ORDER_ID ( Primary Key ) ORDER_DATE ORDER_DESCRIPTION CUSTOMER_ID CUSTOMER CUSTOMER_ID ( Primary Key ) CUSTOMER_NAME CUSTOMER_ADDRESS

1) A program to change the name of a customer, using a FIND loop with UPDATE and ENDTRANSACTION statements. Spec: A program to change the name of customer with CUSTOMER_ID equal to 12345 to Bobs Jobs Inc.

DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME 02 CUSTOMER_ADDRESS END-DEFINE LABEL. FIND(1) CUSTOMER WITH CUSTOMER_ID = 12345 CUSTOMER_NAME := Bobs Jobs Inc UPDATE (LABEL.) END-FIND END TRANSACTION END

2) A program that changes the name of a customer for a specific order, using a nested FIND loop. Spec: A program to change the name of the customer who placed the order with ORDER_ID = 54321 to Teds Freight Company.

DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER Mainframe & Natural Documentation.doc 49e Page 38 /


02 CUSTOMER_ID 02 CUSTOMER_NAME 02 CUSTOMER_ADDRESS 01 ORDER VIEW OF ORDER 02 ORDER_ID 02 ORDER_DATE 02 ORDER_DESCRIPTION 02 CUSTOMER_ID END-DEFINE FIND(1) ORDER WITH ORDER_ID = 54321

Mainframe & Natural Training Documentation

LABEL. FIND(1) CUSTOMER WITH CUSTOMER_ID = ORDER.CUSTOMER_ID CUSTOMER_NAME := Teds Freight Company UPDATE (LABEL.) END-FIND END-FIND END TRANSACTION END 3) A program that displays customer information for an inputted order, using a nested FIND and using statements WRITE and INPUT. Also IF NO RECORDS FOUND should be used to display an error message if the order does not exist. Spec : A program that displays all customer details for a particular order. The program should prompt for the order id and display an error message if it does not exist.

DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME 02 CUSTOMER_ADDRESS 01 ORDER VIEW OF ORDER 02 ORDER_ID 02 ORDER_DATE 02 ORDER_DESCRIPTION 02 CUSTOMER_ID 01 #ORDER-CRITERIA (N5) END-DEFINE INPUT Enter Order Id : (AD=O) #ORDER-CRITERIA FIND(1) ORDER WITH ORDER_ID = #ORDER-CRITERIA IF NO RECORDS FOUND INPUT (AD=O) Error Order does not exist with order id #ORDER-CRITERIA ESCAPE ROUTINE END-NOREC FIND(1) CUSTOMER WITH CUSTOMER_ID = ORDER.CUSTOMER_ID END-FIND END-FIND WRITE CUSTOMER_ID CUSTOMER_NAME CUSTOMER_ADDRESS END

4) A program that copies a record using the STORE statement and deletes a record using the DELETE statement.

Mainframe & Natural Documentation.doc 49e

Page 39 /


Spec :

Mainframe & Natural Training Documentation A program that will copy the contents of customer record with CUSTOMER_ID = 10101 to a new record and give it a customer name of Aluns Crowbars Ltd and a customer id of 99999, then deleting the old record with CUSTOMER_ID = 10101.

DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME 02 CUSTOMER_ADDRESS END-DEFINE CUSRCH. FIND(1) CUSTOMER WITH CUSTOMER_ID = 10101 CUSTOMER_ID := 99999 CUSTOMER_NAME := Aluns Crowbars Ltd STORE CUSTOMER DELETE (CUSRCH. ) END-FIND END TRANSACTION END

5) A program that retrieves the date of the most recent order for a particular customer and displays how many days it has been since that order. This program should use variables of type D and incorporate EDIT MASKS. Spec : Find the date of the most recent order for an inputted CUSTOMER_ID and calculate the number of days between that date and the current date on the system.

DEFINE DATA LOCAL 01 CUSTOMER VIEW OF CUSTOMER 02 CUSTOMER_ID 02 CUSTOMER_NAME 02 CUSTOMER_ADDRESS 01 ORDER VIEW OF ORDER 02 ORDER_ID 02 ORDER_DATE 02 ORDER_DESCRIPTION 02 CUSTOMER_ID 01 #ORDER-CRITERIA (N5) 01 #MOST-RECENT-ORDER-DATE (D) 01 #DAYS (N8) END-DEFINE * * NB * 01 / 01 / 1582 is the earliest valid date accepted by NATURAL variables of type D. * MOVE EDITED 15820101 TO #MOST-RECENT-ORDER-DATE (EM=YYYY/MM/DD) INPUT (AD=O) Enter Customer ID : #ORDER-CRITERIA FIND ORDER WITH CUSTOMER_ID = #ORDER-CRITERIA IF NO RECORDS INPUT (AD=O) This customer has never placed an order. ESCAPE ROUTINE END-NOREC IF ORDER_DATE > #MOST-RECENT-ORDER-DATE #MOST-RECENT-ORDER-DATE := ORDER_DATE Mainframe & Natural Documentation.doc 49e Page 40 /

Mainframe & Natural Training Documentation END-IF END-FIND SUBTRACT #MOST-RECENT-ORDER-DATE FROM *DATX GIVING #DAYS INPUT (AD=O) Customer ID = #ORDER-CRITERIA / Most Recent Order Date = #MOST-RECENT-ORDER-DATE / Current Date = *DATX (EM=DD/MM/YYYY) / Number of days since last order = #DAYS

END

Map editor
To get into the map editor go into Development Facilities then create a Map, giving it a suitable name. Press enter and you should be at the map editor menu. Call the map TE_ _MAP1 (blanks are your initials)

Code .. C

Type .. M

Name .. TE_ _MAP1__________________

Ensure the profile is DOMMI, then choose to initialise the map.

Code .. I

Name .. TE_ _MAP1

Profile .. DOMMI_________

On pressing ENTER the map settings screen will now be displayed showing the delimiters, format, etc.

Mainframe & Natural Documentation.doc 49e

Page 41 /

Mainframe & Natural Training Documentation

Delimiters Delimiters control the class, attributes and colour of the fields on the map. Cls (class) A M O T Input Field Output field (modifiable) Output field (not modifiable) Text constant

Attr (attributes) B D I N U C V Y Blinking Default Intensity intensified Non-Display underlined Cursic/Italic Inverse Video Dynamic (Controlled from calling program, by using control variables)

CD (Colour Definition) BL GR NE Blue green Neutral (white) Page 42 /

Mainframe & Natural Documentation.doc 49e


PI RE TU YE Layout Pink Red Turquoise Yellow

Mainframe & Natural Training Documentation

Standard map layouts have been provided to aid development of programs. The layouts are as follows: BSLAY Basic map (heading and field only) BSLAYFM1 File maintenance (heading, command and action) BSLAYFM2 File maintenance (as above with scrolling) BSLAYFM3 File maintenance (new model with action array) BSLAYMN1 Menu BSLAYMP1 Multi purpose screen with action code field BSLAYOM1 Object maintenance (heading, command and action) BSLAYOM2 Object maintenance (as above with scrolling) BSLAYSC1 Primary key input BSLAYSL1 Browse (heading, command, key-input and action array) BSLAYSL2 Browse (as above minus action array) These layouts may be used by setting the profile to DOMMI. For training purposes the layout has been left blank (you will need to blank in out on your map)

Pressing Enter should take you through to the map editor.

Mainframe & Natural Documentation.doc 49e

Page 43 /

Mainframe & Natural Training Documentation

The map editor allows screens to be created and related processing to be performed independently from the object that will invoke the screen. All aspects of map and form definition can be handled by the map editor : Screen layout Data communication Validation Program syntax The data (fields) used within the map must already have been defined within the define data statement at the start of your program. If you use one of the layouts, they have pre-defined fields, which you will have to declare in your program. Control will only be returned to the invoking object when all map processing has been completed. PF keys in the map editor PF2 PF3 PF4 PF9 PF6,7,8,10,11 PF12 Return to map settings screen Quit See what the user will see Flip between full and split screen view Screen positioning on large maps Ignore all changes since last Enter key

Incorporating data Data can be incorporated into the map by typing a module code followed by its name into the command line at the top left of the screen. The modules that can be incorporated are: A G H L N P S V Parameter Data Area Global Data Area Help Routine Local Data Area Subprogram Program Subroutine View

For example, to incorporate fields from view AWTRN-VEHICLES into a map, enter V AWTRNVEHICLES on the command line after Ob. To scroll up and down the list of fields use - and + on the command line. The same can be done for programs.

Ob : P

TE_ _01P

As long as these are declared in you program, you map will know where to get the information from. Mainframe & Natural Documentation.doc 49e Page 44 /

Mainframe & Natural Training Documentation

To get a fields onto the map from the view enter the delimiter required followed by the corresponding number of the field. Enter :3 on the screen after the prompt, to get the field PERSONNEL_ID in modifiable output, of default underlined and green in colour.

Field commands Field commands allow manipulation of the screen , they begin with a period . , this being entered over the delimiter character of the field in question. .A .C .D .E .M Array definition Centre Field Delete Field Invoke Extended field editing Move field to cursor

Extended Field Editing This is where field attributes and length displayed on screen are altered and help routines can be attached. To get to the extended editing screen, go to the first space on the field you wish to edit and press PF5

Mainframe & Natural Documentation.doc 49e

Page 45 /

Mainframe & Natural Training Documentation

To attach a Help Routine to a field, the name of the routine and the parameters it takes must be entered in the HE field. E.g. BWER02H1,#customer-name If more room is needed in the help field type + to open up more space. The AL attribute field will limit the length of a displayed variable on the map, for instance if a field is an A40, it can be shortened to make it fit neatly on a map. The CV attribute field is used for attaching control variables to the field (they will need to be declared in your program)

Stowing and Saving Once the map is complete, PF3 out of the map editor back to the map editor menu and choose to stow or save the map. You will need to stow the map if you wish to run it. The program that uses the map will need to be stowed after any changes are made to the map. Attaching to a program To attach a map to a program, you must declare a data area in your program. This area is a pre-defined routine, which validates the map. It is called CDGETDCA. DEFINE DATA LOCAL USING CDGETDCA LOCAL <Declarations> Mainframe & Natural Documentation.doc 49e Page 46 /


END-DEFINE To call the map you use an input statement: INPUT USING MAP TE_ _MAP1

Mainframe & Natural Training Documentation

REMEMBER

When using a map set the profile to DOMMI. Use British Steel standards for map layout and attribute definitions. STOW the map before you try to run it. All fields in the map need to be declared in the program. Call the map using an INPUT statement. Re-stow the program that calls a map if you make any changes to that map.

Test Programs
The following are some simple test programs to get you familiar with Natural. These programs should be written in the Natural environment accessible from the CICSO menu as option 3. The test views are available in this environment. Answers to the programs are held in the Solutions section. When naming your programs you should use the following structure: TE_ _XXP The two blanks should be filled in with your initials and the Xs replaced with the program number (01 09. Sub-programs should end with an N in place of a P and maps with an M).

Mainframe & Natural Documentation.doc 49e

Page 47 /


1.

Mainframe & Natural Training Documentation

Write / Input 1.1. Write a program that displays Hello World! to the screen. 1.2. Modify the program so that it accepts a string from the user and displays it to the screen. 1.3. Modify the program so that the string is displayed 3 times, first in blue, second in red and third in green. IF / Decide 2.1. Write a program that accepts a number from the user. If the number is greater than 10 display the message Number is greater than 10 Otherwise display the message Number is less than or equal to 10. 2.2. Modify the program so that it uses a decide statement and displays different message for each of the following conditions :Number is less than 10. Number equals 10. Number is greater than 10. For / Repeat 3.1. Write a program that will display the numbers 1 to 10 to the screen using a for loop. 3.2. Modify the program so that it will display the numbers 10 to 1 to the screen using a for loop. 3.3. Modify the program so that it uses a repeat loop to display the numbers 1 to 10, use a until condition to exit the loop when the counter equals 10. 3.4. Modify the program so that it uses a repeat loop to display the numbers 1 to 10, use a while condition to exit the loop when the counter equals 10. Find 4.1. Write a program to find the number of records in the view AWTRN-VEHICLES and display the result to the screen. 4.2. Modify the program so that it finds 20 records from the view AWTRN-VEHICLES. Make sure you limit the search to 20 otherwise you will spend the next 15 minutes scrolling through records as there are over 1000. For each record display the REG_NUM and MODEL. 4.3. Modify the program so that the data is sorted in descending order. 4.4. Modify the program so that it accepts a REG_NUM from the user and displays the record matching that REG_NUM. Type the command l v AWTRN-VEHICLES on the command line to find out the data type for the REG_NUM field. Remember to limit the search to 1 as there will only be one matching record. 4.5. Modify the program so that it incorporates an IF NO RECORDS FOUND condition, and display an error message within the statement. 4.6. Modify the program so that it will display the owners employee details along with the vehicle details. The view for employees is AWTRN-EMPLOYEES. PERSONNEL_ID on the vehicle view should be used as a foreign key. Again use an IF NO RECORDS FOUND condition. Compute / Escape 5.1. Write a program that will prompt for the user to enter a number. The number should then be added to a running total, and the program should loop adding all numbers and displaying the running total until the user enters 0. At this point the running total should be displayed before the program ends. Assign / Store / End Transaction 6.1. Write a program that will add a record to the view AWTRN-VEHICLES with REG_NUM equal to your initials succeeded by a 1. If for example your initials were TCG the REG_NUM should equal TCG1. Prompt the user to enter the records details and also check to see if a record already exists with that REG_NUM. Fill in the record details as you wish, and add the record to the view. Update

2.

3.

4.

5.

6.

7.

Mainframe & Natural Documentation.doc 49e

Page 48 /

Mainframe & Natural Training Documentation

7.1. Write a program that will search for the vehicle record created in 6.1 and display it to the screen. If the record is not found, an error message should be displayed to the screen. 7.2. Modify the program so that it will allow you to modify the colour field. The program should display an Are you sure? prompt before saving the data. You should use Update and End Transaction. Remember Screen I/O has the same effect as an End Transaction being issued. 8. Delete 8.1. Write a program that will delete the record created in 6.1. The program should display an Are you sure? prompt before completing the action. Sub-programs 9.1. Write a sub-program that accepts 2 parameters and returns 1. It should accept 2 numbers of data type N2 and return 1 with the data type N3. The numbers are to be added and returned as the third parameter. 9.2. Write a sub-program that accepts 2 parameters and returns 1. It should accept 2 numbers of data type N2 and return 1 with data type N3. The numbers should be subtracted and returned as the third parameter. 9.3. Write a program that will accepts two numbers as input and store them in separate variables. The program should then prompt the user to enter whether they wish to add or subtract the numbers. Depending on which option is chosen, the appropriate sub-program written above should be called to perform the calculations.

9.

10. Maps 10.1. Create new program TE_ 10P. This program will use a map ( TE_ _10M ) to input a number between 1 and 26. The program will then return the equivalent letter (i.e. user enters 1, program returns A and so on). Remember standard colours and map names. 11. PF-KEYS / Maps / Control Variables 11.1. Create a map to display the registration number, make, model and colour of a vehicle from the view AWTRN-VEHICLES. Write a program, which will displays the first record in the view AWTRN-VEHICLES, ordered by REG_NUM. When the user presses enter the next record should be displayed, and the program should loop performing this function. PF3 should exit the program. 11.2. Modify the program and map so that it displays the owner of the vehicles details on the screen (AWTRN-EMPLOYEES). You will need to use the field PERSONNEL_ID as a foreign key to link to the AWTRN-EMPLOYEES view. Display the PERSONNEL_ID, NAME, FIRST NAME and COUNTRY along with the existing vehicle details. 11.3. Allow users to scroll forward using the enter key or PF8 and scroll backward using PF7. 11.4. Place a field on the map called #action. The allowable actions should be First, Previous, Next and Last. If anything other than these is entered input a suitable error message to the screen. If the action field is empty and enter is pressed another error message should be displayed. Create a control variable for this field called #action-cv and make it Green and underlined. 11.5. Modify the map so it has another field called #REG-NUM-CRITERIA. If the user tabs to this field and enters a registration number, the program should search the views for that REG_NUM and display it if it exists, otherwise an error message should be displayed.

Mainframe & Natural Documentation.doc 49e

Page 49 /

You might also like