Was this helpful?
CATCHUP { statements }
CATCHUP mode is used for building an array of records, and then supplying them at a later time. This is used if there is information in a footer that you need to put in each record. You would assign values to array variables for each line read, plus a counter. Then, when you hit the footer, assign any values you need, and turn CATCHUP mode on (catchup on). In the CATCHUP pattern-action block, build records until you've supplied them all (via accept), then turn CATCHUP mode back off (catchup off).
Example
This detailed example shows a script that assigns values to array variables for each line read and increments a counter to serve as the index of the array. When the line with Account No. is read, it is saved in a variable and CATCHUP mode is turned ON. In CATCHUP mode, the program writes all the records for a company at once, then turns CATCHUP mode back off to prepare for the next company.
Input Source File for Catchup Example
 
Company: Hudson Imports
1. Item A
2. Item B
Account No.: 127-295-0
Company: Periph Supplies
1. Item A
2. Item B
Account No.: 143-396-2
...
CXL Script for Catchup Example
#!djrr
BEGIN { lineno = 0; # lineno is used to count items
rec = 0; } # rec is used to print each item
# find each Company section and store the company name
$0(3 10) ~ /Company:/ { clearvars; coname = trim($0(12 80)); }
$0(1 5) ~ /[0-9]*\. / { lineno = lineno + 1; # found a new item
itno[lineno] = trim(substr($0,1,5)); # store the item number
itdesc[lineno] = trim(substr($0,6,80)); # store the item description
}
# If footer line, store account number and turn CATCHUP mode on
$0(5 16) ~ /Account No.:/ { coacct = trim($0(18 26)); catchup on; }
CATCHUP { rec += 1; # increment rec each time CATCHUP is performed
if (rec <= lineno) # verify not at end of line items
# output stored information for the current line item to the Map Designer
accept <"#"> rec,
<"Company"> coname,
<"Account No."> coacct,
<"Item No."> itno[rec],
<"Item Description"> itdesc[rec];
else
catchup off; # at end of line items, so turn catchup off and
} # continue processing the input
Output Records for Catchup Example
 
 
#
Company
Account No.
Item
Description
1
1
Hudson Imports
127-295-0
1
Item A
2
1
Hudson Imports
127-295-0
2
Item B
3
2
Periph Supplies
143-396-2
1
Item A
4
2
Periph Supplies
143-396-2
2
Item B
5
 
...
...
...
...
Last modified date: 12/03/2024