Example

The example control file (shown below) reads a print stream and uses information from a lookup file to add the appropriate department number to each document. Account numbers not found in the lookup file are written to a report file. Documents are then written to separate output files based on the department number.
<input>
  <name> INPUT                     <! Identifiable name.            >
  <file> H:\INPUT.AFP              <! Input file name.              >
  <type> AFPL A       <! AFP Line data with ASCII carriage controls.>
  <doc> T %%AcctNum CHANGE           <! New document when Account   >
                                     <! number changes.             >
  <field> %%AcctNum KA
    <loc> 13 60 8                   <! Get 8-byte account number.   >
  </field>
  <field> %%Dept     R              <! Replace the first occurrence >
    <loc> 5 67 3                    <! on line 5, column 67 for 3   >
  </field>                          <! bytes.                       >
<input>
<rule>
  <content>
   DOCUMENT:
    <!  Build key for file lookup.                        >
    <!  The account number on the file does not include   >
    <!  the dash as it does on the document.              >
    %%Key = SUBSTR(%%AcctNum,1,3) | SUBSTR(%%AcctNum,5,4)
    <!  File lookup for department number.                >
    <!  If the account number is not in the file          >
    <!  a record is written to a sequential file.         >
    %%Record = LOOKUP('H:\LUFILE.TXT',%%Key,1,7,Y)
    if %%RC = 0 then
      %%Dept = JUSTIFY(SUBSTR(%%Record,8,3),L,3,' ')
    else
      %%Dept = '   '
      %%DocNo = JUSTIFY(%%DOCUMENT_NO,R,5,0)
      %%ErrorRecord = %%AcctNum | %%DocNo
      %%err = WRITE('H:\LUERROR.TXT',%%ErrorRecord,VB,8204)
    endif PRESORTED:
     <! Set the name of output file to include the department number. >
    if CHANGED(%%Dept) then
      %%FN = "DEPT" | %%Dept | ".AFP"
      <filebreak>
    endif
    <output> Output1
   </content>
</rule>
<output>
   <name> Output1                 <! Identifiable name.              >
   <dynafile> %%FN
   <filemax> M
   <presort>
      <pretype> NONE              <! Not LPC or Group1, but other.   >
      <file> H:\INPUTA       <! Indexed sort key file for processing.>
      <sortpart> %%DOCINDEX 9 L ' ' <! Document index system variable>
      <sortpart> %%Dept     3 L ' ' <! Department number             >
      <sortpart> %%AcctNum  8 L ' ' <! Account number                >
      <step> SORT 0 ' SORT FIELDS=(10,3,A,13,8,A),FORMAT=BI,EQUALS
                      OPTION SORTIN=INPUTA,SORTOUT=OUTA'
      <outfile1> H:\OUTA.AFP 20     <! Sorted output file.           >
      <indexcol> 1                  <! Document index in column 1.   >
   </presort>
</output>