Example of Enumeration

Trying to figure out how to use enumerations.  Can anybody help?

I also noticed that visual Cobol doesn't support the Enumeration TryParse?  The goal is to edit the domain extension and ignoring the case.

 

Here is what I have so far.

enum-id DomainExtensions.
01  binary-long.
      78  com.        
      78  edu.        
      78  gov.       
end enum.

 

Now trying to use it is the problem. 

      

method-id ValidateDomain private

01 domainExt type DomainExtensions.

procedure division using by value domainString as String

                   returning validDomain as type Boolean.

   set validDomain to false.

   set domainExt to new DomainExtensions()

   set domainExt to (type DomainExtensions)::Enum::Parse(type DomainExtensions, domainString, true)

   set domainExt to type (DomainExtensions)::Enum::Parse(type DomainExtensions, domainString, true)          

   set domainExt to type (type DomainExtensions)::Enum::Parse(type DomainExtensions, domainString, true)          

   set domainExt to type Enum(type DomainExtensions)::Parse(type DomainExtensions, domainString, true)

   set domainExt to type Enum::Parse(type DomainExtensions, domainString, true).

   if domainExt = type DomainExtensions::com

end method.

Tags:

Parents
  • Verified Answer

    Are you using Visual COBOL 2.2 or an earlier release?

    The following full program compiles fine for me in Visual COBOL 2.2:

           program-id. Program1 as "testenum.Program1".
           data division.
           working-storage section.
           01 validDomain condition-value.
           01 myobj type MyClass.
           procedure division.
               set myobj to new MyClass
               set validDomain to myobj::ValidateDomain("GOV")
               
               goback.
               
           end program Program1.
           class-id MyClass.
           method-id ValidateDomain.
           01 domainExt type DomainExtensions.
           
           procedure division using by value domainString as String
                       returning validDomain as type Boolean.
                
                set validDomain to type Enum::TryParse(domainString, true, domainExt)
                
           end method.
    
           end class.
           
           enum-id DomainExtensions.
           01  binary-long.
               78  com.        
               78  edu.        
               78  gov.        
           end enum.
    
Reply
  • Verified Answer

    Are you using Visual COBOL 2.2 or an earlier release?

    The following full program compiles fine for me in Visual COBOL 2.2:

           program-id. Program1 as "testenum.Program1".
           data division.
           working-storage section.
           01 validDomain condition-value.
           01 myobj type MyClass.
           procedure division.
               set myobj to new MyClass
               set validDomain to myobj::ValidateDomain("GOV")
               
               goback.
               
           end program Program1.
           class-id MyClass.
           method-id ValidateDomain.
           01 domainExt type DomainExtensions.
           
           procedure division using by value domainString as String
                       returning validDomain as type Boolean.
                
                set validDomain to type Enum::TryParse(domainString, true, domainExt)
                
           end method.
    
           end class.
           
           enum-id DomainExtensions.
           01  binary-long.
               78  com.        
               78  edu.        
               78  gov.        
           end enum.
    
Children
No Data