Creating a Rule File

To create a rule file, follow this general process. For more information about any of the steps, see the Enrichment Language Reference Guide.
  1. Decide whether you want to embed the rule file in the control file or whether you want to create a separate rule file that you call from the control file. Most often developers choose to embed the rule file in the control file.
  2. Add the Rule tag group to the control file.
  3. Do one of the following:
    • If you are embedding the rule file in the control file, add the Content tag group to the Rule tag group. The Content tag group will contain the rule file you write.

      An example of the Content tag group is shown below.

      <rule>
      <content> 
      rule file statements
      </content>
      </rule>
    • If you are calling an external rule file, add the <FILE> tag to the Rule tag group and specify the path to the external rule file.
      <rule>
      <file>c:\rules\myRuleFile.txt 
      </rule>
  4. In the rule file (either the external or embedded rule file) create the sections required for your application. Your rule file can contain some or all of the sections listed below. Each section executes at a different time during Enrichment processing. The sections consist of a section header (the section name followed by a colon) and one or more statements. A section header is the section name followed by a colon.

    For example:

    DOCUMENT:
     %%SUM = %%A + %%B
    Note: If you do not designate a section name, Enrichment assumes the section is DOCUMENT:.

    Your rule file can contain some or all of the following sections.

    START Executes before any of the inputs are read. Use this section to initialize variables and add beginning banner pages. You should also declare user-written functions and set the initial file name for dynamically allocated outputs in this section.
    DOCUMENT Executes once for each document as soon as the document has been identified and optionally matched with other inputs. You can use this section to route the document to one or more outputs, append inserts, and add banner pages.

    When inputs are sorted using <SORTMATCH> or <DOUBLESORT>, documents are processed in the sort order, not in the order in which they appear in the original input.

    This section was the rule file in versions of Enrichment prior to 4.x.

    PRESORTED Executes once for each document after postal Presort has occurred. You can add banner pages and reroute the document to a different output (for example, to outsort residual mail pieces). This section only executes on documents routed to an output containing the Presort group.

    The PRESORTED section processes every document for which a record is returned from the external program called by the <PRESORT> <STEP> tags. Documents that are not returned by the external program are instead routed to a reject file if the tag <REJECTFILE> is specified in the Presort tag group. If the tag <REJECTFILE> is not specified, documents that are not returned may be "lost," meaning that they will not appear in any Enrichment output.

    PAGE Executes once for each page in a document immediately prior to writing the page to the output. You can use this section to apply page-varying information, such as checksum for an inserter barcode.

    This section was the pagerule in versions of Enrichment prior to 4.X.

    FINISH Executes once after the last document is processed. You can compute summary information and add banner pages to any or all outputs.
  5. In each section you create, write the appropriate code to accomplish what you want with your application. The code that you write may incorporate the following items.
    User-Defined Variables These let you change fields, insert page file assignments, and insert record file assignments with Set Statements and functions.
    User-Written Functions You can use existing subroutines within rule files as functions or write your own. These subroutines can be written in COBOL, Assembler, or C. For more information, see Working with User-Written Functions.
    Functions There are a rich set of functions for you to use in rule files. You can use these functions to manipulate data and in some cases, return the result as a variable value.
    Instructions These allow you to perform conditional processing. Instructions include IF THEN ELSE, QUIT, FOR…NEXT, DO…NEXT, and SELECT CASE.
    Print Stream Commands These let you manipulate your documents from within the rule file. Print stream commands include <OUTPUT>, <APPEND>, <BANNER>, and <FILEBREAK>.
    Comments These annotate the rule file and can be placed anywhere within it.