Cobol Did Anyone Say Cobol

Embed Size (px)

Citation preview

  • 7/30/2019 Cobol Did Anyone Say Cobol

    1/2

    COBOL? Did Anyone Say COBOL?

    Contributed by Ernie MalagaSaturday, 31 October 1998Last 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 agreat programming language, second only to RPG in the AS/400 arena. Unfortunately, the number of subscribers whoclamor for COBOL coverage is too small to warrant publishing an article every month, and thats why you dont see moreCOBOL 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 pagesof the magazine to cover COBOL, but we can afford this one page. And in it, Ill describe two articles Ive written that youcan 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 tocode interactive programs in COBOL. Ive put a special emphasis on subfiles. To read this article, youll need some basicunderstanding of how subfiles work in RPG. Throughout, I draw parallels between RPG and COBOL to makeunderstanding easier.

    You will need this understanding if your shop is going bilingual. One of the chief ideas behind ILE is to enable you tochoose 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 usingCOBOL 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 itsbest done one way rather than another. The project I present is the creation of an interactive program to maintain a StateCode 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 filesequentially by key and randomly, also by key. I have segregated into separate COPY members many chunks of codethat 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 COBOLor 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

    MC Press Online

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

  • 7/30/2019 Cobol Did Anyone Say Cobol

    2/2

    standardize the capitalization of COBOL code. I firmly believe that writing code using a sound style is an important steptoward 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 manylevels 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 thatwould fix the code automatically, should any of these rules be violated. There is one rule, however, that can be enforcedrather 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 END-PERFORM in one place, an End-Perform in another, and an end-perform in a third place. Many other bizarrecombinations 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 isto use uppercase letters for all reserved words of the program, and lowercase letters for everything else. I feel that theuse of capital letters for the reserved words makes them stand out so I can quickly find a particular statement I amlooking for.

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

    MC Press Online

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