CAPÍTULO II. CASO PRÁCTICO
2.1 GENERALIDADES DE LA EMPRESA
2.1.1 ANTECEDENTES DE LA EMPRESA
5. Move through the members in the set, using SetEnumerator.moveNext().
6. Pull the value of the current member in the set, using SetEnumerator.current().
7. Search for the value in the second set, using Set.in(). If found, remove it using Set.remove().
Set setOne;
Set setTwo;
SetEnumerator enumerator;
Int value;
setOne = new Set(types::Integer);
setOne.add(1);
setOne.add(2);
setOne.add(3);
setTwo = new Set(Types::Integer);
setTwo.add(3);
setTwo.add(4);
setTwo.add(5);
while (enumerator.moveNext())
Array objects may hold values of any single type, including objects and records.
Objects of this type may be transferred to functions and methods. The values are stored sequentially.
The following methods are commonly used on Array objects:
• exists(int) - checks if a value exists in a specific position in the array.
• lastIndex() - retrieves the highest index that is used to store a value in the array.
• value(int _index, [anytype _value]) - gets or sets the value of the array member that is stored at the specified index.
• typeId() - returns the data type that the Array contains.
The following is an example using an Array object that holds three different Query objects:
Array array = new Array (Types::Class);
array.value(1, new Query());
array.value(2, new Query());
array.value(3, new Query());
Struct
Struct objects (short for structures) are entities that can hold a number of values of any X++ type. Structs are used to group information about a specific entity.
For example, there may be a need to store information about a customer's name, group and address and then treat this compound information as one item.
The following methods are commonly used on struct objects:
• add(str _fieldName, anytype _value) - adds a new field to the struct and assigns the specified value to it.
• exists(str _fieldName) - determines whether a particular field exists in a struct.
• fieldName(int _index) - returns the name of the field in the struct at the position specified.
• fields() - returns the number of fields in the struct.
• index(str _fieldName) - calculates the position of a field in the struct based on its name.
• remove(str _fieldName) - removes a field from a struct.
• value(str _fieldName, anytype _value) - gets or sets the value for a specific field.
• valueIndex(int _index, anytype _value) - gets or sets the value of the field at a specific index position in a struct.
The fields in a struct are specified by a data type and a name. Fields can be added when the struct is created by using the new() method, or they can be created after the struct has been created using the add() method. If a field is added using the add() method, the value is specified for the field at the same time, and the data type is inferred from this value. If a field is added during the instantiation of the struct, the value() or the valueIndex() method needs to be used to assign a value to it.
The fields in a struct are arranged in alphabetical order of the field names.
The following is an example using the Struct object.
Struct struct = new Struct();
int i;
// Add new fields and values struct.add("Group", "DOM");
struct.add("Name", "Jane Doe");
struct.add("Shoesize", 45);
// Prints the type and name of all items in the struct for (i = 1 ; i <= struct.fields() ; i++)
{
info(strfmt("%1 : %2", struct.fieldType(i), struct.fieldName(i)));
}
The result in the infolog should be:
• String : Group
• String : Name
• Integer : Shoesize
RecordSortedList
The RecordSortedList class inserts multiple records in a single database trip, and can hold a subset of data from a table in a particular sort order that does not exist as an index.
A RecordSortedList object holds records from a single table. The list has a unique key that is defined by the fields listed by using the sortOrder method.
Records are automatically sorted as they are inserted, they do not have to be inserted in sort sequence.
RecordSortedList objects are particularly useful for passing a result-set as a parameter.
There is no limit to the size of a RecordSortedList object, but they are
completely memory-based, so there are potential memory consumption problems.
Use a RecordSortedList in preference to a temporary table when:
• Only one sort order is needed.
• The number of records is not too high (to avoid memory problems).
Compared to temporary tables, RecordSortedList objects:
• Are faster
• Are not disk-based
• Only have one index
• Cannot be used in forms
• Require a call between the client and server per (grouped) read The following methods are commonly used on RecordSortedList objects:
• del(common) - removes a record that has a key that matches the key fields in the recordBuffer from the RecordSortedList.
• find(common) - sets the recordBuffer to the contents of the record that has a key that matches the key fields in the recordBuffer, and positions the list to the record returned.
• first() - positions the list to the first record in the list, and copies its contents to the recordBuffer.
• ins(common) - inserts a new record in a RecordSortedList, unless it is a duplicate.
• insertDatabase() - inserts multiple records on a single trip to the database.
• len() - returns the current number of records in a RecordSortedList object.
• next() - sets the record buffer to the contents of the next record in the RecordSortedList and positions the list to the record returned.
• sortOrder(fieldId, ...) - defines the fields on which the records are sorted.
• sortOrderFromContainer(container) - defines the field(s) on which the records are sorted.
The following code sample demonstrates how to insert multiple CustTable records in the same database trip, using RecordSortedList.
RecordSortedList recordSortedList;
The RecordInsertList class provides array insert capabilities in the kernel. This allows you to insert more than one record into the database at a time, which reduces communication between the application and the database.
Records are inserted only when the kernel finds the time appropriate, but they are inserted no later than the call to the add() and insertDatabase() methods. These same methods also return the accumulated number of records that are currently inserted, which allows you to keep track of when the records are actually inserted.
The array insert operation automatically falls back to classic record-by-record inserts when non-SQL based tables are used (for example, temporary tables), or
RecordInsertList is similar to RecordSortedList, but it has built-in client/server support (it automatically packs data from one tier to another when needed), and it lacks the sort order features available in RecordSortedList.
The following methods are commonly used on RecordInsertList objects:
• add(common) - inserts a new record in a RecordInsertList.
• insertDatabase() - inserts multiple records on a single trip to the database.
The following is an example using RecordInsertList to copy a bill of materials (BOM) from one BOM to another.
void copyBOM(BOMId _fromBomId, BOMId _toBomId) {
RecordInsertList bomList;
BOM bom, newBom;
bomList = new RecordInsertList(tableNum(BOM));
while select bom
where bom.BOMId == _fromBomId {
newBom.data(bom);
newBom.BOMId = _toBomId;
bomList.add(newBOM);
}
bomList.insertDatabase();
}