Processing Rules and Helproutines

Processing rules and helproutines are defined for fields in a map.

When you have completed the exercises below, your sample application will consist of the following modules (a processing rule cannot be defined as a separate module; it is always part of a map):

Application structure

This document contains the following exercises:


Defining a Processing Rule

You will now define the message that is to be displayed when the user presses ENTER without specifying a starting name.

Start of instruction setTo define a processing rule

  1. Return to the map editor by entering the following.

    EDIT MAP01
  2. Use the arrow keys to select the input field for the starting name. Press ESC to redisplay the menu and choose Modify.

    The Extended Field Editing window appears.

    +-Extended Field Editing-------------------------------------------------------+
    ¦Field : #NAME-START                                                           ¦
    ¦Format: A Len: 20         AL: 20          PM:                  ZP: N  SG: N   ¦
    ¦Rules : 0 Rule Editing: N Array: None     Array Editing: N     Mode:  User    ¦
    ¦AD: ILMFHT'_'  CD:        CV:                                  DY: N  HE: N   ¦
    ¦EM:                                                                           ¦
    +------------------------------------------------------------------------------+
  3. Use TAB to move to the field Rule Editing. Either enter "Y" in this field or press PF2.

    The following screen appears.

    +-Current Field: #NAME-START---------------------------------------------------+
    ¦                      R U L E   E D I T I N G (Esc = Quit)                    ¦
    ¦Rules                                   Fields                                ¦
    +------------------------------------------------------------------------------+
                                                                                    
                               End XXXXXXXXXXXXXXXXXXXX                             
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
     Create or modify a rule for this field
  4. Choose Rules and then <CREATE>.

    An empty editor window appears.

  5. Enter the following processing rule (use the line command I to insert blank lines):

    IF & = ' ' THEN
      REINPUT 'Please enter a starting name.'
      MARK *&
    END-IF

    The ampersand (&) in the processing rule will dynamically be replaced with the name of the field. In this case, it will be replaced with #NAME-START. If #NAME-START is blank, the message defined with the REINPUT statement is displayed.

    MARK is an option of the REINPUT statement. Its syntax is MARK *fieldname. MARK specifies the field in which the cursor is to be placed when the REINPUT statement is executed. In this case, the cursor will be placed in the #NAME-START field.

  6. Enter the following in the command line:

    P=1

    The rank defines the sequence in which the rules for the different fields are to be processed. All rules with rank 1 are processed first, followed by those with rank 2, etc.

    EDIT:                                     S 02- ---------------Columns 001 074  
    Rank:  NEW RULE      Rule:                                      Typ: R  Mode: S 
    Cmnd=> p=1                                                   Scroll==> CSR
    ****** ******************************* top of data *****************************
    000001 IF & = ' ' THEN                                                          
    000002   REINPUT 'PLEASE ENTER A STARTING NAME.'                                
    000003   MARK *&                                                                
    000004 END-IF                                                                   
    ****** ***************************** bottom of data ****************************
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
    PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
    P     U     End   P*    Rfind Rchng Up    Down        Right Left  Home
  7. Press ENTER to save your input.

    The following screen appears again. Your new rule with the rank 1 is now shown below <CREATE>. When you select this rule, the first lines of your code are shown at the bottom of the screen.

    +-Current Field: #NAME-START---------------------------------------------------+
    ¦                      R U L E   E D I T I N G (Esc = Quit)                    ¦
    ¦Rules                                   Fields                                ¦
    +--------+---------------------------------------------------------------------+
    ¦<CREATE>¦                                                                      
    ¦       1¦             End XXXXXXXXXXXXXXXXXXXX                                 
    +--------+                                                                      
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
    0010 IF & = ' ' THEN                                                            
    0020   REINPUT 'PLEASE ENTER A STARTING NAME.'                                  
    0030   MARK *&                                                                  
                                                                                    
     Create or modify a rule for this field
  8. Press ESC repeatedly until the Natural Map Editor menu is shown again.

  9. Test the map.

  10. In the resulting output, enter any starting name and press ENTER.

    The output screen is closed.

  11. Test the map once more. Do not enter a name and press ENTER.

    The message defined with the processing rule should now appear in the map.

  12. To leave the output screen, enter a dot (.) in the field which prompts for a starting name and press ENTER.

  13. Stow the map.

Defining a Helproutine

A helproutine is displayed when the user presses the help key when the cursor is on the input field for the starting name.

You will first define the helproutine and then associate it with a specific field.

Start of instruction setTo create a helproutine

  1. From the Natural Map Editor menu, choose Quit.

    Natural's main menu is shown again with the Direct Command window prompting for input.

  2. Enter one of the following:

    EDIT PROGRAM
    E P

    An empty editor appears.

  3. Enter the following:

    WRITE 'Type the name of an employee'
    END
  4. Change the program to a helproutine by entering the following in the program editor's command line:

    SET TYPE H

    where "H" denotes helproutine.

  5. Stow the helproutine and name it HLP01.

    STOW HLP01

Start of instruction setTo associate the helproutine with a field on the map

  1. Return to the map editor by entering the following in the command line of the screen in which you have just entered the helproutine.

    E MAP01
  2. Select the data field for the starting name, press ESC to display the Natural Map Editor menu and choose Modify.

    The Extended Field Editing window is displayed for the field.

  3. Use TAB to move to the field HE. Either enter "Y" in this field or press PF2.

    A window appears prompting for the name of the helproutine.

  4. In the HE field enter "'HLP01'" (including the single quotation marks).

    This is the name under which you have saved your helproutine.

    XXXXXXXXXX                                                           TT:TT:TT   
                                                                                    
                                                                                    
                             Start XXXXXXXXXXXXXXXXXXXX                             
                                                                                    
                               End XXXXXXXXXXXXXXXXXXXX                             
                                                                                    
                                                                                    
                                                                                    
                                                                                    
         +-HE-----------------------------------------------------------------+     
         ¦HE: 'HLP01'                                                         ¦     
         ¦                                                                    ¦     
         +--------------------------------------------------------------------+     
                                                                                    
    +-Extended Field Editing-------------------------------------------------------+
    ¦Field : #NAME-START                                                           ¦
    ¦Format: A Len: 20         AL: 20          PM:                  ZP: N  SG: N   ¦
    ¦Rules : 1 Rule Editing: Y Array: None     Array Editing: N     Mode:  User    ¦
    ¦AD: MILFHT'_'  CD:        CV:                                  DY: N  HE: Y   ¦
    ¦EM:                                                                           ¦
    +------------------------------------------------------------------------------+
     Helproutine and Parameters
  5. Press ENTER twice to save your changes and close all windows.

  6. Test the map.

  7. In the resulting output, enter a question mark (?) in the input field for the starting name.

    The help text you have defined is shown.

  8. Press ENTER to return to the map.

  9. To leave the map, enter a dot (.) in the field which prompts for a starting name and press ENTER.

  10. Stow the map.

  11. From the Natural Map Editor menu, choose Quit.

    Natural's main menu is shown again with the Direct Command window prompting for input.

You can now proceed with the next exercises: Local Data Areas.