...................................................................... 4444444444444444444444444444444444444444444444444444444444444444444444 0000000000000000000000000000000000000000000000000000000000000000000000 ...................................................................... 4444444444444444444444444444444444444444444444444444444444444444444444 0000000000000000000000000000000000000000000000000000000000000000000000 PF23:+280, PF22:-280, PF8:REDNX, PF7:REDPR Access Method is MAGEC/DB ```** ** NOTE: ** This display presumes that your file was intialized with one record having a key of 'XXXXXXXXXXXXXXXXXX'. That may, or (cont.) may not, be true for your installation since different options are available for initializing files. Figure 19 -- DBDITO Screen # Business Rules ## Cross-Field / Cross-File Edits MAGEC provides the means for you to define extended, complex editing of data which can involve multiple data items and (cont.) even cross-file validations. This editing can be defined by the person defining the data to the dictionary and will (cont.) then be automatically inserted into any applications generated which update the data. These edits are called "Business (cont.) Rules". Business Rules are routines coded in Cobol which may be as large as 15,000 lines of Procedure Division code plus 15,000 (cont.) lines of Data Division code. They are associated with an Element. Whenever that Element is added or updated the (cont.) Business Rule logic is invoked. While the primary purpose for coding Business Rules is to validate data before it is (cont.) placed onto the files, there is actually no limitation to what you can do in this logic. It is perfectly legal to do (cont.) I/O, even other updates or adds, in the Business Rule logic. Some examples of what you might do in the Business Rule (cont.) logic are: 1)   Verify that if Employee type is "salaried" and Location is Texas then Salary must be not less than $20,000 and not greater than $80,000.   2)   Concatenate the first three digits of Zip Code with the two-character State code and use the result as a key to access (cont.) the Zip-State cross-reference file to ensure that this is a valid Zip Code within this State.   3)   If processing an "add" function, access the Control File to obtain the next available mod-11 Employee Number and plug it into the key for this new record to be added.   4)   Verify that if the salary of the employee being updated is greater than $60,000, then the authorization level of the (cont.) operator making this change/add must be greater than a certain predefined authorization level. These are a few examples of the power of Business Rules. Even the limit of 15,000 lines is not really a limit, since you can include -MAGECINC control cards, each of which could expand to 15,000 more lines. The most common use for (cont.) -MAGECINC's in Business Rules will be in the Data Division to include Element copybooks for I/O's done in the Procedure (cont.) Division code for the Business Rule. SInce this coding might very well be inserted into several applications, and since those applications might very well (cont.) include -MAGECINC's for some of the same copybooks as are being called for in the Business Rule's Data Division coding, (cont.) we recommend that you take advantage of the facility in MAGEC to specify that your -MAGECINC is to be expanded only if (cont.) it is not elsewhere included in this same program. This avoids the nuisance of duplicate definitions and resulting need (cont.) to qualify all references, and wasted space. | ``` **     DO THIS: Key the command: RULADD VAD01/RULWORK, press ENTER     ```** | ``` **  RULADD  VAD01/RULWORK SEARCH ARG: .................................................................. Password: M A G E C .......  page New Password:  ELEMENT DATA RULES  ........   TAB Option: ON ....+..;10.;..+;..20....+...30....+...40...;+...50....+...60....+...70..   05  RUL-xxx01-FLD1  PIC X.  01   05  RUL-xxx01-FLD2  PIC 9.  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 20 -- Business Rule Add Screen The way you tell MAGEC to do that is via the -IFUNIQUE control card immediately preceeding your -MAGECINC, as shown below: -IFUNIQUE **-MAGECINC member/modifier   This will cause the member named "member/modifier" to be included into the program only if it is not already included. (cont.) This works even if the other -MAGECINC for that member appears after this one in the physical program listing. This (cont.) facility is not restricted only to Business Rules, it may be used anywhere in any MAGEC application; however, we (cont.) believe that you will avoid much trouble if you establish a standard of using the -IFUNIQUE in front of every Data (cont.) Division -MAGECINC in your Business Rules. You are adding the Data Division code for your Business Rule. The rule we will be adding will verify that the Employee (cont.) Number being added to the VAD Data Class is a valid number defined on the SIF Data Class. This means that the SIF Data (cont.) Class is the "master file" and that you may not have vacation data for an employee who is not defined on the SIF (cont.) file. Business Rules can consist of Data Division and/or Procedure Division coding. The modifier "RULWORK" signifies that (cont.) this code is to be inserted into the Data Division; it will be the definitions of work areas needed by the procedural (cont.) logic (which you will be adding next). You are specifying, in this example, that you wish the SIF01-C copybook included (cont.) unless it has been included elsewhere in the program. To add a Business Rule for our VAD01 Element: | ```      DO THIS: Key the two lines of code shown below, press ENTER.     ```** The code you have specified here will be inserted into the Data Division, in the TWA area of any MMP's generated to (cont.) update Element VAD01. Since this is in the Linkage Section of your programs *you must not use the Cobol VALUE** (cont.) clause*. You must also remember that this code will be inserted immediately behind a Cobol data item which is at level (cont.) 03; therefore, your work fields should be Cobol level 04 and below. 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: .................................................................. Next: https://magec.com/DOC/markdown/data03.md.txt