FTYPE( ) function

Returns a character identifying the data category of a field or variable, or the type of an Analytics project item.

Syntax

FTYPE(field_name_string)

Parameters

Name Type Description
field_name_string character

A field name, variable name, or Analytics project item name.

Enclose field_name_string in quotation marks:

 FTYPE("Amount")

Output

Character. This function returns one of the following characters, which indicates the field, variable, or Analytics project item type:

  • "C" Character field
  • "N" Numeric field
  • "D" Datetime field
  • "L" Logical field
  • "c" Character variable
  • "n" Numeric variable
  • "d" Datetime variable
  • "l" Logical variable
  • "b" Analytics script
  • "y" Analytics table layout
  • "w" Analytics workspace
  • "i" Analytics index
  • "r" Analytics report
  • "a" Analytics log file
  • "U" Undefined

Examples

Basic examples

The following example assigns a value of 4 to the num variable and then checks the type.

Returns "n":

ASSIGN num = 4
FTYPE("num")

Advanced examples

Testing for the data type of a field

You have a script or analytic that requires a numeric Amount field, and you need to test that the field is the correct type before running the script.

The following command only runs Script_1 if Amount is a numeric field:

OPEN Invoices
DO Script_1 IF FTYPE("Amount") = "N"

Testing if a table or Analytics project item exists

The following command only runs Script_1 if a table named Invoices is present in the project:

DO Script_1 IF FTYPE("Invoices") <> "U"

Testing the runtime environment

You can use FTYPE to determine if an analytic is running in Analytics, or on Analytics Exchange or in the Analysis App window.

If an analytic is running on Analytics Exchange, or in the Analysis App window, 'ax_main' is equal to 'b':

IF FTYPE('ax_main') = 'b' v_running_in_ax_or_analysis_app = T

If an analytic is running in Analytics, 'ax_main' is not equal to 'b':

IF FTYPE('ax_main') <> 'b' v_running_in_ax_or_analysis_app = F

The ability to detect the runtime environment allows you to design a single script that executes different blocks of codes depending on which application it is running in.