List of Class Objects
I know you can do this with invoke, list and add but can it be done with traditional cobol. I want to create a list of class objects. So I have a class that consists of student information
These all have properties set.
01 _studentname pic x(30) private.
01 _studentid pic x(9) private.
01 _studentmajor pic x(11) private.
01 _studentclassification pic x(9) private.
01 _studentsexcode pic x(6) private.
01 _studentgpr pic 9(1)V9(4) private usage comp-3.
01 _majorcount pic 9(2) private.
01 _classcount pic 9(2) private.
01 _sexcount pic 9(2) private.
Then in another cobol program I create an instance of this with a list. So I have.
01 tso type List[type TO_Students].
When I create the list with these objects, I invoke::tso::Add(new TO_Students(prop StudentName...) etc.
How can this be done in a traditional cobol manner wherein I create tso, then write tso with the objects.
RE: List of Class Objects
I assume you're using managed COBOL - that is, COBOL for .NET or JVM - and not native OO COBOL.
I'll also assume you're using a relatively recent version of Visual COBOL, as you've mysteriously neglected to supply this key piece of information.
Managed COBOL has portable syntax for working with list containers. See the product documentation:
So, for example:
01 tso list[type TO_Students].
end method new.
method-id AddStudent(studentName as string, ...).
declare student = new TO_Student(studentName, ...)
sync on tso
write tso from student
end method AddStudent.
Out of curiosity, why are you using pic x(n) rather than managed types such as string in your TO_Student class?