Natural Construct for New Application Development

This document is intended for programmers who are creating new applications that require the benefits and functionality of object-oriented development for client/server applications. It describes a Natural Construct business object and how to define the business object in Predict. The last section in this document contains a step-by-step example of generating an object maintenance process.

This document covers the following topics:


Natural Construct Business Object

A business object is a group of entities that work together to process a single business function, such as adding an order. When you create a maintenance program using conventional design, the program contains the logic to access and validate data, as well as the user interface code. When you create the program using object-oriented design, the user interface is isolated from the rest of the program code.

The user interface component (dialog) invokes actions (methods) that are implemented by the data access component (data object). Because these components are separate, data is passed back and forth between the dialog and the data object via a communication component. The combination of these components produces a Natural Construct business object.

There are many advantages to separating data access from user interface, such as:

  • Data, logic, and business rules are embedded in one central location.

  • Data objects are reusable. For example, you can use the same data object with an Accounts Payable dialog and a Product Distribution dialog.

  • The data object can be stored on a file server and the dialog can reside on another platform.

The following diagram shows how a Natural Construct business object encapsulates business rules and data access requirements for use with different interfaces:

Business object

To create an object transaction, you must create the modules for the following data object and communication components:

Component Module Required Purpose
Data object   Builds the data access to a data structure.
  Object subprogram Contains all the integrity checks, edit checks, and updates to the database.
Communication   Passes messages and data from the dialog to the data object.
  Parameter data area (object PDA) Contains the database fields that comprise the data object.
  Restricted PDA Contains variables for update logic that checks for intervening updates in the data object. It is passed with the object PDA.

Natural Construct provides a series of models to generate the modules for an object transaction. The following table lists each module and which model to use:

Subcomponent Model
PDA Object-Maint-PDA
Restricted PDA Object-Maint-PDA-R
Object subprogram Object-Maint-Subp
Map Map
Object maintenance dialog program Object-Maint-Dialog
Object maintenance dialog subprogram Object-Maint-Dialog-Subp

Note:
In addition to the Object-Maint models, Natural Construct provides a series of Object-Browse models to generate an object query process. For information, see Object-Browse Models in Natural Construct Generation.

Add a Business Object

Once you decide to use a business object, the next step is to look at the relationships between the files. Certain relationships must exist before you can use the Object-Maint models effectively. The following diagram shows the files used for a maintenance function in the demo system supplied with Natural Construct:

Object relationships

The files in the shaded area represent the business object, Order. These files have intra-object relationships. The NCST-CUSTOMER, NCST-WAREHOUSE, and NCST-PRODUCT files are not part of the Order object, but they do have inter-object relationships with the NCST-ORDER files.

The metadata stored in Predict provides Natural Construct with the information it needs to create data areas and generate a working program. When generating the components of an object transaction, Natural Construct not only uses the file information in Predict to build views, but it also builds referential integrity and verification rules based on the relationship metadata between the files.

When coding a maintenance program that maintains two or more files, you need to understand the file relationships and decide whether a modification of the business object (for example, the adding, deleting, or modifying of an order) will affect the secondary and/or tertiary files.

When you use the Object-Maint models to generate the program, you only specify the primary file; Natural Construct uses the Predict metadata to identify all other files that belong to the business object and all the maintenance logic required to access the data. To ensure data integrity, the primary file must contain a unique primary key field (either a descriptor or a superdescriptor) and a timestamp field.

For more information about the file views and relationships in Predict, see Object-Maint Models in Natural Construct Generation.

File Relationships Within Objects

To include files within a business object, you must verify that an intra-object relationship exists between the files and that it has been documented in Predict as type "N" (Natural Construct). Intra-object relationships relate the files within an object, since they define the object within the overall file structure.

Files have intra-object relationships if:

  • They have an upper cardinality of (1:1) and a lower cardinality of (0 or 1:N).

  • Always behave in a cascading delete fashion.

  • Each contain a key that relates the parent file to the child file.

NCST-ORDER-HEADER and NCST-ORDER-LINES meet these requirements since:

  • Every order header must have at least one order line.

  • When an order is deleted, the order lines should also be deleted.

  • NCST-ORDER-LINES has a key called ORDER-LINE-KEY that is made up of ORDER-NUMBER (a key field from NCST-ORDER-HEADER) and LINE-NUMBER (the suffix portion of the key).

Once you determine that intra-object relationships exist, define the relationship in Predict. All files used to define the relationships form a single object. From a Predict point of view, the object has already been created since Predict only describes the application's data needs and technical details required to implement the object.

File Relationships Between Objects

The cardinality between files is identified by inter-object relationships. All inter-object relationships with a business object must have a restricted delete and update constraint type. For example, in the above diagram, the NCST-CUSTOMER, NCST-WAREHOUSE, and NCST-PRODUCT files must have a restricted delete and update constraint type. You would not want actions (such as delete) to affect these files.

Application Design

After the files have been documented in Predict, you're ready to create the business object from a Natural Construct point of view. For the object maintenance process example, intra-object relationships exist between the NCST-ORDER-HEADER, NCST-ORDER-LINES, and NCST-ORDER-DISTRIBUTION files and inter-object relationships exist between the Order object and the NCST-CUSTOMER, NCST-WAREHOUSE, and NCST-PRODUCT files.

The following diagram shows the modules required to create an object maintenance process:

Modules for object maintenance

Generate a Business Object

In this section, you'll generate a business object to maintain customer orders. It is assumed that the required demo modules and Predict relationships are installed.

Note:
Before beginning the procedure, ensure that the required modules have been copied to the current library. For a list of modules, see Before You Begin.

Start of instruction setTo create an object maintenance process

  1. Generate the object maintenance subprogram, which automatically generates the object PDA and restricted object PDA.

  2. Generate the external map.

  3. Generate the object maintenance dialog.

    The components must be generated in this order as the specifications for the object maintenance dialog require the names of an existing map, object maintenance subprogram, object PDA, and restricted object PDA.

    In the following sections, you'll generate the object maintenance subprogram and dialog for an order maintenance function. The external map is one of the demo system modules you copied into your library in Introduction to Natural Construct.

Generating the Object Maintenance Subprogram

