DEFINE

From CometWiki

Jump to: navigation, search

DEFINE
Syntax:
DEFINE field-name=expression;length[.precision][,display-length][;title]
Placement:
Place the DEFINE command either before or after the REPORT command.
Discussion:
DEFINE allows you to set up a new field name for The Reporter that doesn't already exist (i.e, a virtual field) and assign it to a numeric or string expression based on the fields available to you in The Reporter.
The field name can be up to 15 characters long and must be described by the expression that follows the equal sign.
The name can contain periods, letters or numbers, but it cannot contain any other characters.
You must define fields for the report before you use the field names with the following commands:

The expression can be constants, fields, operators, or functions that work alone or are combined to yield a string or numeric value.
All MTB operators and functions are supported. Hex constants are also supported.

The length.precision parameter gives the field's length in characters (or digits) and the decimal place precision.
The number to the left of the period represents the total length of the field, and the number to the right of the period represents the number of decimal places included in the number.
Do not specify a precision if the field represents a string.

The display-length parameter overrides the column width calculation and defines the number of characters to display.
This can be very useful when defining an HTML hyperlink that will be displayed in a web browser (see Example 2).

You can specify a title to print above a new column you are defining
. If you do not specify a title, the field-name will be printed above the column.

Line continuation

To continue a DEFINE command to the next line, use an "_" character anywhere it would be allowed by the MTB compiler in your expression, but not before the "=".

History:
The display-length parameter was added in version 01.01.

Example 1:

 100    INPUT CUSTOMER
 200    TITLE PAST.DUE.ACCOUNTS
 300   DEFINE PAST.DUE = AR.OVER.60 + AR.OVER.90;8.2;PAST DUE
 400   SELECTING IF PAST.DUE GT 0
 500   SORT ON STATE;CUST.NAME
 600   REPORT
 700   USING CUST.TO.HIST
 800   PRINT CUST.NAME;CUST.NUMBER;STATE;PREVIOUS.YTD;PAST.DUE
 900   BREAK ON STATE
1000  TOTAL PAST.DUE;PREVIOUS.YTD
1100  END

In this example, the DEFINE command on line 300 creates a new field named PAST.DUE, which is the sum of two existing fields (AR.OVER.60 and AR.OVER.90).
The field length/precision is 8.2, and the field title is PAST DUE.

Example 2:
There are HTML commands which require long MTB strings of data but which are then reduced considerably by the browser.
An example of this is <a href> tag, which doesn't actually display the hyperlink address, just the text associated with it. For example:

DEFINE X='<a href="http://...">'+"CLICK HERE</a>";40,10

In this example, the length of 40 represents the length of the MTB variable, X, and the override length of 10 represents the number of spaces required to display "CLICK HERE" in the browser.
Without the length override, the Reporter would force the column width to be wide enough to accommodate the entire X string.

Personal tools