Match

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.

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:

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.

  1. FileA, record 1 is read, FileB, record 1 is read: Glb.Match = Glb.Spaces

  2. FileA, record 2 is read, FileB, record 2 is read: Glb.Match = Glb.Spaces

  3. FileA, record 3 is read, FileB, record 3 is read: Glb.Match = Glb.Spaces

  4. 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:

  1. FileA, record 2 is read, FileB, record 3 is read: Glb.Match = Glb.Spaces

  2. 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:

  1. FileA, record 1 is read, FileB, record 1 is read: Glb.Match = Glb.Spaces

  2. FileA, record 2 is read, FileB, record 2 is read: Glb.Match = "FileB"

  3. FileA, record 2 remains, FileB, record 3 is read: Glb.Match = "FileB"

  4. FileA, record 2 remains, FileB, record 4 is read: Glb.Match = "FileB"

  5. FileA, record 2 remains, FileB at end-of-file:   Glb.Match = "FileA"

  6. 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