Sunteți pe pagina 1din 2

MC Press Online

COBOL? Did Anyone Say COBOL?


Contributed by Ernie Malaga Saturday, 31 October 1998 Last Updated Saturday, 31 October 1998

Learn more about COBOL at the MC Web site. This article explains how.

From time to time, I hear from readers who wish to see COBOL included in the magazine. And why not? COBOL is a great programming language, second only to RPG in the AS/400 arena. Unfortunately, the number of subscribers who clamor for COBOL coverage is too small to warrant publishing an article every month, and thats why you dont see more COBOL articles in the pages of MC.

This month, we decided to do something a little differenta sort of compromise. We still cannot afford to use many pages of the magazine to cover COBOL, but we can afford this one page. And in it, Ill describe two articles Ive written that you can read at your leisure on our Web site. So, without much further ado, lets see what those articles are about.

COBOL Subfile Primer

The first article, COBOL Subfile Primer, (available at http://www.midrangecomputing.com/mc/98/11) shows you how to code interactive programs in COBOL. Ive put a special emphasis on subfiles. To read this article, youll need some basic understanding of how subfiles work in RPG. Throughout, I draw parallels between RPG and COBOL to make understanding easier.

You will need this understanding if your shop is going bilingual. One of the chief ideas behind ILE is to enable you to choose the right language for the task at handand thats great since each language has unique strengths. Furthermore, considering the large number of mainframe shops that downsize to AS/400s, you can count on more shops using COBOL as time goes on. Next time you update your rsum, be sure to include COBOL among your skills.

The approach I have taken in this article is to present a project, explain how to code the program, and explain why its best done one way rather than another. The project I present is the creation of an interactive program to maintain a State Code database. The display file contains a message subfile as well as a regular list-with-selection subfile,

function keys, numbered options like WRKxxx panels have, and so on. The COBOL program needs to read the file sequentially by key and randomly, also by key. I have segregated into separate COPY members many chunks of code that you would want to use again and again, and Ive explained how to code a COPY statement in COBOL.

Subfiles are a very important part of interactive programming on the AS/400. If your shop is going to start using COBOL or if you are an RPG programmer curious to learn the language, you owe it to yourself to read this article.

Using the Proper Case in COBOL Code

My second COBOL utility (also available at http://www.midrange computing.com/mc/98/11) is designed to help


http://www.mcpressonline.com Powered by Joomla! Generated: 26 September, 2008, 04:38

MC Press Online

standardize the capitalization of COBOL code. I firmly believe that writing code using a sound style is an important step toward making your programs easier to decipher and maintain.

You can do many things to achieve code clarity: Use long, meaningful identifiers; avoid nesting code blocks too many levels deep; avoid the GO TO statement if at all possible; and place your programs paragraphs in alphabetical sequence.

All these things are fine, but to do them you have to examine the code manually; its rather difficult to write a program that would fix the code automatically, should any of these rules be violated. There is one rule, however, that can be enforced rather easily from a program: Use the right capitalization.

COBOL/400 accepts lowercase as well as uppercase, so its a simple matter to get carried away and code an ENDPERFORM in one place, an End-Perform in another, and an end-perform in a third place. Many other bizarre combinations of upper- and lowercase are possible, and the compiler will accept all of them.

The solution is not in using uppercase or lowercase all the time, but in mixing them somehow. My personal preference is to use uppercase letters for all reserved words of the program, and lowercase letters for everything else. I feel that the use of capital letters for the reserved words makes them stand out so I can quickly find a particular statement I am looking for.

This Web article presents a utility that changes the case of COBOL code according to my preferences. Try it out, and see for yourself. If you disagree with my capitalization scheme, by all means change the utility to suit your tastesbut adhere to your standard from then on. (And speaking of capitalization, Ive always felt that the name of the language ought to be in all caps; after all, its an acronym just like RPG and IBM. And who would write Rpg or Ibm?)

http://www.mcpressonline.com

Powered by Joomla!

Generated: 26 September, 2008, 04:38

S-ar putea să vă placă și