COBOL COmmon Business Oriented Language Work began in 1959 and has never stopped
CODASYL Conference on Data Systems Languages Primarily Business Wanted a language designed for their needs. The resulting language reflected business needs and the computing environment.
File Formatting You can read to or from records specifying precision by digit. While it is different than what we are used to, it is as powerful as newer languages for records.
Records COBOL understands the idea of a record Has incorporated support for composite and atomic attributes from the beginning This understanding avoids some of the more tedious aspects of programming with records by minimizing parsing.
Computing Environment Words and Bytes: Many assumptions we make every day the COBOL programmer could not rely on. Environment Division: Specifies to the compiler and programmer the target environments. More or less just comments now, useful for maintenance.
Punch Card
Changes with Time Certainly the most difficult part of COBOL is that all new versions must be backwards compatible. It is possible to get nearly 817 keywords (ca.1985)
Artifacts Program line numbers for program cards Spacing (Areas A & B) While not as familiar or as “clean” as {} block structures, it does add a visual structure to a program
Divisions and Sections Sections subdivide four primary divisions Provides a top level organization for programs. More later.
Procedural Paradigm Supported but not enforced Centers mostly on GOTO (and in newer versions, IF/THEN) All procedures names are labels. Newer versions support some OO features.
IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION FOUR PROGRAM DIVISIONS
IDENTIFICATION DIVISION Provides the name of the program, who wrote it, when and where it was written, when it was compiled, and what security precautions(if any) should be taken to restrict access to the program or to the file it processes. Division should end with a set of English sentences giving a brief overview of what the program does.
ENVIRONMENT DIVISION Contains information about the computer(s) on which the COBOL program will be compiled and on which the resulting machine- language program will be run. It also gives a COBOL name to each file to be processed and assigns each file to a specified I/O device. This information defines the hardware environment in which programs runs.
DATA DIVISION Gives a brief description of each file to be processed, and then gives a detailed layout for the records in the file. Each field in a record is described in terms of its length and its type of data. The DATA DIVISION also describes in a memory area called WORKING- STORAGE. All data fields(in file records or in working-storage) must be described in the DATA DIVISION.
PROCEDURE DIVISION The computer is actually instructed as to what processing is to be carried out. The directions closely resemble English sentences.
SIMPLE SAMPLE PROGRAM IDENTIFICATION DIVISION PROGRAM-ID. HELLOWORLD ENVIRONMENT DIVISION CONFIGURATION SECTION SOURCE-COMPUTER. RM-COBOL OBJECT-COMPUTER. RM-COBOL DATA DIVISION FILE SECTION PROCEDURE DIVISION MAIN-LOGIC SECTION DISPLAY “HELLO WORLD!” STOP RUN.
SAMPLE PROGRAM “ ACCEPT_NUM” ID DIVISION PROGRAM-ID. ACCEPT DATA DIVISION WORKING-STORAGE SECTION WS-FIRST-NUMBER PIC 9(3) WS-SECOND-NUMBER PIC 9(3) WS-TOTAL PIC ZZZ9.
SAMPLE PROGRAM “ ACCEPT_NUM” ID DIVISION PROGRAM-ID. ACCEPT DATA DIVISION WORKING-STORAGE SECTION WS-FIRST-NUMBER PIC 9(3) WS-SECOND-NUMBER PIC 9(3) WS-TOTAL PIC ZZZ9.
SAMPLE PROGRAM “ ACCEPT_NUM” PROCEDURE DIVISION MAINLINE DISPLAY 'ENTER A NUMBER: ' ACCEPT WS-FIRST-NUMBER * DISPLAY 'ANOTHER NUMBER: ' ACCEPT WS-SECOND-NUMBER * COMPUTE WS-TOTAL = WS-FIRST-NUMBER + WS-SECOND- NUMBER DISPLAY 'THE TOTAL IS: ', WS-TOTAL STOP RUN.
SAMPLE PROGRAM “ ACCEPT_NUM SAMPLE RUN” ENTER A NUMBER: 7 ANOTHER NUMBER: 7 THE TOTAL IS: 14
COMPARED TO OTHER LANGUAGES “ THE GOOD SIDE” Self-Documenting Reserved Words Based on English Readability Easy to learn Business Oriented Non-proprietary(portable)
COMPARED TO OTHER LANGUAGES “ THE BAD SIDE" No encapsulation and little information hiding No block structure All variables are global Numbers closer to human arithmetic No recursion Not designed for graphical user environment Only best for business applications
SOURCES Newcomer, Lawrence R.. Theory and Problems of Programming with Structured COBOL.McGraw-Hill, Inc