Start of instruction setTo generate the object maintenance subprogram

  1. Enter "ncstg" at the Natural prompt. The Generation main menu is displayed.

  2. Enter "C" in the Function field. This clears the edit buffer.

  3. Specify the following:

    M Function field
    MYORDSUB Module field
  4. Press Enter. Because you didn't specify a model name, Natural Construct displays the Select Model window.

  5. Enter "O" in the Model field. This repositions the list of models to model names beginning with "O".

  6. Select "Object-Maint-Subp".

  7. Press Enter. The Standard Parameters panel is displayed:

    CUOBMA                   OBJECT-MAINT-SUBP Subprogram                  CUOBMA0 
    Oct 22                       Standard Parameters                        1 of 2 
    
     Module ............. MYORDSUB                                                 
     System ............. MYLIB___________________________                         
    
     Title .............. Object ....______________                                
     Description ........ This subprogram is used to perform object maintenance__  
                           for..._________________________________________________  
                           _______________________________________________________  
                           _______________________________________________________  
    
     Message numbers .... _                                                        
    
    
    
    
    
    
    
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
    right help  retrn quit                                            right main
  8. Specify the following:

    Order Maintenance Subprog Title field
    ... the Order business object Description field
  9. Press Enter. The Additional Parameters panel is displayed:

    CUOBMB                   OBJECT-MAINT-SUBP Subprogram                  CUOBMB0 
    Oct 22                      Additional Parameters                       2 of 2 
    
       Predict view ............. ________________________________ *               
       Primary key .............. ________________________________ *               
       Hold field ............... ________________________________ *               
    
       Object description ....... ____________________                             
    
                                               Generate   Source     Object        
       Object PDA ............... MYORMSA_ *       X                               
       Restricted PDA ........... MYORMSR_ *       X                               
       Object name .............. MYORMSA_________________________                 
    
       Next action prefix ....... _                                                
       Log file suffix .......... ________                                         
       Trace relationships ...... _                                                
    
    
    
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
    main  help  retrn quit                                      left  userX main
  10. Specify the following:

    NCST-ORDER-HEADER Predict view field
    ORDER-NUMBER Primary key field
    ORDER-TIMESTAMP Hold field

    Tip:
    As indicated by the asterisk (*), these fields have selection help available. To display the selection window, either type "?" and press Enter or press PF1 (help) when the cursor is in the field.

  11. Type "Order" in the Object description field. Application messages will be displayed as "Order has been added" or "Order has been updated".

    Note:
    Because the object PDA and restricted PDA do not exist, Natural Construct will automatically name and generate these modules. It determines their names based on the object maintenance subprogram name. For information, see Object-Maint Models in Natural Construct Generation.

  12. Type "Order" over "MYORMSA" displayed in the Object name field.

  13. Press Enter. You are returned to the Generation main menu.

  14. Enter "G" in the Function field. A confirmation message is displayed, indicating that the subprogram has been generated. For more information, see Generate Source Function in Natural Construct Generation.

  15. Enter "W" in the Function field. A confirmation message is displayed, indicating that the subprogram has been stowed. For more information, see Stow Generated Source Function in Natural Construct Generation.

    Next, you'll list the objects in your library to see how many modules have been created.

  16. Enter "L" in the Function field. The Select Module window is displayed:

    CSGLIST                   Natural Construct                   CSGLIST0 
    Dec 03                      Select Module                       1 of 1 
    
      Module                Model                        Title             
    ---------- -------------------------------- -------------------------  
    MYORDSUB   OBJECT-MAINT-SUBP                Order Maintenance Subprog  
    MYORMSA    OBJECT-MAINT-PDA                                            
    MYORMSR    OBJECT-MAINT-PDA-R                                          
    SUPRDREW   VB-CLIENT-SERVER-SUPER-MODEL     Super Spec for...          
    VB-DREW    VB-CLIENT-SERVER-SUPER-MODEL     Super Spec for...          
    VEHLBCPV   VB-BROWSE-OBJECT                 VB Browse Object ...       
    VEHLBSO    OBJECT-BROWSE-SUBP               Object Browse ...          
    VEHLBSP    SUBPROGRAM-PROXY                 Subprogram proxy for...    
    VEHLMCDV   VB-MAINT-DIALOG                  Object Dialog...           
    VEHLMCPV   VB-MAINT-OBJECT                  Visual Basic Maint Object  
    VEHLMSA    OBJECT-MAINT-PDA                                            
    Module ... ________  Model .... ________________________________       
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11 
          help  retrn                         bkwrd frwrd

    Notice that three modules were generated: the object maintenance subprogram, the object PDA and the restricted object PDA.

  17. Press PF2 (retrn). You are returned to the Generation main menu. Now, you'll regenerate the subprogram and specify trace options.

  18. Enter "M" in the Function field. The Standard Parameters panel is displayed.

  19. Press Enter. The Additional Parameters panel is displayed:

    CUOBMB                   OBJECT-MAINT-SUBP Subprogram                  CUOBMB0 
    Dec 03                      Additional Parameters                       2 of 2 
    
       Predict view ............. NCST-ORDER-HEADER_______________ *               
       Primary key .............. ORDER-NUMBER____________________ *               
       Hold field ............... ORDER-TIMESTAMP_________________ *               
    
       Object description ....... Order_______________                             
    
                                               Generate   Source     Object        
       Object PDA ............... MYORMSA_ *       _      MYLIB      MYLIB         
       Restricted PDA ........... MYORMSR_ *       _      MYLIB      MYLIB         
       Object name .............. Order__________________________                 
    
       Next action prefix ....... _                                                
       Log file suffix .......... ________                                         
       Trace relationships ...... _                                                
    
    
    
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
    main  help  retrn quit                                      left  userX main

    Notice that the parameter data areas are not being generated by default.

  20. Mark the Trace relationships field.

  21. Press Enter. You are returned to the Generation main menu.

  22. Enter "G" in the Function field. Because you marked the Trace relationships field, Natural Construct displays each Predict relationship and indicates whether it has been accepted as an intra- or inter-object relationship.

    For example, Natural Construct displays the following message for the NCST-ORDER-HAS-LINES relationship between the NCST-ORDER-HEADER and NCST-ORDER-LINES files:

     CUOBGPR4                     Natural Construct                     CUOPGPR0 
     Dec 03              NCST-ORDER-HEADER Relationship Trace             1 of 1 
    
     Relationship ....... NCST-ORDER-HAS-LINES                                   
     Type ............... N                                                      
    
     Cardinality ........ 1  : CN                                                
    
     File 1                                     Minimum    Average    Maximum    
     File ..... NCST-ORDER-HEADER                 1        1.00         1        
     Field .... ORDER-NUMBER                                                     
     File 2                                                                      
     File ..... NCST-ORDER-LINES                           5.00         30       
     Field .... ORDER-LINE-KEY                                                   
     Constraint attribute                                                        
     Update Type .. N                                                            
     Delete Type .. C                                                            
     Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF1 
           help  retrn                                                           
     Relationship accepted as part of object MYORMSA

    This indicates an intra-object relationship between the files and the object is maintained.

  23. Press Enter to display the next relationship.

  24. Press Enter again. The NCST-PRODUCT-ORDER-LINES relationship is displayed:

    CUOBGPR4                     Natural Construct                     CUOPGPR0 
    Dec 03              NCST-ORDER-LINES Relationship Trace              1 of 1 
    
    Relationship ....... NCST-PRODUCT-ORDER-LINES                               
    Type ............... N                                                      
    
    Cardinality ........ 1  : CN                                                
    
    File 1                                     Minimum    Average    Maximum    
    File ..... NCST-PRODUCT                      1        1.00         1        
    Field .... PRODUCT-ID                                                       
    File 2                                                                      
    File ..... NCST-ORDER-LINES                           100.00                
    Field .... ORDER-PRODUCT-ID                                                 
    Constraint attribute                                                        
    Update Type .. R                                                            
    Delete Type .. R                                                            
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF1 
          help  retrn                                                           
    Accepted as object Update Type constraint against foreign file

    This indicates an inter-object relationship between the files and Natural Construct will check to see if the product exists before adding an order line to the order.

  25. Continue pressing Enter until all relationships have been displayed. When generation is completed, a confirmation message is displayed.

  26. Enter "W" in the Function field. A confirmation message is displayed. Your object maintenance subprogram is now regenerated and stowed.

    Tip:
    If your module will not stow, ensure that you changed the object name to Order on the Additional Parameters panel.

    You've successfully created the object maintenance subprogram. To see the code generated by the Object-Maint-Subp model, enter "E" in the Function field.

    Note:
    If you have any problems creating the subprogram, see Troubleshooting and Debugging for possible reasons.

    For more information about the Object-Maint-Subp model, see Object-Maint-Subp Model in Natural Construct Generation.

