Data Types

Conventional data types include number, date, string. Use them for basic computing. Object data types instantiate objects from PeopleTools classes. The appropriate use of each data type is demonstrated where the documentation discusses PeopleCode that uses that data type.

Declare variables before you use them.

This section discusses:

  • Conventional data types.

  • Object data types.

PeopleCode includes these conventional data types:

  • any

    When variables and function return values are declared as any, the data type is indeterminate, enabling PeopleTools to determine the appropriate type of value based on context. Undeclared local variables are any by default.

  • boolean

  • date

  • datetime

  • float

  • integer

    Note: The float and integer data types should be used instead of Number only when a performance analysis indicates that the increased speed is useful and an application analysis indicates that the different representations will not affect the results of the computations.

  • number

  • string

  • time

Considerations for Float, Integer, and Number Types

The Integer type is a number represented as a 32-bit signed twos complement number, so it has a range of -2,147,483,648 to 2,147,483,647.

The Float type is a number represented using the machine floating binary point (double precision) representation. This floating binary point representation is not appropriate for exact calculations involving decimal fractions; in particular, calculations involving money. For example, because a tenth (1/10 or .1) cannot be exactly represented in floating binary point, a floating binary point sum of .10 + .10 is not be equal to .20.

The Number type has a size limit of 34 digits, not including the decimal point, with a maximum of 32 digits to the right of the decimal point. Since the Number type is a floating decimal point representation, it is the appropriate data type for calculations involving money.

Operations (other than division) are done using integer arithmetic if the operands are both integers and the destination is an integer, even if the variable is declared as the Number type. The destination is considered to be an integer if one of the following is True:

  • The destination is an assignment to an integer variable or parameter.

  • The destination is an array subscript.

  • The destination is the right-hand operand of a comparison and the left-hand operand is an integer.

  • The destination is a when-expression part of an evaluate statement, and the expression evaluated at the start of the evaluate statement is an integer.

  • The destination is a for-loop initial, limit, or step expression and the control variable of the for-loop is an integer.

Division (the / operator) is never performed using integer arithmetic. It is always performed using the floating-decimal-point arithmetic, even if the result variable is declared as an Integer type.

Follow these recommendations for assigning types to numbers:

  • Use Number for most application data values.

  • Use Integer when you are counting items, such as rows in a rowset.

  • Use Float only when you are tuning the code for performance (after it is already working).

    In addition, you should only use the Float type when you are certain that the resulting loss of precision will not affect the application and that the increase in the speed of the computation makes a difference to the transaction. In general, few applications should use the Float type.

For most classes in PeopleTools, you need a corresponding data type to instantiate objects from that class.

See Classes and Objects.

PeopleCode includes these built-in component buffer access types:

  • Field

  • Record

  • Row

  • Rowset

PeopleCode also includes these built-in display data types:

  • AnalyticGrid

  • Chart

  • Gantt

  • Grid

  • GridColumn

  • OrgChart

  • Page

  • RatingBoxChart

PeopleCode also includes these built-in internet script data types:

  • Cookie

  • Request

  • Response

PeopleCode includes numerous miscellaneous data types—for example, Array, Chart, Exception, File, Message, XmlDoc, among many others.

API Object Types

Use this data type for any ApiObject, such as a session object, a tree object, a component interface, a portal registry, and so on.

The following ApiObject data type objects can be declared as type Global:

  • Session

  • PSMessages collection

  • PSMessages

  • All tree classes (trees, tree structures, nodes, levels, and so on)

  • All query classes

All other ApiObject data type objects (such as all the PortalRegistry classes) must be declared as Local.