DO Values with Arrays of Objects
- Last UpdatedOct 24, 2022
- 1 minute read
Imagine that you have already defined an object type EMPLOYEE which contains a member of type STRING. You then create an array of EMPLOYEE objects and set the Name member of each of each object.
!MyEmployees[1] = object EMPLOYEE()
!MyEmployees[2] = object EMPLOYEE()
!MyEmployees[3] = object EMPLOYEE()
!MyEmployees[1].Name = 'James'
!MyEmployees[2].Name = 'Joe'
!MyEmployees[3].Name = 'Mike'
You then want to create a new array containing just the names of the employees.
!Names = ARRAY()
do !Person VALUES !MyEmployees
!Names.Append(!Person.Name)
enddo
Each time round the do-loop, the do-variable becomes an object of the appropriate type, even if the array is a heterogeneous mixture of objects.