Type

type returns an integer value representing the data type of a variable.

Syntax

type(VARIA)
  • VARIA is a Sage X3 variable.
Type of variable Value returned Declaration keyword used for this type
Variable that does not exist -1 none
Tiny integer in (0,255) range 1 Tinyint
Short integer in (-32768,32767) range 2 Shortint
Date in [1/1/1600], [31/12/9999] range 3 Date
Long integer (4 bytes) 4 Integer
Floating point number(server dependent, and obsolete) 5 Float
Double floating point number(server dependent, and obsolete) 6 Double
Decimal number (32 digits precision) 7 Decimal
Character string of maximum length equal to L 10+L Char
Binary object (BLOB) 522 Blbfile
Long character object (CLOB) 523 Clbfile
Reference to an instance 524 Instance
Unique ID 525 Uuident
Date time 526 Datetime

Example

# This function  returns a string describing the variable sent and its contents
Funprog FORMATTED_VALUE(VARIA)
Local Integer TYP
  TYP=type(VARIA)
  Case TYP:
    When -1: End "The variable doesn't exist"
    When 1 : End "Tiny integer"-format$("N:3#",VARIA)
    When 2 : End "Short integer"-format$("N:6#",VARIA)
    When 3 : End "Date"-format$("D:4Y[-]2M[-]2D",VARIA)
    When 4 : End "Long integer"-format$("N:11#",VARIA)
    When 5 : End "Floating number"-format$("N:12F",VARIA)
    When 6 : End "Double Floating number"-format$("N:12F",VARIA)
    When 7 : End "Decimal"-format$("N:32F",VARIA)
    When 522 : End "Binary object"
    When 523 : If len(VARIA)<100 : End "Long string of"-num$(len(VARIA))-"characters:"+left$(varia,100)
               Else End "(long string of"-num$(len(VARIA))-"characters starting with:"+left$(VARIA,20)+"..."
               Endif
    When 524 : If VARIA=NULL 
                 End "Null instance reference"
               Else
                 End "Instance of "+VARIA.Objecttype
               Endif
    When 525 : End "UUID"-num$(VARIA)
    When 526 : End "Date time"-num$(VARIA)
    When Default : If TYP>10 and TYP<266
                     End "String of"-num$(TYP-10)-"characters maximum with a length of"-num$(len(VARIA))
&                        +string$(len(VARIA)<=20,":"-VARIA)+string$(len(VARIA)>20," starting with:"-left$(VARIA,20)+"...")
                   Endif
  Endcase
End "Unknown type"

Comment

A common test used to verify that a variable exists is done by the following condition:
  If type(VARIA)>0
     # The variable exists
  Else
     # The variable doesn't exist
  Endif

See also

Tinyint, Shortint, Date, Integer, Float, Double, Decimal, Char, Clbfile, Blbfile, Uuident, Datetime, Instance.