Reading and Writing Record Data

The READ and WRITE functions read and write one record at a time from a file.

The READ function is normally used in the START: rules to initialize data or within the DOCUMENT: rules to read files associated with each document to get additional data. Refer to the Enrichment Language Reference Guide for more information on the READ function.

You can use WRITE to create reports, indexes or any other data on a sequential basis. Unlike the Sidefile tag group process, you can use WRITE to write multiple records per document or to only write records for some documents. The following illustrates the use of READ and WRITE in the rule file.

START:
  %%JOBNUM = READ(DD:JOBNUM)                <! Get job number.       >
  %%OUTPUTFILE = ’FILE:’| %%JOBNUM | ’.RPT’ <! Set output file name. >
  %%TOTALAMOUNT = 0
DOCUMENT:
  %%CUSTINFO = %%CUSTNUM | %%INVOICE
  %%TOTALAMOUNT = %%TOTALAMOUNT + %%INVOICE <! Add total invoices.   >
  WRITE(%%OUTPUTFILE,%%CUSTINFO)            <! Write customer record.>
FINISH:
  %%CUSTINFO = ’TOTAL:  ’ | %%TOTALAMOUNT   <! Write total record.   >
  WRITE(%%OUTPUTFILE,%%CUSTINFO)

In the START: section, Enrichment reads the value of %%JOBNUM from a file and uses it to establish the name of the report file. In the DOCUMENT: section, Enrichment writes the invoice amount for each customer to the report. In the FINISH: section, Enrichment writes the total invoices to the report.