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.     ```** The screen will appear ready for you to enter your code. A proforma will be shown on the screen. You can simply alter it to suit your needs. This saves keystrokes and minimizes errors. If you need to add work areas into the Data Division you should use the RULWORK identifier as you would for a Business Rule. | ``` ** RULADD  VAD01/RULDELT 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 24 -- Deletion Rule Add Screen | ``` **     DO THIS: Key in the code shown below, press ENTER.     ```** The error number '91J' should already exist on the MAGEC ERR file. If it does not, you should add it via the command: ERRADD 91J To see if it is already defined you could use the command: ERRSEE 91J   -- if it is on file, it will be displayed to you. The restrictions which applied to Business Rules also apply to Deletion Rules. The only difference between them is where they are inserted in the logic of a generated MMP. | ``` ** RULADD  VAD01/RULDELT 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 vad01-empnum Less than nineteen  01   move '91j'  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 ```** ** NOTE: ** It is not necessary to type the entire Cobol statement above since hte proforma displayed to you strongly resembles it. (cont.) You can simply overkey the portions of the proforma which you need to alter in order to correctly build this Cobol (cont.) statement. The underlines in the proforma help you to see where modifications most likely need to be made to the (cont.) proforma in order to build a correct statement. This gives you a fill-in-the-blanks aid to coding. Figure 25 -- Deletion Rule Logic # Review In the preceeding project you have defined and created a completely new Data Class (a VSAM file, in this example) from (cont.) scratch. The process is the same for any other data you need to define to MAGEC. You can review this tutorial and/or (cont.) the MAGEC "Database Administration" chapter whenever you need to define new files or databases. We defined it in a "top-down" manner as: To define the Data Class:   DCLADD VAD Next: https://magec.com/DOC/markdown/data04.md.txt