User Guide > Using Content Extraction Language > Script Examples > Example Script 1: Fixed-Format Report
Was this helpful?
Example Script 1: Fixed-Format Report
Most reports are written in a fixed format style with similar information appearing repeatedly at specific locations in the file. The input source file in this example contains a classical fixed format report. The report is divided into pages. Each page begins with header information, followed by groups of detail lines with details presented in labeled columns. Summary information appears under some columns at the end of each group and at the end of the report.
The script extracts information from each detail line and, when executed by the Map Designer, will write that information to a data file or table. Since lines other than detail can be ignored, most of the script matches patterns that are rejected. The elimination process uses several strategies. All empty lines, i.e., length(trim($0)) == 0, are rejected. The Input Field Separator (IFS) is set to a blank (space) so that the pre-assigned variable NF can be used to reject lines with fewer than three columns. Other lines are rejected if they contain certain text patterns, e.g., the word TOTAL in uppercase. From the lines that aren't rejected, check number (check_no) and date (check_dt ) are captured from the first two blank-delimited fields; vendor number (vendor_no), name (name), and check amount (check_amt) are extracted from specific locations in the input line.
The values of the variables listed in the accept statement are displayed in the Source Data Browser, and will eventually be written to a Map Designer data file. If column labels are not defined in the accept statement, the default field names (Field1, Field2, Field3, ... ) would be used as the column labels, and field lengths would only be as long as the data collected in the first field. It is generally a good idea to assign field names and lengths for ease of mapping in the Map Designer, and to avoid possible data truncation.
Input Source File
RUN DATE: 12/14/94 abc PAGE: 1
DATE: 11/16/94 CHECK HISTORY REPORT TIME: 03:10 PM
AS OF: 12/31/94
BANK CODE: A Security Pacific Checking
CHECK CHECK VENDOR CHECK
NUMBER DATE NUMBER NAME AMOUNT
001611 05/31/95 01-AIRWAY AIRWAY PROPERTY 7,000.00
001618 05/31/95 02-ARROW ARROWSMITH WATER 75.00
001618 05/31/95 02-ARROW ARROWSMITH WATER 75.00-
001621 05/31/95 02-LEARNER ROGER W. LEARNER 2,500.00
001668 05/31/95 01-STEV STEVENS FREIGHT S 936.34
001711 05/31/95 01-ANDERS ANDERS AUTO REP 3,524.81
001713 05/31/95 *** VOID CHECK ***
001730 05/31/95 01-COMPAQ COMPAQ COMP CORP 5,000.00
------------
BANK A TOTAL: 18,961.15
------------
REPORT TOTAL: 18,961.15
============
Last modified date: 07/26/2024