#DEFINE
Syntax
#DEFINE substitution_variable value
Description
Declares a value for a substitution variable within the body of the report (rather than using the ASK command).
#DEFINE is useful for specifying constants such as column locations, printer fonts, or any number or string that is used in several locations in the program. When the value of the number or string must be changed, you need only change the #DEFINE command. All references to that variable change automatically, which makes modifying programs much simpler.
If the ASK command is used to obtain the value of a substitution variable that has already been defined, ASK uses the previous value and the user is not prompted. This enables you to predefine some variables and not others. When the report runs, ASK requests values for only those variables that have not had a value assigned.
You can use #DEFINE commands inside an include file. This is a method of gathering commonly used declarations into one place, and reusing them for more than one report.
The value in the #DEFINE command can have embedded spaces and does not need to be enclosed within quotes. The entire string is used as is.
The #DEFINE command cannot be broken across program lines.
Parameters
| Parameter | Description |
|---|---|
|
substitution_variable |
The variable to be used as the substitution variable. The substitution variable is used to substitute any command, argument, or part of a SQL statement at compile time. |
|
Value |
The value to be substituted. |
Example
This code example defines several constants:
#define page_width 8.5
#define page_depth 11
#define light LS^10027
#define bold LS^03112
#define col1 1
#define col2 27
#define col3 54
#define order_by state, county, city, co_name
This code example from a report uses the definitions from the preceding example:
begin-setup
declare-printer contacts
type=hp
paper-size=({page_width}, {page_depth})
end-declare
end-setup
begin-heading 5
print 'Company Contacts' (1,1) center
print 'Sort: {order_by}' (2,1) center
print 'Company' (4,{col1})
print 'Contact' (4,{col2})
print 'Phone' (4,{col3})
end-heading
begin-procedure main
begin-select
company (1,{col1})
print '{bold}' (0,{col2}) ! Print contact in boldface.
contact ()
print '{light}' () ! Back to lightface.
phone (0,{col3}) ! Note: There must be enough
next-listing ! space between col2
from customers ! and col3 for both
order by {order_by} ! font changes and the
end-select ! contact field.
end-procedure
See ASK