Way back in the early 80’s when I started developing in COBOL, code was always written entirely in uppercase, due to the limitations of the keypunch machines used in those days. We’ve come a long way since then, and today’s COBOL is pretty easy-going. It isn’t at all particular about whether you use uppercase or lowercase when you enter your code.
The following lines of code will all compile and have identical results when executed:
MOVE 1 TO NUMBER-FIELD.
move 1 to number_field.
MOVE 1 to number-field.
move 1 to NUMBER_FIELD.
Move 1 to Number-Field.
mOve 1 to nUmBer_FieLd.
Notice that in the examples above I’ve sometimes used a hyphen, and other times used an underscore. COBOL does not differentiate between these two characters, and that can sometimes drive you crazy when you’re searching for a particular variable name. If you can’t find the variable name in the code with a hyphen, try using an underscore.
Lately, I’ve found that I prefer to enter my code in lowercase, as it just looks a little friendlier. I guess that online email etiquette course I was forced to endure at work may have had some effect on me. Now when I review a program that is written entirely in uppercase, it appears to be shouting at me. Yes, I have created most of the code samples on my blog in uppercase, mainly to avoid confusing any newbies, but please feel free to use whichever case you prefer. Either way, COBOL doesn’t complain.
One thing to note, though, if you decide to get chummy with your code and convert all of the verbiage in your program from uppercase to lowercase, you do still need to be aware of case when you read an external file or database table. For example, if you read an external file containing a field called yes-no-flag, and that field contains an upper case “Y”, you must use an upper case “Y” in your “if” statement. If not, your program will not have the results you expected.
See the problem? If the field yes-no-flag contains an uppercase “Y”, and you test for a lowercase “y”, the negative path will be taken. COBOL is case-sensitive for anything between quotes, and you must be aware of this when coding.
I hope I’ve made my “case”.