TYPE

In this section:

How to:

Reference:

The TYPE command writes messages to a file, a web browser, or the Maintain Data output window. The TYPE command is helpful for application debugging, such as tracing application flow-of-control, and for recording an accounting trail. To display messages to application users, it is recommended that you use forms, which provide superior display capabilities and better control than the TYPE command.

Syntax: How to Use the TYPE Command

The syntax of the TYPE command is

TYPE [ON ddname] "message" [[|] "message"] ... [;]

where:

ON ddname

Specifies the logical name of the file that the TYPE message is written to when ON is specified. You must define the ddname (using a DYNAM or FILEDEF command) prior to the first usage. The message string can be up to 256 characters in length. The output starts in column 1. In order to append to an existing file or to write to a file from more than one procedure, append to the file by specifying the appropriate option in the DYNAM command.

In addition, if ON ddname is omitted and this procedure was called remotely (that is, called using a CALL procname command), the message will also be copied to the FocMsg stack of the calling procedure.

message

Is the information to be displayed or written. The message must be enclosed in double quotation marks ("). The message can contain:

  • Any literal text
  • Variables
  • Horizontal spacing information
  • Vertical spacing information

The layout of the message is exactly what is specified.

;

Terminates the command. Although the semicolon is optional, including it to allow for flexible syntax and better processing is recommended. For more information about the benefits of including the semicolon, see Terminating a Command's Syntax.

Reference: Commands Related to TYPE

SAY. Writes messages to a file or to the server console. Messages can include multiple expressions of all types.

Including Variables in a Message

You can embed variables in a message by prefixing the variable with a left angle bracket (<). Unless the field name is the last item in the string, it must be followed by a space. Maintain Data does not include the angle bracket and space in the display. For example:

TYPE "Accepted:  <Indata(Cnt).Fullname";

Embedding Horizontal Spacing Information

TYPE information can be placed in a specific column or can be moved a number of columns away from the current position. The following example

TYPE "<20 This starts 20 spaces over";
TYPE "Skip <+8 8 spaces within text";
TYPE "Back up <-4 4 spaces and overwrite";

results in:

                   This starts 20 spaces over
Skip         8 spaces within text
Back4 spaces and overwrite

Embedding Vertical Spacing Information

Lines can be skipped by supplying a left angle bracket (<), slash (/), and the number of lines to be advanced. If the line advance specification is at the beginning of the line, the specified number of lines are advanced before the following text.

TYPE "</3 Displays 3 blank lines" |
" before this line";

If </number is encountered in the middle of the line, the line feed occurs when </number is encountered.

TYPE "This will </2 leave one" |
" blank line before the word leave";

Coding Multi-Line Message Strings

Sometimes, a message string needs to be coded on more than one line of a TYPE command. This can occur if indented TYPE lines, spacing information, or field prefixes extend the message string beyond the end of the line. You can wrap a message string onto the next line of a TYPE command if you:

  1. End the first line with an ending double quotation mark ("), followed by a vertical bar ( | ).
  2. Begin the second line with a double quotation mark ("). For example:
    TYPE "Name: <Employee(Cnt).First_Name" |
    "<Employee(Cnt).Last_Name" |
    "Salary: <Employee(Cnt).Salary";

Justifying Variables and Truncating Spaces

To either truncate or display trailing spaces within a field, a left angle bracket (<) or a double left angle bracket (<<) may be used, respectively. For character fields, the field values are always left justified. For example:

TYPE "*** <Car.Country ***";
TYPE "*** <<Car.Country   ***";

produces:

*** ENGLAND***
*** ENGLAND  ***

For numeric fields, the left angle bracket causes the field values to be left justified, and trailing spaces are truncated. The double left angle bracket causes the field values to be right justified and leading spaces are displayed.

For example

TYPE "*** <Car.Seats ***"
TYPE "*** <<Car.Seats ***"

produces:

*** 4***
***   4***

Writing Information to a File

You can use TYPE commands to write information to a file. The following example writes every transaction record to a log file:

FOR ALL NEXT Emp_ID Last_Name First_Name INTO Stackemp;
COMPUTE Cnt=Cnt+1;
TYPE ON TransLog "<Stackemp(Cnt).Emp_ID " |
"<Stackemp(Cnt).Last_Name" |
"<Stackemp(Cnt).First_Name";

The next example places a message into an errors log file if the salary in the stack is greater than allowed:

IF Stackemp(Cnt).Curr_Sal GT Allowamt THEN TYPE ON ErrsFile
   "Salary for employee <Stackemp.Emp_ID" |
   "is greater than is allowed.";

The last example writes three lines to the file NoEmpl if the employee is not in the data source:

MATCH Emp_ID;
ON NOMATCH TYPE ON NoEmpl "<Emp_ID"
                          "<Last_Name"
                          "<First_Name";