Related Information Examples & Tutorials

Using Flags To Control Printing

There may be times when you only want to print certain areas of your report based on criteria that you set. If you cannot use a WHERE clause to get the results you want, you may be able to create a clause using a flag. For instance, you may have a section of column headings written into your report that you only want to print if there is data in that section.

Let's assume your header is the following text:

@!@& DEBTOR PAYMENTS RECEIVED (TO TRUST ACCOUNT)@!@&

---------------------------------------------------------------------------------------------------------------
Here you may have several column headings.
----------------------------------------------------------------------------------------------------------------

You only want this to print when you find a matching transaction, and then to print only one time, before the first transaction in the group.

You can do this in the following manner:

Declare A Flag

1. Declare a flag to control the printing, and set the value to the first Debtor Status in your Debtor Status list, for example, ACT.

@varPrintTheHeader = ACT

2. Loop through the list you are evaluating.

@tr no total where (@tr.pda = @tsr.fr .. @tsr.to) where (@tr.ty = 101 .. 102) where (@tr.ofdcr != X)
@tr.cl<6> @tvarClient<40> @tr.fi<6> @tr.de<30> @tr.tu>13.2> @tr.di>13.2> @tr.ca>13.2> @tr.op>
@tr

3. Modify the loop so that the header prints before the normal output is printed, and then turns the flag off.

@tr no total where (@tr.pda = @tsr.fr .. @tsr.to) where (@tr.ty = 101 .. 102) where (@tr.ofdcr != X)
@ds where (@ds.co = @varPrintTheHeader)
@!@& DEBTOR PAYMENTS RECEIVED (TO TRUST ACCOUNT)@!@&

// Here I assume you DO NOT have a status XXX in your Debtor Status list!!!
@varPrintTheHeader = XXX
@ds
@tr.cl<6> @tvarClient<40> @tr.fi<6> @tr.de<30> @tr.tu>13.2> @tr.di>13.2> @tr.ca>13.2> @tr.op>
@tr

Top of page.

Sample Report Snippet

A sample report snippet would look something like this:

// Set the flag to print the header if we find any data.
@varPrintTheHeader = ACT

// Loop through looking for matching transactions.
@tr no total where (@tr.pda = @tsr.fr .. @tsr.to) where (@tr.ty = 101 .. 102) where (@tr.ofdcr != X)

// Grab the Client Name.
@cl no total where (@cl.cl = @tr.cl) max = 1
@tvarClient = @cl.na<40>
@cl

// Print the header only the first time. Then set the flag to a non-existent
// status so the header doesn't print on the second or subsequent
// transactions found.

@ds where (@ds.co = @varPrintTheHeader) max = 1
@!@& DEBTOR PAYMENTS RECEIVED (TO TRUST ACCOUNT)@!@&

---------------------------------------------------------------------------------------------------------------
Here you may have several column headings.
----------------------------------------------------------------------------------------------------------------

// Here I assume you DO NOT have a status XXX in your debtor status list!!!
@varPrintTheHeader = XXX
@ds

// Print the actual output.
@tr.cl<6> @tvarClient<40> @tr.fi<6> @tr.de<30> @tr.tu>13.2> @tr.di>13.2> @tr.ca>13.2> @tr.op>

// And here is the end of the loop.
@tr

If you have read all the comments - lines starting with //, you will see how the headings can be printed conditionally. Now let's expand on this to print Totals.

Top of page.

Print Totals Conditionally

// Set the flag to print the header if we find any data.
@varPrintTheHeader = ACT

// Set the flag to NOT print Totals by default.
@varPrintTheTotals = XXX

// And a bucket for Totals
@varTotal$ = 0.0

// Loop through looking for matching transactions.
@tr no total where (@tr.pda = @tsr.fr .. @tsr.to) where (@tr.ty = 101 .. 102) where (@tr.ofdcr != X)

// Grab the Client Name.
@cl no total where (@cl.cl = @tr.cl) max = 1
@tvarClient = @cl.na<40>
@cl

// Print the header only the first time. Then set the flag to a non-existent
// status so the header doesn't print on the second or subsequent
// transactions found.

@ds where (@ds.co = @varPrintTheHeader) max = 1
@!@& DEBTOR PAYMENTS RECEIVED (TO TRUST ACCOUNT)@!@&

---------------------------------------------------------------------------------------------------------------
Here you may have several column headings.
----------------------------------------------------------------------------------------------------------------

// Here I assume you DO NOT have a status XXX in your Debtor Status list!!!
// Setting this to XXX will cause this @ds loop never to happen again.
@varPrintTheHeader = XXX

// Here I assume you have status code ACT in your system, and
// ensure the Totals are printed at the end.
@varPrintTheTotals = ACT

// End of the section that prints the header once only.
@ds

// Print the actual output.
@tr.cl<6> @tvarClient<40> @tr.fi<6> @tr.de<30> @tr.tu>13.2> @tr.di>13.2> @tr.ca>13.2> @tr.op>

// Accumulate a total.
@varTotal += @(tr.tu+tr.di)

// And here is the end of the loop.
@tr

// Now print the Totals only if needed.
@ds where (@ds.co = @varPrintTheTotals) max = 1
Total: @varTotal
@ds

Top of page.

Summary

Flags are a very useful way to control what is printed in your reports. Many times, the WHERE clause is all that is needed to control the results that are output. However, whenever you want to control actual text that is printed conditionally, such as column headings, then you can use a flag. You can also use flags to print Totals conditionally, as shown above.

Top of page.

See Also

- Report Topics Index

Top of page.

Was this page helpful? Do you have any comments on this document? Can we make it better? If so how may we improve this page.

Please click this link to send us your comments: helpinfo@collect.org