Supplied External Map

The external map is called "MYMAP" and is one of the modules copied into your library from from the demo library. This map was created using the Map model. For more information, see Map Model in Natural Construct Generation.

Natural Construct provides many variables you can use on your maps. For example, you can use the following variables to define scroll regions on a map:

Variable Purpose
#LIN (P3) Output field that identifies the array occurrences. The upper bounds value for this variable must match the upper bounds value for the largest array.
#NEXT-ARRAYn (P3) Modifiable field that allows the user to specify which occurrence appears at the top of the display area.
#ARRAYn (N7) Starting index for all the fields from the secondary file.

For a complete list of the variables you can use on a maintenance map, see Variables You Can Use with Object-Maint-Dialog Model Maps in Natural Construct Generation.

Generating the Object Maintenance Dialog

Start of instruction setTo generate the object maintenance dialog

  1. Enter "C" in the Function field on the Generation main menu. This clears the specifications from the previous generation.

  2. Specify the following:

    M Function field
    MYORDDIA Module field
    Object-Maint-Dialog Model field
  3. Press Enter. The Standard Parameters panel is displayed:

    CUOMMA                   OBJECT-MAINT-DIALOG Program                   CU--MA0 
    Oct 22                       Standard Parameters                        1 of 4 
    
     Module ............. MYORDDIA                                                 
     System ............. MYLIB___________________________                         
     Global data area ... CDGDA___                                                 
     With block ......... ________________________________                         
    
     Title .............. Object Dialog..._________                                
     Description ........ This program is used to maintain the...________________  
                          _______________________________________________________  
                          _______________________________________________________  
                          _______________________________________________________  
    
     First heading ...... ________________________________________________         
     Second heading ..... ______________________________________________________   
    
     Command ............ _                                                        
     Message numbers .... _                                                        
     Password ........... _                                                        
    
     Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
     right help  retrn quit                                            right main
  4. Specify the following:

    NCGDA Global data area field
    Order Maintenance Dialog Title field
    ... Order business object Description field
    Order Entry System First header field
    Maintain Customer Orders Second header field
  5. Press Enter. The Additional Parameters panel is displayed:

    CUOMMB                   OBJECT-MAINT-DIALOG Program                   CUOMMB0 
    Oct 22                      Additional Parameters                       2 of 4 
    
    
       Object maint subprogram .. ________ *                                       
    
       #ACTION field length ..... 1  Add ...... X  Browse ... ________ *           
                                     Clear .... X  Display .. X                    
                                     Modify ... X  Next ..... X                    
                                     Purge .... X  Former ... _                    
    
       Window support ........... _                                                
       Push-button support ...... _                                                
       Mark cursor field ........ ________________________________________________ 
    
    
    
    
    
    
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
          help  retrn quit        windw                         left  right main
  6. Select "MYORDSUB" from the Object maint subprogram field. This is the name of the object maintenance subprogram you created.

    Note:
    By default, the Add, Clear, Display, Modify, Next, and Purge actions are selected. These are the actions the program will allow.

  7. Type "2" over "1" displayed in the #ACTION field length field. You change the length because the action field on MYMAP is two characters long.

  8. Mark the Push-button support field. This allows users to select actions by cursor on the generated screen.

  9. Press Enter. The Scroll Region Parameters panel is displayed:

    CUOMMC                   OBJECT-MAINT-DIALOG Program                   CUOMMC0 
    Oct 22                     Scroll Region Parameters                     3 of 4 
    
    
       Horizontal panels ................. 1                                       
    
       >> 1 Input using map .............. ________ *                              
    
            Scrollable Regions              1        2        3        4           
            Total occurrences ............  _____    _____    _____    _____       
            Screen occurrences ...........  ___      ___      ___      ___         
            Starting from ................ #ARRAY1  #ARRAY2  #ARRAY3  #ARRAY4      
            Scroll with panel ............   _        _        _        _          
    
            Top left ...... Line .........  ___      ___      ___      ___         
                            Column .......  ___      ___      ___      ___         
            Bottom right .. Line .........  ___      ___      ___      ___         
                            Column .......  ___      ___      ___      ___         
    
            Depth occurrences ............ ___                                     
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
          help  retrn quit        deflt       bkwrd frwrd       left  right main
  10. Select "MYMAP" from the Input using map field.

  11. Press PF5 (deflt). Natural Construct reads the map and retrieves information about the arrays and scroll regions:

    CUOMMC                   OBJECT-MAINT-DIALOG Program                   CUOMMC0 
    Oct 22                     Scroll Region Parameters                     3 of 4 
    
    
       Horizontal panels ................. 1                                       
    
       >> 1 Input using map .............. MYMAP *                                 
    
            Scrollable Regions              1        2        3        4           
            Total occurrences ............  30___    10___    20___    _____       
            Screen occurrences ...........  1__      4__      2__      ___         
            Starting from ................ #ARRAY1  #ARRAY2  #ARRAY3  #ARRAY4      
            Scroll with panel ............   _        _        _        _          
    
            Top left ...... Line .........  10_      10_      16_      ___         
                            Column .......  2__      45_      2__      ___         
            Bottom right .. Line .........  15_      15_      18_      ___         
                            Column .......  70_      70_      64_      ___         
    
            Depth occurrences ............ ___                                     
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
          help  retrn quit        deflt       bkwrd frwrd       left  right main   
    Scroll parameters read from MYMAP map successfully
  12. Press Enter. The Related File Parameters panel is displayed. As Natural Construct does not require access to other files, you don't need to specify information on this panel.

  13. Press Enter again. You are returned to the Generation main menu.

  14. Enter "G" in the Function field.

  15. Enter "W" in the Function field. Your maintenance dialog is now generated and stowed.

    To see the code generated by the Object-Maint-Dialog model, enter "E" in the Function field. To see what the panel will look like to users, enter "T" in the Function field:

     Add        Clear      Display    Modify     Next       Purge                  
    
    MYORDDIA                ***** Order Entry System *****               MYMAP     
    Oct 25,01                - Maintain Customer Orders -              9:00 PM     
     Action...........: __                                                         
     Order Number.....: ______   Invoice Number.....: ______                       
     Customer Number..: _____                                                      
     Warehouse ID.....: ___                                                        
     Order Date.......:          Order Amount:                                     
     1_ ----- Product Information ------        1_ Distribution Information        
      1 *Product....: ______             /\          Account     Amount            
         Quantity...: _________                  1  _________ ____________ /\      
         Cost/Unit..:                            2  _________ ____________         
         Total......:                            3  _________ ____________         
         Description:                    \/      4  _________ ____________ \/      
     1_ Delivery Instructions (Scroll right for full screen)                       
      1                                                              /\            
      2                                                              \/            
    
    
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
    confm help  retrn quit        flip  pref  bkwrd frwrd                   main
  16. Press PF2 (retrn). You are returned to the Generation main menu.

    You've successfully created the object maintenance dialog, but there are no business rules or validation edits. You can add this logic in the UPDATE-EDITS user exit for the object maintenance subprogram (the MYORDSUB module). The following section describes how to do this.

    Note:
    If you have any problems creating the dialog, see Troubleshooting and Debugging for possible reasons.

    For more information, see Object-Maint-Dialog Model in Natural Construct Generation.

