Skip to main content

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.

class-id TO_Students.
       Working-Storage Section.
               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.

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.

class-id TO_Students.
       Working-Storage Section.
               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.

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:

https://www.microfocus.com/documentation/enterprise-developer/ed40pu4/ED-VS2017/H2TYRHTYPE01.html

https://www.microfocus.com/documentation/enterprise-developer/ed40pu4/ED-VS2017/GUID-4ED9B3DC-81E8-4184-8D41-C4A6B2E4BEC4.html

https://www.microfocus.com/documentation/enterprise-developer/ed40pu4/ED-VS2017/GUID-03EEDEF5-7229-4341-94F8-F3E5664D6C56.html

So, for example:

01 tso list[type TO_Students].

method-id new.
create tso
end method new.

method-id AddStudent(studentName as string, ...).
declare student = new TO_Student(studentName, ...)
sync on tso
write tso from student
end-sync
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?