Since any given program might have several Business Rules inserted (because it updates several Elements), it would be (cont.)
wise to force the work fields you define to be unique so that they do not conflict with other data items in the (cont.)
program. One good standard would be to prefix them with the Element name followed by* two* dashes, (cont.)
i.e:
04 VAD01--WORK-FIELD PIC S9(5).
 
That way you need not worry whether some other data item in the program might have the same name. Data Items in the (cont.)
Element definition always have a prefix of the Element name followed by *one* dash. This scheme will also help (cont.)
programmers to quickly recognize Business Rule work items.
Also keep in mind that these work fields will be in the TWA and will not be part of the VARIABLE-STORAGE area which is (cont.)
always initialized to LOW VALUES; therefore, it will be your responsibility to initialize these areas in your Procedure (cont.)
Division logic, if such initialization is necessary. *The contents of these fields will be unpredictable upon entry to (cont.)
the Business Rule Procedural logic.*
| ```
**
 RULADD  VAD01/RULWORK
SEARCH ARG: ..................................................................
Password: M A G E C VAD01 page
New Password:  ELEMENT DATA RULES  (001)
MAGEC Vacation Dummy data  TAB Option: ON
....+..;10.;..+;..20....+...30....+...40...;+...50....+...60....+...70..
-ifunique  01
-magecinc sif01-c  02
  03
  04
  05
  06
  07
  08
  09
  10
  11
  12
  13
  14
  15
Move CURSOR to a line, use ERASE EOF to Delete it -or-  PF20 to Insert After it
Semicolon (;) is the TAB Character Asterisk (*) in col. 1 = suppress upcase
  Press PF4 for Menu of Named Proformas
```**
Figure 21 -- Business Rule Data Definition Code
Next you will add the Procedure Division code for your Business Rule, as indicated by the modifier "RULPROC". Note that (cont.)
the two modifiers, RULWORK and RULPROC, are the only two modifiers allowed for Business Rules. If you omit the modifier (cont.)
MAGEC will default to RULPROC. If you attempt to specify some other modifier, you will receive an error message and be (cont.)
unable to add it to the dictionary.
This logic is calling the MAGEC I/O module to read the SIF01 Element into the SIF01-C copybook (the group data item (cont.)
defining the entire element is named SIF01-ELEMENT). If a NOT-FOUND return code is sensed then it sets the error flag (cont.)
and specifies an error number to be issued. This triggers the MMP logic to bypass the update (or add) of the VAD01 data (cont.)
and to send the screen with an error message instead.
The setting of error message numbers and of the master error flag is identical to the way it is done in the ordinary (cont.)
editing of the screen (in the %EDIT insertion point); except that this logic is not specifically associated to any one (cont.)
single screen or MMP. As a result, you must abide by certain limitation.
**Never** reference any screen field except the four standard fields which are always present on every screen (except (cont.)
that you can reference screen fields using MAGEC's Symbolic Screen Field References described later). They are: SFUNCT, (cont.)
SKEY, SCOMPL, and SERRMSG (and their associated control and attribute fields). In this example we are setting the error (cont.)
flag for the SKEY field (on line one of the screen) so that it will be highlighted.
**Never** PERFORM a paragraph outside of the Business Rule logic, except for the standard routines which are always present in all MMP's.
If you need to insert a paragraph name into your code, use one which will not conflict with others in the various (cont.)
programs in which this logic might be inserted. The easiest way to do that is to establish a standard of using (cont.)
paragraph names which have a prefix of:
BB6nn-eeeee--
 
where:
nn
             
= any two-digit number
eeeee
             
= the Element name for which this logic applies
Note the two dashes after the Element name. This helps avoid conflicts with paragraph names from other Business Rules, (cont.)
programmer's custom coding, and standard MAGEC-generated code. The Business Rules are inserted into the BB600-BUILD-REC (cont.)
routine; hence, the BB6nn prefix.
| ```
**     DO THIS:
Key the command: RULADD VAD01/RULPROC, press ENTER.
   
```**
The screen appears ready for you to key in your code. To save you keystrokes and reduce errors, there is a proforma (cont.)
displayed on the screen. You can overtype all or part of it, using it as a fill-in-the-blanks model. If this proforma (cont.)
is not suitable for what you wish to do, there are many others available. You can press PF4 for a list of them and then (cont.)
cursor-select the one you would like.
| ```
**
RULADD  VAD01/RULPROC
SEARCH ARG: ..................................................................
Password: M A G E C VAD01 page
New Password:  ELEMENT DATA RULES  (001)
MAGEC Vacation Dummy data  TAB Option: ON
.....+..;10.;..+;..20....+...30....+...40...;+...50....+...60....+...70..
  IF ____________________  01
  MOVE '___'  TO ERROR-NUMBER  02
  PERFORM CA100-LOAD-ERR-CODE-TBL THRU CA199-EXIT.  03
  04
  05
  06
  07
  08
  09
  10
  11
  12
  13
  14
  15
Move CURSOR to a line, use ERASE EOF to Delete it -or-  PF20 to Insert After it
Semicolon (;) is the TAB Character Asterisk (*) in col. 1 = suppress upcase
  Press PF4 for Menu of Named Proformas
```**
Figure 22 -- Business Rule Add Screen
| ```
**     DO THIS:
Key in the code as shown below, press ENTER
   
```**
The code you are keying in is the standard call to the MAGEC I/O module. You could refer to the "Database (cont.)
Administration" chapter of the *Programmer's Reference Guide* for more details about calling the I/O module. You will (cont.)
notice that the call to 'MAGECSET' is used to point the I/O module to the SIF01-ELEMENT area to read into. (cont.)
SIF01-ELEMENT is the group item which is in the SIF01-C copybook which was included in the RULWORK (cont.)
code.
Notice, also, that you are setting the 3270 attribute for the SKEY field to high-intensity (line 13 of the code). That (cont.)
is legal in a Business Rule since you can depend on SKEY being present on any MAGEC screen. Screen fields other than (cont.)
the standard MAGEC screen fields (which are on all screens) *must not* be directly referenced in Business Rules. See (cont.)
NOTE2 below for more about referencing screen fields.
The technique of setting an error number and performing the "CA100-" routine is identical to that used in coding custom (cont.)
editing for an MMP. In this example we assume that error number "9XX" is already defined in the dictionary. If it were (cont.)
not, you would need to define it using the function:
ERRADD 9XX
 
You would then enter the short message (33 characters) which is to be displayed at the bottom of the screen, and the (cont.)
4-line narrative explanation which will be presented if the user asks for help by pressing the HELP key. You can use (cont.)
the same error message definitions for your Business Rules as are being used for other types of (cont.)
editing.
**
NOTE1:
**
The Business Rule is also a last chance to modify the data in the element before it is written to the file. This is (cont.)
handy for setting default values into some fields. It also can be a handy place to define the logic used to obtain a (cont.)
unique key for a new record add. This removes from the programmer the burden of coding it (perhaps in several (cont.)
programs), and also gives the database administrator greater control.
**
NOTE2:
**
The code on lines 10 and 11 is using a symbolic reference to a screen field associated with the database field (cont.)
"VAD01-EMPNUM". You should refer to the *Programmer's Reference Guide*, to the "Database Administration" chapter for (cont.)
more information about symbolic screen field references. The -IFEXIST statement renders the symbolic reference (cont.)
conditional. That means that if there is no screen field associated with VAD01-EMPNUM, line 11 will become a comment (cont.)
(asterisk in column 7). If there is a screen field associated with VAD01-EMPNUM then line 11 will move E to its (cont.)
error-flag. In this way you can indirectly reference screen fiields within a Business Rule, even though you do not know (cont.)
what their names will be in the MMP's.
Symbolic references to screen fields may be used by Application Developers in their customization coding, as well as by (cont.)
Database Administrators in coding Business Rules and Referential Integrity Rules They may be used only in coding for (cont.)
online applications -- batch programs do not have screen fields.
| ```
**
 RULADD  VAD01/RULPROC
SEARCH ARG: ..................................................................
Password: M A G E C VAD01 page
New Password:  ELEMENT DATA RULES  (001)
MAGEC Vacation Dummy data  TAB Option: ON
.....+..;10.;..+;..20....+...30....+...40...;+...50....+...60....+...70..
;;move 'sif01';to twa-elt-list.  01
;;move redky;to twa-db-request.  02
;;move 'sifk1';to twa-db-key-name.  03
;;move zero;to sif01-key-prefix.  04
;;move vad01-empnum;to sif01-empnum.  05
;;move sif01-master-key;to twa-key-value.  06
;;call 'magecset' using twa-db-area-a sif01-element.  07
;;perform aa840-call-magec-io thru aa899-exit.  08
;;if (not rec-found)  09
-ifexist  10
;;;move e;to @vad01-empnum@e  11
;;;move '9xx';to error-number  12
;;;move atuadhnm;to skeya  13
;;;perform ca100-load-err-code-tbl thru ca199-exit.  14
  15
 
Move CURSOR to a line, use ERASE EOF to Delete it -or-  PF20 to Insert After it
Semicolon (;) is the TAB Character Asterisk (*) in col. 1 = suppress upcase
  Press PF4 for Menu of Named Proformas
```**
Figure 23 -- Business Rule Procedure Division Code
##
Referential Integrity
The Business Rule processing enables the DBA to ensure the integrity of data content in the database. It also enables (cont.)
him/her to prevent the addition of "subordinate" items (i.e. invoices) unless their "parent" items are defined (i.e. (cont.)
customers). This is important in order to preserve the *referential integrity* of the database. That means that items (cont.)
reference only valid, existing entities, rather than erroneous (non-existing) entities (invalid customer (cont.)
number).
In order to fully defend the referential integrity of the database, one more facility is needed. We must be able to (cont.)
ensure that the parent item (i.e. customer) does not get deleted if there are subordinates (invoices) on file (cont.)
referencing it. Therefore, MAGEC provides another type of rule logic which the DBA can provide, it is called a (cont.)
"Deletion Rule".
Deletion Rules are identified by the word "RULDELT", as compared to the Business Rules identified by the word "RULPROC". They are defined and maintained in exactly the same way.
The RULDELT logic will be inserted into the generated MMP's in the BB400-EDIT-FOR-DELETE paragraph which is performed (cont.)
just prior to the the actual delete operation. Setting the error flag will prevent the delete from taking place, just (cont.)
as it prevents the add or update from taking place in the RULPROC logic.
| ```
**     DO THIS:
Key the command: RULADD VAD01/RULDELT, press ENTER.
   

next: data08.md.txt