Case sensitive

How do I make variable case sensitive.  I would like to make policyNumber and PolicyNumber different variables.  How is that done?

 

      

working-storage section.

       01 policyNumber type String property no set.

      

method-id New.

procedure division using by value policyNumber as type String.

 Set PolicyNumber to policyNumber.

end method.

Tags:

  • Verified Answer

    COBOL does not allow data names to differ only by case, but you can distinguish an instance or static field from a method local variable or parameter by using the self:: prefix like this:

    working-storage section.

          01 PolicyNumber String property no set.

    method-id New.

    procedure division using by value PolicyNumber as String.

    Set self::PolicyNumber to PolicyNumber.

    end method.

    If you really want two properties (or public fields to differ only by case, you could use the AS phrase:

          01 PolicyNumber String property no set .

          01 PolicyNumber2 String property no set as "policyNumber".

    ...but I can't really think of any reasons one might want to do this...

  • The reason I was doing this was to stick to C# naming conventions.  I will probably use self::fieldname or just change the name thanks.

  • Other .NET languages have similar constraints, most notably VB.NET. This has been recognised since the earliest days of .NET. Microsoft introduced the Common Language Specification (CLS) to ensure .NET libraries could be effectively used by different languages, and one of it's rules is that names cannot differ just by case.

    Related to this, if you need to use a Cobol reserved word as the name of a dataname, then you can prefix it with hash e.g. #move if you need a member name "move".