Adding Business Rules and Validation Edits

Start of instruction setTo add business rules and validation edits

  1. Enter "C" in the Function field on the Generation main menu.

  2. Specify the following:

    R Function field
    MYORDSUB Module field
  3. Press Enter. Natural Construct reads the object maintenance subprogram into the edit buffer.

  4. Enter "U" in the Function field. Because you marked the Trace relationships field when you created MYORDSUB, the relationship windows are displayed. Continue pressing Enter until all relationships have been shown and the User Exits panel is displayed:

    CSGSAMPL                      NATURAL CONSTRUCT                         CSGSM0 
    Oct 22                            User Exits                            1 of 1 
    
                   User Exit              Exists    Sample   Required Conditional  
        -------------------------------- -------- ---------- -------- ------------ 
     _  CHANGE-HISTORY                            Subprogram                       
     _  PARAMETER-DATA                             Example                         
     _  EXTENDED-RI-VIEWS                                                          
     _  LOCAL-DATA                                 Example                         
     _  START-OF-PROGRAM                           Example                         
     _  SELECT-STATEMENT                          Subprogram               X       
     _  USER-DEFINED-FUNCTIONS                     Example                         
     _  BEFORE-ET-PROCESSING                       Example                         
     _  AFTER-ET-PROCESSING                        Example                         
     _  END-OF-PROGRAM                             Example                         
     _  AFTER-GET                                  Example                         
     _  AFTER-INIT                                 Example                         
     _  UPDATE-EDITS                              Subprogram                       
     _  DELETE-EDITS                              Subprogram                       
     _  AFTER-GET-EDITS                           Subprogram                       
     _  EXTENDED-RI-CHECKS                        Subprogram                       
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
    frwrd help  retrn quit                    bkwrd frwrd
  5. Mark the UPDATE-EDITS user exit.

  6. Press Enter twice. The UPDATE-EDITS Build Subroutine window is displayed:

    CUOBGS                      Natural Construct                      CUOBGS0  
    Oct 22                UPDATE-EDITS Build Subroutine                 1 of 1  
    
       File name                                                                
    ------------------------------------                                        
     _ NCST-ORDER-HEADER                                                        
     _ NCST-ORDER-LINES                                                         
     _ NCST-ORDER-DISTRIBUTION                                                  
    
    
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF  
          help  retrn

    Natural Construct provides validation subroutines that execute edit checks at different points during the processing of an entity.

  7. Mark NCST-ORDER-HEADER.

  8. Press Enter. The default code is displayed in the User Exit editor:

    0010 DEFINE EXIT UPDATE-EDITS                                                
    0020 *                                                                       
    0030 * Specify subroutines of the form V0-entity-name (or V1- or V2-) used   
    0040 * to validate or manipulate data before an UPDATE/STORE operation which 
    0050 * move data from the object to the entity-name record. Data manipulation
    0060 * must be made against the record. If any reference to the object is    
    0070 * required because the relevant fields have different names on the      
    0080 * object and the file, appropriate indices (#L2),(#L2,#L3),(#L2,#L3,#L4)
    0090 * should be used. The V2- routine is performed for an entity after all  
    0100 * of its children's processing while the V0-/V1- are invoked before     
    0110 * its children's, and before/after its PREDICT rules respectively.      
    0120 *                                                                       
    0130 ************************************************************************
    0140 DEFINE SUBROUTINE V0-NCST-ORDER-HEADER                                  
    0150 ************************************************************************
    0160 *                                                                       
    0170 * Insert code which is necessary to validate/manipulate the data from   
    0180 * NCST-ORDER-HEADER record before an update/store operation,            
    0190 * before its children's processing and before its PREDICT rules if any. 
    0200 *                                                                       
    0210 DECIDE FOR FIRST CONDITION                                              
    0220   WHEN NCST-ORDER-HEADER.ORDER-NUMBER EQ 0                              
    0230     ASSIGN MSG-INFO.##MSG = ' :1: is required'                          
    0240     ASSIGN MSG-INFO.##MSG-DATA(1) = 'Order Number'                      
    0250     ASSIGN MSG-INFO.##ERROR-FIELD = 'ORDER-NUMBER'                      
    0260   WHEN NCST-ORDER-HEADER.ORDER-AMOUNT EQ 0                              
    0270     ASSIGN MSG-INFO.##MSG = ' :1: is required'                          
    0280     ASSIGN MSG-INFO.##MSG-DATA(1) = 'Order Amount'                      
    0290     ASSIGN MSG-INFO.##ERROR-FIELD = 'ORDER-AMOUNT'                      
    0300   WHEN NCST-ORDER-HEADER.ORDER-DATE EQ 0                                
    0310     ASSIGN MSG-INFO.##MSG = ' :1: is required'                          
    0320     ASSIGN MSG-INFO.##MSG-DATA(1) = 'Order Date'                        
    0330     ASSIGN MSG-INFO.##ERROR-FIELD = 'ORDER-DATE'                        
    0340   WHEN NCST-ORDER-HEADER.ORDER-CUSTOMER-NUMBER EQ 0                     
    0350     ASSIGN MSG-INFO.##MSG = ' :1: is required'                          
    0360     ASSIGN MSG-INFO.##MSG-DATA(1) = 'Customer Number'                   
    0370     ASSIGN MSG-INFO.##ERROR-FIELD = 'ORDER-CUSTOMER-NUMBER'             
    0380   WHEN NCST-ORDER-HEADER.ORDER-WAREHOUSE-ID EQ ' '                      
    0390     ASSIGN MSG-INFO.##MSG = ' :1: is required'                          
    0400     ASSIGN MSG-INFO.##MSG-DATA(1) = 'Warehouse ID'                      
    0410     ASSIGN MSG-INFO.##ERROR-FIELD = 'ORDER-WAREHOUSE-ID'                
    0420   WHEN NCST-ORDER-HEADER.INVOICE-NUMBER EQ 0                            
    0430     ASSIGN MSG-INFO.##MSG = ' :1: is required'                          
    0440     ASSIGN MSG-INFO.##MSG-DATA(1) = 'Invoice Number'                    
    0450     ASSIGN MSG-INFO.##ERROR-FIELD = 'INVOICE-NUMBER'                    
    0460   WHEN NCST-ORDER-HEADER.DELIVERY-INSTRUCTIONS(*) EQ ' '                
    0470     ASSIGN MSG-INFO.##MSG = ' :1: is required'                          
    0480     ASSIGN MSG-INFO.##MSG-DATA(1) = 'Delivery Instructions'             
    0490     ASSIGN MSG-INFO.##ERROR-FIELD = 'DELIVERY-INSTRUCTIONS'             
    0500     ASSIGN MSG-INFO.##ERROR-FIELD-INDEX1 = 1                            
    0510   WHEN ANY                                                              
    0520     ESCAPE ROUTINE                                                      
    0530   WHEN NONE                                                             
    0540     IGNORE                                                              
    0550 END-DECIDE                                                              
    0560 END-SUBROUTINE /* V0-NCST-ORDER-HEADER                                  
    0570 *                                                                       
    0580 ************************************************************************
    0590 DEFINE SUBROUTINE V1-NCST-ORDER-HEADER                                  
    0600 ************************************************************************
    0610 *                                                                       
    0620 * Insert code which is necessary to validate/manipulate the data from   
    0630 * NCST-ORDER-HEADER record before an update/store operation,            
    0640 * before its children's processing and after its PREDICT rules if any.  
    0650 *                                                                       
    0660   ESCAPE ROUTINE                                                        
    0670 END-SUBROUTINE /* V1-NCST-ORDER-HEADER                                  
    0680 *                                                                       
    0690 ************************************************************************
    0700 DEFINE SUBROUTINE V2-NCST-ORDER-HEADER                                  
    0710 ************************************************************************
    0720 *                                                                       
    0730 * Insert code which is necessary to validate/manipulate the data from   
    0740 * NCST-ORDER-HEADER record before an update/store operation             
    0750 * after all of its children have been processed.                        
    0760 *                                                                       
    0770   ESCAPE ROUTINE                                                        
    0780 END-SUBROUTINE /* V2-NCST-ORDER-HEADER                                  
    0790 END-EXIT

    For this example, you need only ensure that the order number and amount are not zero.

  9. In the DEFINE SUBROUTINE V0-NCST-ORDER-HEADER section, delete the conditions for the order date, order customer number, order warehouse ID, invoice number, and delivery instructions (lines 300 to 500 of the default code).

  10. Type "." on the command line in the User Exit editor.

  11. Press Enter. You are returned to the Generation main menu.

  12. Enter "G" in the Function field.

  13. Enter "W" in the Function field. Your object maintenance subprogram is now generated and stowed.

    You've successfully added business rules and validation edits to your object maintenance subprogram. The following section describes how to execute the Maintain Customer Orders function you've created.

Executing the Program

Up to this point, you've executed programs using the Test Source function on the Generation main menu. You can also execute Natural Construct-generated programs as you do any Natural program from the command line.

Start of instruction setTo execute the Maintain Customer Orders function

  1. Type "MYORDDIA" on the Natural command line.

  2. Press Enter. The Maintain Customer Orders panel is displayed.

  3. Move the cursor to Next.

  4. Press Enter. The order information for the first record is displayed:

     Add        Clear      Display    Modify     Next       Purge                  
    
    MYORDDIA                ***** Order Entry System *****               MYMAP     
    Oct 25                   - Maintain Customer Orders -              9:25 PM     
     Action...........: __                                                         
     Order Number.....: 122___   Invoice Number.....: 999___                       
     Customer Number..: 22266                                                      
     Warehouse ID.....: 544                                                        
     Order Date.......: 99/08/12 Order Amount: 10880.00                            
     1_ ----- Product Information ------        1_ Distribution Information        
      1 *Product....: 187361             /\          Account     Amount            
         Quantity...: 444______                  1  _________ ____________ /\      
         Cost/Unit..:      20.00                 2  _________ ____________         
         Total......:      8880.00               3  _________ ____________         
         Description: Fish Sticks        \/      4  _________ ____________ \/      
     1_ Delivery Instructions (Scroll right for full screen)                       
      1                                                              /\            
      2                                                              \/            
    
    
    
    Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
    confm help  retrn quit        flip  pref  bkwrd frwrd                   main

    You've successfully executed the Maintain Customer Orders function from the Natural command line. To test the edits, try adding an order with an order number or amount of zero and see if an error message is displayed.

    Note:
    If you have any problems executing the program, see Troubleshooting and Debugging for possible reasons.