Share via


Struct Class

A struct holds several values of any X++ type, to group the information about a specific entity.

Syntax

class Struct extends Object

Run On

Called

Methods

  Method Description
Gg926473.pubmethod(en-us,AX.60).gif add Adds a new item to the struct and assigns the specified value to it.
Gg926473.pubmethod(en-us,AX.60).gif cancelTimeOut Cancels a previous method call to the setTimeOut method. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif definitionString Returns a description of the names and types of the elements in the struct.
Gg926473.pubmethod(en-us,AX.60).gif equal Determines whether the specified object is equal to the current one. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif exists Determines whether a particular item exists in a struct.
Gg926473.pubmethod(en-us,AX.60).gif fieldName Returns the name of the item in the struct at the specified position.
Gg926473.pubmethod(en-us,AX.60).gif fields Returns the number of items in the struct.
Gg926473.pubmethod(en-us,AX.60).gif fieldType Returns the data type of the item in the struct at the specified position.
Gg926473.pubmethod(en-us,AX.60).gif getTimeOutTimerHandle Returns the timer handle for the object. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif handle Retrieves the handle of the class of the object. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif index Calculates the position of an item in the struct based on its name.
Gg926473.pubmethod(en-us,AX.60).gif new Creates a struct. (Overrides the new Method.)
Gg926473.pubmethod(en-us,AX.60).gif notify Releases the hold on an object that has called the wait method on this object. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif notifyAll Releases a lock on the object that was issued by the wait method on this object. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif objectOnServer Determines whether the object is on a server. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif owner Returns the instance that owns the object. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif pack Serializes the current instance of the Struct class.
Gg926473.pubmethod(en-us,AX.60).gif remove Removes an item from a struct.
Gg926473.pubmethod(en-us,AX.60).gif setTimeOut Sets up the scheduled execution of a specified method. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif toString Returns a string that describes the contents of the struct. (Overrides the toString Method.)
Gg926473.pubmethod(en-us,AX.60).gif usageCount Returns the current number of references, that is, the value of the reference counter, that the object has. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif value Gets or sets the value for a specified item in a struct.
Gg926473.pubmethod(en-us,AX.60).gif valueImage Returns a string that describes the value of the item at a particular position in the struct.
Gg926473.pubmethod(en-us,AX.60).gif valueIndex Gets or sets the value of the item at a specified position in a struct.
Gg926473.pubmethod(en-us,AX.60).gif wait Pauses a process. (Inherited from Object.)
Gg926473.pubmethod(en-us,AX.60).gif xml Returns an XML string that represents the current object. (Overrides the xml Method.)
Gg926473.pubmethod(en-us,AX.60).gif Gg926473.static(en-us,AX.60).gif ::create Creates a struct from a container that is obtained from a prior call to Struct.pack.
Gg926473.pubmethod(en-us,AX.60).gif Gg926473.static(en-us,AX.60).gif ::createFromXML
Gg926473.pubmethod(en-us,AX.60).gif Gg926473.static(en-us,AX.60).gif ::equal Determines whether two structs are equal.
Gg926473.pubmethod(en-us,AX.60).gif Gg926473.static(en-us,AX.60).gif ::merge Combines two structs to create a new struct.

Top

Remarks

A struct (short for structure) is an entity that can hold several values of any X++ type. Structs are used to group information about a specific entity. For example, you might want to store information about a customer's name, age and address and then treat this compound information as one item.

The items in a struct are specified by a data type and a name. Items are added when the struct is created by using the new method, or they are created after the struct has been created by using the add method. If you add an item by using the add method, you specify the value for the item at the same time, and the data type is inferred from this value. If you add an item during the instantiation of the struct, you need to use the value or the valueIndex method to assign a value to it.

The items in a struct can be of any of the data types found in the Types system enum, including: string, integer, real, date, container, record, and class.

The items in a struct are arranged in alphabetical order of the item names.

The fields in a struct can be traversed by using the fields, fieldName, and fieldType methods. Structs can be packed into containers and later restored by using the Struct::create method.

Structs have some similarities to X++ containers. However, a container is a value type and is built into the X++ language. You can create nested containers, but you cannot create nested structs.

X++ classes can store information in much the same way as structs. But although classes can supply methods to manipulate the data, no such facility is provided for structs, and there is no concept of overriding or extension. Classes can only be created in the AOT, but structs exist solely in the context of the code in which they are created. Class member variables are private to the class, so accessor functions must be coded for them for the values to be used from outside the class. The items within a struct are publicly accessible.

Examples

The following example creates a struct with two items and then assigns values to those items. A new item is then added by using the Struct.add method; the data type of the item is inferred from the value assigned to it. The struct is then packed into a container and used to create a new struct, a copy of the original struct.

{ 
    Struct s = new struct ("int age; str name"); 
    Struct copy; 
    container c; 
    int i; 
     
    // Add values to the items 
    s.value("age", 25); 
    s.value("name", "Jane Dow"); 
  
  // Add a new item; data type is inferred from value 
    s.add("Shoesize", 45); 
  
    // Print the definition of the struct 
    print s.definitionString(); 
  
    // Prints the type and name of all items in the struct 
    for (i =  1;   i <= s.fields();i++) 
    { 
         print s.fieldType(i), " ", s.fieldName(i); 
    }  
  
    // Pack the struct into a container and restore it into copy 
    c = s.pack(); 
    copy = Struct::create(c); 
    print copy.definitionString(); 
    pause; 
} 

Inheritance Hierarchy

Object Class
  Struct Class

See Also

Set Class