Postal Presort Example
The following example demonstrates how to perform a postal presort on mainframe systems using a POSTNET™ Code barcode as the sort criterion.
<input>
<name> INPUT <! Identifiable name. >
<file> DD:INPUT <! Input file name. >
<type> AFPL A <! AFP line data w/ANSI controls.>
<doc> T %%AcctNum CHANGE <! Top of document when field changes. >
<field> %%AcctNum KA <! Find all occurrences >
<loc> 13 60 8 <! Line 13, column 60, for 8 bytes. >
</field>
<field> %%SortBar K <! The delivery point barcode field >
<loc> 12 10 12 <! Print line 12, column 10, 12 bytes. >
</field>
</input>
<rule>
<content>
<! Initialize the variables used in the rule. >
START:
%%Oldtray = ' '
%%Traydocs = 0
%%Traypages = 0
<! Everytime there is a new tray, make an entry in the report >
<! file that has the accumulated total documents pages. >
PRESORTED:
if %%TRAY_NO <> ' ' THEN <! don't increment for rejects >
if %%Oldtray <> %%TRAY_NO AND %%Oldtray <> '' then
%%Report = %%Traydocs | ',' | %%Traypages | ',' | %%Oldtray
WRITE('DD:TRAYRPT',%%Report,FB, 80, 8000)
%%Oldtray = %%TRAY_NO
%%Traydocs = 0
%%Traypages = 0
endif
%%Traydocs = %%Traydocs + 1
%%Traypages = %%Traypages + %%TOTAL_PAGES
endif
<! Make the last entry in the report for the last tray. >
FINISH:
%%Report = %%Traydocs | ',' | %%Traypages | ',' | %%Oldtray
WRITE('DD:TRAYRPT',%%Report,FB, 80, 8000)
</content>
</rule>
<output> <! The presorted output file. >
<name> GoodOut <! Identifiable name. >
<file> DD:OUTPUT1 <! Output file name. >
<presort> <! Specify presort details. >
<pretype> LPC <! Type of presort to be done. >
<file> DD:MSSTIN
<sortpart> %%DOCINDEX 8 L ' ' <! System variable, 8 bytes. >
<sortpart> %%SortBar 12 L ' ' <! POSTNET data, 12 bytes. >
<rejectfile> DD:REJECT <! Any documents with invalid zipcodes>
<! The presort steps to process with appropriate params and >
<! in the order of execution. >
<step> MSDR00
<outfile1> DD:MSWKIJ4 400 <! Presorted, indexed file. >
</presort>
</output>