How To Use The If Conditional
In your report definition, you may want to assign a value to
a variable only when a certain condition is met. For instance,
if the debtor's owing is less than $50, you may want to output
a line of text in your report. To do this, you can place an
If Statement after a variable declaration, and the assignment
will only occur if the condition is true.
The If Statement can also be used in Control Files to
change a field label or assign a value when a certain condition
is met. Please see How To Use Control Files for details.
Requirements
- Familiarity with use of the Report Writer
- Review How To Use Variables
Please be aware that with loops, we use the
WHERE clause to set conditions. Although the report writer
evaluates the If Statement in a similar way, the If Statement is
used to assign a value to a single variable. It is not used in the
loop syntax.
Examples Of If Statements
After your variable has been declared and initialized,
you can assign a value to it using an If Statement.
Each If Statement must start at the beginning
of the line in the report writer. Do not indent or it will
not work.
One complete statement should be printed on
a single line. The following statements have been spread
over two lines for printing and display purposes in your
browser. When you use them in your own code, please
put the entire statement on a single line and DO NOT
INDENT in the report writer.
Example 1:
@varTotalPrincipal =
@de.pr if (@de.mo = Active)
Example 2:
@varTotalPaid =
@(varTotalPaid+de.pa) if (@de.mo = Closed)
Example 3:
@varTotalDirect =
@(varTotalPaid+tr.di) if (@tr.ty = 104)
Example 4:
@varString1 =
owes less than $100.00 if (@de.ow < 100)
Clearing A Text String With If
This example clears a text string variable.
@varString1 = if (@de.ow < 1)
Changing A Field Value With If
This example will change the debtor's status to SKP
if the Address is not OK.
@EDITde.sta = SKP if (@de.ao = " ")
Include With If Statements
You can use IF statements with the @include
command to load files conditionally when your report prints.
Example:
@include header1.txt if ( @de.cn = 92 )
@include header2.txt if ( @de.cn = 98 )
@include header3.txt if ( @de.cn = 101 )
This example loads a different header file depending
on the Debtor's Client.
Please refer to Help topic, How to Use @Include in Reports.
Summary
To understand the concept of Variables
used in these code snippets, please refer to
How To Use Variables.
See Also
- Report Sample to view sample reports and letters
- Report Topics Index for a list of all report and letter topics
|
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