Bringing Information in from Other Registers
There will be occasions when the register in a particular section does not contain all the information that you want printed. If so, you can link to another register or setting to bring in the information that you need. For example, each Customer record has a Category Code field, but not a Category Name field. If you want to print a Customer list that includes Category Names, you will have to establish a link to the
Customer Categories setting. Similarly, each Invoice Item includes the Unit Price and the Sum charged to the Customer. It would be possible to establish a link to the Item register to bring in the Base Price of each Item, so that the standard sales price of an Item (its Base Price) could be compared with the actual sales price (the Unit Price in an Invoice). Follow these steps:
- Return to the Report Definition record and go to the 'Data' card.
- Select the register that you are linking from. For example, to print a Customer list that includes Category Names, you will have to establish a link from the Customer register to the Customer Categories setting. So, click on the line marked "Register: Customers...".
- Click the [Look Up] button above the report display area. The 'Lookup Record' dialogue box appears:
- Register
- Paste Special
Registers in Hansa
- Specify here the register that you want to link to.
- The register you are linking from and the one you are linking to must have a common field. In the example, the Customer Category Code is common to the Customer register and the Customer Categories setting.
- The link must be a "many-to-one" (or "one-to-one") link: there must only be one record at the end of the link. In the example, several Customers can have the same Customer Category Code, but only one Customer Category can have that same Code. So this condition is satisfied because there will only be one Customer Category record at the end of the link.
- Index
- Paste Special
Indexes in the selected register
- Use this field to specify the sort order to be used in the register you are linking to.
- It's best to sort this register by the common field (see above).
- Variable Name
- Enter a name for the variable that will contain the linked record (in the example, the Customer Category record).
- where, is
- Use these fields to construct the search expression that will find the single matching record in the register you are linking to. The Where field should contain the field in the linked register that is to be searched, while the Is field should contain what is being searched for.
- The Where column contains a list of fields in a particular register or setting: in this case, the Customer Categories setting. This list cannot be changed: it depends on the Index you specified in the field above. If you want to search in a field that is not listed, you will need to change the Index first. In this example, you can search in the Code field in the Customer Categories setting.
- Specify what you are searching for in the Is column: in this case, the Customer Category Code of the current Customer. In the top field in the Is column in the illustration below, we have entered the expression that holds this information: "vrCustomer.CustCat".
- Note that although the Customer Category Code field is the common field, the internal names for this field in the Customer register and in the Customer Categories setting are not the same ("CustCat" in the Customer register and "Code" in the Customer Categories setting).
When you click [OK], the lookup appears as a "Lookup:" line in the Customer section in the report display area:
Because the lookup is in the Customer section, it will be carried out once for each Customer listed in the report.
- Now you can specify what information from the linked register is to be printed in the report. You must do this using variables because the linked register is not given its own sections on the 'Layout' card. The sections that are already in the report cannot accept fields from the register you are linking to. In the example, the Customer Header, Before, After and Footer sections can only accept fields from the Customer register, not from the Customer Category register.
Change to the 'Layout' card and click on the section in which you want the variable to be printed. Then, click the [Formula] button. When the 'Formula' dialogue box opens, enter the name of the variable and appropriate left and right co-ordinates and choose a justification.
In this example, the expression "vrCategory.Comment" will print the Customer Category Name. "vrCategory" is the name of the variable containing the current Customer Category (as specified in the 'Lookup Record' dialogue box above), and "Comment" is the internal name for the Customer Category Name field in the Customer Categories setting.
- When you click [OK], the formula is placed in the correct position (in our example, in the Customer Before section):
This is the result: