4D v16.3

Data Types

Home

 
4D v16.3
Data Types

Data Types  


 

 

4D fields, variables, and expressions can be of the following data types:

Data TypeFieldVariableExpression
String (see note 1)YesYesYes
Number (see note 2)YesYesYes
DateYesYesYes
TimeYesYesYes
BooleanYesYesYes
PictureYesYesYes
PointerNoYesYes
BLOB (see note 3)YesYesNo
Array (see note 4)NoYesNo
Integer 64 bits (see note 5)YesNoNo
Float (see note 5)YesNoNo
Object (see note 6)YesYesYes
UndefinedNoYesYes

Notes:

  1. String includes alphanumeric field, fixed length variable, and text field or variable.
  2. Number includes Real, Integer, and Long Integer field and variable.
  3. BLOB is an acronym for Binary Large OBject. For more information about BLOBs, see the section BLOB Commands.
  4. Array includes all types of arrays. For more information, see the chapter Arrays.
  5. The Integer 64 bits and Float types are only managed via SQL. It is not recommended to work with them via the 4D language because in this case they are converted into the Real type which could lead to some loss of accuracy.
  6. Objects let you store and manipulate structured data. They are managed using the commands found in the "Objects (Language)" theme.

String  

String is a generic term that stands for:

  • Alphanumeric fields or variables: an Alphanumeric field may contain from 0 to 255 characters (limit set when field is defined).
  • Text fields or variables: a Text field, variable, or expression may contain from 0 to 2 GB of text..
  • Any String or Text expression

There is no difference between a string or text variable.

You can assign a string to a text field and vice-versa; 4D does the conversion, truncating if necessary. You can mix string and text in an expression.

Note: In the 4D Language Reference manual, both string and text parameters in command descriptions are denoted as String, except when marked otherwise.

Number  

Number is a generic term that stands for:

  • Real Field, variable or expression
  • Integer field, variable or expression
  • Long Integer field, variable or expression

The range for the Real data type is ±1.7e±308 (13 significant digits)
The range for the Integer data type (2-byte Integer) is -32,768..32,767 (2^15..(2^15)-1)
The range for the Long Integer data type (4-byte Integer) is -2^31..(2^31)-1

You can assign any Number data type to another; 4D does the conversion, truncating or rounding if necessary. However, when values are out of range, the conversion will not return a valid value. You can mix Number data types in expressions.

Note: In the 4D Language Reference manual, no matter the actual data type, the Real, Integer, and Long Integer parameters in command descriptions are denoted as number, except when marked otherwise.

Date  

  • A Date field, variable or expression can be in the range of 1/1/100 to 12/31/32,767.
  • Using the US English version of 4D, a date is ordered month/day/year.
  • If a year is given as two digits, it is assumed to be in the 1900’s if the value is greater than or equal to 30, and the 2000’s if the value is less than 30 (this default can be changed using the SET DEFAULT CENTURY command).
  • Although the representation mode for dates by C_DATE can work with dates up to the year 32 767, certain operations passing through the system impose a lower limit. 

Note: In the 4D Language Reference manual, Date parameters in command descriptions are denoted as Date, except when marked otherwise.

Since dates in JavaScript are objects, they are sent to 4D as text containing their JSON form like any other object. This principle is implemented in particular when using 4D Mobile or Web Area.
The JSON form of the JavaScript Date object follows the ISO 8601 standard, for example "2013-08-23T00:00:00Z".

It is your responsibility to convert this text into a 4D date (C_DATE). Two solutions are available:

  • Using the JSON Parse command:
     C_TEXT($1// reception of a date in ISO format
     C_DATE($d)
     $d:=JSON Parse("\""+$1+"\"";Is date))
  • Using the Date command:
     C_TEXT($1// reception of a date in ISO format
     C_DATE($d)
     $d:=Date($1)

Note the difference between these two solutions: JSON Parse respects the conversion mode set using the SET DATABASE PARAMETER (if any), while Date is not subject to this. Conversion using the Date command always takes the local time zone into account.

Time  

  • A Time field, variable or expression can be in the range of 00:00:00 to 596,000:00:00.
  • Using the US English version of 4D, time is ordered hour:minute:second.
  • Times are in 24-hour format.
  • A time value can be treated as a number. The number returned from a time is the number of seconds that time represents. For more information, see the section Time Operators.

Note: In the 4D Language Reference manual, Time parameters in command descriptions are denoted as Time, except when marked otherwise.

Boolean  

A Boolean field, variable or expression can be either TRUE or FALSE.

Note: In the 4D Language Reference manual, Boolean parameters in command descriptions are denoted as Boolean, except when marked otherwise.

Picture  

A Picture field, variable or expression can be any Windows or Macintosh picture. In general, this includes any picture that can be put on the pasteboard or read from the disk using 4D or Plug-In commands.

Note: In the 4D Language Reference manual, Picture parameters in command descriptions are denoted as Picture, except when marked otherwise.

Pointer  

A Pointer variable or expression is a reference to another variable (including arrays and array elements), table, or field. There is no field of type Pointer.

For more information about Pointers, see the section Pointers.

Note: In the 4D Language Reference manual, Pointer parameters in command descriptions are denoted as Pointer except when marked otherwise.

BLOB  

A BLOB field or variable is a series of bytes (from 0 to 2 GB in length) that you can address individually or by using the BLOB Commands. There is no expression of type BLOB.

Note: In the 4D Language Reference manual, BLOB parameters in command descriptions are denoted as BLOB.

Object  

Variables, fields or expressions of the Object type can contain various types of data. The structure of "native" 4D objects is based on the classic principle of "property/value" pairs. The syntax of these objects is based on JSON notation, but does not follow it completely. 

  • A property name is always a text, for example "Name".
  • A property value can be of the following type:
    • number (Real, Integer, etc.)
    • text
    • array (text, real, Boolean, object, pointer)
    • null
    • Boolean
    • pointer (stored as such, evaluated using the JSON Stringify command or when copying),
    • date (format "\"YYYY-MM-DDTHH:mm:sssZ\"")
    • object (objects can be nested on several levels)

You manage Object type variables, fields or expressions using the commands available in the Objects (Language) theme. Note that specific commands of the Queries theme such as QUERY BY ATTRIBUTE and QUERY SELECTION BY ATTRIBUTE can be used to carry out processing on object fields. 

Undefined is not actually a data type. It denotes a variable that has not yet been defined. A function (a project method that returns a result) can return an undefined value if, within the method, the function result ($0) is assigned an undefined expression (an expression calculated with at least one undefined variable). A field cannot be undefined (the Undefined command always returns False for a field).

Array  

Array is not actually a data type. The various types of arrays (such as Integer Array, Text Array, and so on) are grouped under this title. Arrays are variables—there is no field of type Array, and there is no expression of type Array. For more information about arrays, see the section Arrays.

Note: In the 4D Language Reference manual, Array parameters in command descriptions are denoted as Array, except when marked otherwise (i.e., Text Array, Numeric Array, etc.).

The 4D language contains operators and commands to convert between data types, where such conversions are meaningful. The 4D language enforces data type checking. For example, you cannot write: "abc"+0.5+!12/25/96!-?00:30:45?. This will generate syntax errors.

The following table lists the basic data types, the data types to which they can be converted, and the commands used to do so:

Data Type to Convertto Stringto Numberto Dateto Time
String(*)NumDateTime
Number (**)String
DateString
TimeString
BooleanNum
ObjectJSON Stringify

(*) Strings formatted in JSON can be converted into scalar data or into objects using the JSON Parse command.
(**) Time values can be be treated as numbers.

Note: In addition to the data conversions listed in this table, more sophisticated data conversions can be obtained by combining operators and other commands.



See also 

Arrays
Character Reference Symbols
Constants
Control Flow
Identifiers
Methods
Operators
Pointers
String
Type
Variables

 
PROPERTIES 

Product: 4D
Theme: Language definition

 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)