11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

COBOL 91pr<strong>of</strong>essional programmers. (This theme <strong>of</strong> “programmingwithout programmers” would recur with regard to otherlanguages such as RPG, BASIC, <strong>and</strong> various database systems,always with limited success.)Program StructureA COBOL program as a whole resembles a business form inthat it is divided into specific sections called divisions, eachwith required <strong>and</strong> optional items.The Identification division simply identifies the programmer<strong>and</strong> gives some information about the program:IDENTIFICATION DIVISION.PROGRAM-ID WEEKLY REPORT.AUTHOR JAMES BRADLEY.DATE-WRITTEN DECEMBER 10, 2000.DATE-COMPILED DECEMBER 12, 2000.REMARKS THIS IS AN EXAMPLE PROGRAM.The Environment division contains specifications aboutthe environment (hardware) for which the program willbe compiled. In some cases (for example, microcomputerversions <strong>of</strong> COBOL) it may not be needed. In other cases, itmight simply have a Configuration section that specifies themachine to be used:ENVIRONMENT DIVISION.CONFIGURATION SECTION.SOURCE-COMPUTER IBM-370.OBJECT-COMPUTER IBM-370.(The reason for the separate source <strong>and</strong> object computers isthat programs were sometimes compiled on one computerfor use on another, <strong>of</strong>ten smaller, one.)In some cases, the Environment Division must alsoinclude an Input-Output section that specifies devices <strong>and</strong>files that will be used by the program. For example:INPUT-OUTPUT SECTION.FILE-CONTROL.SELECT STUDENT-FILE ASSIGN TO READERSELECT STUDENT-LISTING ASSIGN TO LOCAL-PRINTERThe Data division gives a description <strong>of</strong> the data records<strong>and</strong> other items that will be processed by the program.It is roughly comparable to the declarations <strong>of</strong> variablesin languages such as Pascal, C, or BASIC. Since COBOLfocuses on the processing <strong>of</strong> file records <strong>and</strong> the formatting<strong>of</strong> reports, it tends to have fewer data types than manyother languages, but it makes it easier to describe the kinds<strong>of</strong> data structures commonly used in business applications.For example, it is easy to describe records that have fields<strong>and</strong> subfields by using level numbers to indicate the relationship:DATA DIVISION.FILE SECTION.FD INFILELABEL RECORDS ARE OMITTED.01 STUDENT-DATA.02 STUDENT-ID PIC 999999.02 STUDENT-NAME.03 LAST-NAME PIC X(15).03 INITIAL PIC X.03 FIRST-NAME PIC X(10).02 GPA PIC 9.99The “PIC” or picture clause specifies the type <strong>of</strong> data(using 9’s <strong>and</strong> a decimal point for numbers <strong>and</strong> X for text)<strong>and</strong> the length. In addition to specifying the input records,the Data division <strong>of</strong>ten includes items that specify the format<strong>of</strong> the lines <strong>of</strong> output that are to be printed.The Procedure division provides the statements thatperform the actual data manipulation. Procedures can beorganized as subroutines (roughly equivalent to proceduresor functions on other languages). Some sample procedurestatements are:READ STUDENT-DATA INTO STUDENT-WORK-RECORDAT END MOVE ‘E’ TO PROC-FLAG-STGO TO EXIT-PRINTADD 1 TO TOTAL-STUDENT-RECORDSMathematical expressions can be computed using aCompute statement:COMPUTE GPA = TOTAL-GRADES / CLASSESBranching (if) statements are available, <strong>and</strong> looping isprovided by the Perform statement, for example:PERFORM 100-PRINT-LINEUNTIL LINES-FL IS EQUAL TO ‘E’(As with older versions <strong>of</strong> BASIC, subroutines are numbered.)Impact <strong>and</strong> ProspectsFrom the 1960s through the 1980s, COBOL became theworkhorse language for business applications for mainframe<strong>and</strong> mid-size computers, <strong>and</strong> it is still widely usedtoday. (The concerns about possible problems at the end<strong>of</strong> the century <strong>of</strong>ten involved older programs written inCOBOL, see y2k problem.) The main line <strong>of</strong> programminglanguage evolution bypassed COBOL <strong>and</strong> went throughAlgol (a contemporary <strong>of</strong> COBOL) <strong>and</strong> on into Pascal, C,<strong>and</strong> other block-structured languages (see also structuredprogramming).Some modern versions <strong>of</strong> COBOL have incorporatedlater developments in structured programming (such asmodularization) <strong>and</strong> even object-oriented design. COBOLhas also shown considerable versatility in accommodatingmodern development frameworks, including Micros<strong>of</strong>t.NETas well as processing now-ubiquitous XML data. Nevertheless,usage <strong>of</strong> COBOL continues to decline slowly as developersincreasingly turn to languages such as C++, scriptinglanguages, or database development systems.Further ReadingBivar de Oliveria, Rui. The Power <strong>of</strong> COBOL: For Systems Developers<strong>of</strong> the 21st Century. Charleston, S.C.: BookSurge, 2006.COBOL Portal. Available online. URL: http://www.cobolportal.com. Accessed June 8, 2007.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!