Syntax
MATCH { CompareAscending | CompareDescending } (extract_file , extract_file) [ AND { CompareAscending | CompareDescending } (extract_file , extract_file) ] [ GS status ]
Parameters
The Match logic command is followed by a set of logic statements to execute for each iteration, and finally by an End, EndExit, or EndNoPrint logic statement. If an EndExit logic statement is specified, the report goes to end-of-job after the first time through the Match logic statement loop.
CompareAscending or CompareDescending
The order in which to read records. This can be one of the following:
CompareAscending
CompareDescending
extract_file (first)
The first extract file to match.
If matching using a specific attribute of the extract file, this must be the full qualifier of the attribute, in the form <extract file>.<layout>.<attribute>, where <layout> is the class to read the extract file as.
extract_file (second)
The second extract file, to match to the first extract file.
If matching using a specific attribute of the extract file, this must be the full qualifier of the attribute, in the form <extract file>.<layout>.<attribute>, where <layout> is the class to read the extract file as.
AND
Matches using more than one pair of attributes from the extract files.
This command option can only be specified if matching using specific attributes of the extract files.
GS status
Indicates if neither extract file contains data, using the specified qualifier.
Description
The Match logic command compares two extract files. The behavior of the Match logic command is similar to that of the Determine Actual logic command, except that it reads two extract files instead of one.
Set the <Extract File Name>.Record built-in extract file attribute to the specific records to start reading from for each extract file. For example:
FileA.Record := 2
Note: If Record is not set to a number, or it is set to the Glb.Zeros built-in segment attribute, the read starts from the first record. Refer to Record built-in extract file attribute for more information.
Records are read from both extract files until the Glb.Match built-in segment attribute is set (either explicitly, or if one extract file reaches end-of-file before the other).
For applications deployed to Windows, when the Match logic command reaches an end-of-file, the last record read from that file is available.
If attributes to match are not specified, a record from each file is read until Glb.Match is set to a value other than spaces.
If attributes to match are specified, just one file can be read repeatedly until the value of the specified attribute from that extract file matches or exceeds the value of the specified attribute from the other extract file.
The behavior of the Match logic command when reading an extract file is similar to that of the Determine Actual logic command. Refer to Extract File Variant for more information.
Glb.Match
The Glb.Match built-in segment attribute is set to the name of the next extract file that is to be read by the Match logic command. Within the Match logic command loop, if the Glb.Match built-in segment attribute is set to spaces, it indicates that both extract files are to be read. Outside the Match logic command loop, the Glb.Match built-in segment attribute is set to spaces, being reset immediately upon exiting the loop.
To read a record from only one of the two extract files, explicitly set the Glb.Match built-in segment attribute to the extract file to be read.
Specify a DoWhen logic command as the first statement within the Match logic command loop to test the value of the Glb.Match built-in segment attribute.
Failure behavior
The Glb.Status built-in segment attribute is set to "*****" if neither extract file contains data. Use the GS logic command option to direct the Glb.Status built-in segment attribute value to a variable.
Recovery of reports that invoke the Match logic command can be achieved similarly to that of reports that invoke the Determine Actual logic command.
Restrictions
The following restrictions apply to use of the Match logic command:
The specified extract files must be fully defined by previous Extract, Determine Actual, and/or SetTitle logic statements.
The RetainAs command option of the Extract logic command is invalid within Match logic command loops. File name assignment can be achieved using the SetTitle logic command. For example:
SetTitle FileA "A_FileName" SetTitle FileB "B_FileName" Match CompareAscending(FileA.Cust.Rep, FileB.Cust.Code) GS TStatus If Glb.Match = "FileA" Frame10.Print() End Frame20.Print() End
Results obtained from an Extract or Determine Actual logic statement specifying the same extract files as a Match logic statement can be inconsistent when invoked from within the Match logic statement loop. Correspondingly, use of such logic statements is not recommended.
CriticalPoint and Restart logic statements are invalid within Match logic statement loops.
Match logic statement loops cannot be nested.
Extract files cannot be matched against themselves (the two specified extract files must be distinct).
Examples
Example 1
This example shows how an extract file that has different record formats (such as header, trailer, and data records) can be read.
This example uses the following two extract files:
FileA
Record | Name | Dept | Phone |
---|---|---|---|
1 | Adam | Systems | 8765 |
2 | Barbara | Finance | 8567 |
3 | Bruce | Qual | 8123 |
FileB
Record | Name | Dept | Phone |
---|---|---|---|
1 | Adam | Systems | 8766 |
2 | Adrian | Training | 8024 |
3 | Alan | Admin | 8777 |
4 | Anthea | Research | 8999 |
If the following Match logic statement is specified, with only the extract file names:
Match CompareAscending(FileA, FileB) If Glb.Match <> Glb.Spaces Frame10.Print() End End
The result is:
The Match command compares the two extract files and prints a record when Glb.Match is set to a value other than spaces. In this example, record 4 of File B is printed. As there is no key attribute specified, Glb.Match will be spaces until the end of file of File A reached.
FileA, record 1 is read, FileB, record 1 is read: Glb.Match = Glb.Spaces
FileA, record 2 is read, FileB, record 2 is read: Glb.Match = Glb.Spaces
FileA, record 3 is read, FileB, record 3 is read: Glb.Match = Glb.Spaces
FileA, record 3 remains, FileB, record 4 is read: Glb.Match = "FileB"
Example 2
In this example, the same two extract files as in Example 1 (FileA and FileB) are matched. The Record built-in attribute specifies where the reading of the extract files should start.
FileA.Record := 1 FileB.Record := 2 Match CompareAscending(FileA, FileB) If Glb.Match <> Glb.Spaces Frame10.Print() End End
The result is:
FileA, record 2 is read, FileB, record 3 is read: Glb.Match = Glb.Spaces
FileA, record 3 is read, FileB, record 4 is read: Glb.Match = “FileB”
The Match command reads record 2 of FileA and record 3 of FileB, compares the two extract files, and prints a record when Glb.Match is set to a value other than spaces. In this example, record 4 of FileB is printed. As there is no key attribute specified, Glb.Match will be set to spaces until the end of file of FileA is reached.
Example 3
In this example, the same two extract files as in Example 1 (FileA and FileB) are matched. The Name attribute is used for comparison.
Match CompareAscending(FileA.Cust.Name, FileB.Cust.Name) If Glb.Match <> Glb.Spaces Frame10.Print() End End
The result is:
FileA, record 1 is read, FileB, record 1 is read: Glb.Match = Glb.Spaces
FileA, record 2 is read, FileB, record 2 is read: Glb.Match = "FileB"
FileA, record 2 remains, FileB, record 3 is read: Glb.Match = "FileB"
FileA, record 2 remains, FileB, record 4 is read: Glb.Match = "FileB"
FileA, record 2 remains, FileB at end-of-file: Glb.Match = "FileA"
FileA, record 3 is read, FileB, record 4 remains: Glb.Match = "FileA"
The Match command compares two extract files, where Cust.Name is the key attribute and prints a record when Glb.Match is set to a value other than spaces. In this example, the records: Adrian, Alan, Anthea, Barbara, and Bruce are printed as the key attributes do not match.
Example 4
In this example, the Glb.Match built-in segment attribute is set to one of the Extract file names within the Match logic command to force that file to be read on the next Match cycle loop.
Match CompareAscending(EXTRACT1.F10.F10K1, EXTRACT2.F27.F27K1) \ AND CompareAscending(EXTRACT1.F10.F10K2, EXTRACT2.F27.F27K2) \ AND CompareAscending(EXTRACT1.F10.F10K3, EXTRACT2.F27.F27K3) SD_DATESTART := EXTRACT1.F10.F10DATE BeginCase GLB.MATCH Case GLB.SPACES SD_DATEEND := EXTRACT1.F27.F27DATE If SD_DATESTART >= SD_DATEEND GLB.MATCH := “EXTRACT1” :force read of EXTRACT1 Else GLB.MATCH := “EXTRACT2” :force read of EXTRACT2 End .. .. EndCase .. End foreach MyIterator in MyExtract MyCustomerNumber := MyIterator.Cust.Customer : ... end