COBOL
description
Transcript of COBOL
COBOLCOmmon BusinessOrientedLanguage
Work began in 1959 and has never stopped
CODASYL Conference on Data Systems Languages Primarily BusinessWanted 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 000100 IDENTIFICATION DIVISION.000200 PROGRAM-ID. HELLOWORLD.000300000400 ENVIRONMENT DIVISION.000500 CONFIGURATION SECTION.000600 SOURCE-COMPUTER. RM-COBOL.000700 OBJECT-COMPUTER. RM-COBOL.000800 000900 DATA DIVISION.001000 FILE SECTION.001100 101200 PROCEDURE DIVISION.101300101400 MAIN-LOGIC SECTION.101500 DISPLAY “HELLO WORLD!”101600 STOP RUN.
SAMPLE PROGRAM “ACCEPT_NUM”000100 ID DIVISION. 000200 PROGRAM-ID. ACCEPT1. 000300 DATA DIVISION. 000400 WORKING-STORAGE SECTION. 000500 01 WS-FIRST-NUMBER PIC 9(3). 000600 01 WS-SECOND-NUMBER PIC 9(3). 000700 01 WS-TOTAL PIC ZZZ9.
SAMPLE PROGRAM “ACCEPT_NUM”000100 ID DIVISION. 000200 PROGRAM-ID. ACCEPT1. 000300 DATA DIVISION. 000400 WORKING-STORAGE SECTION. 000500 01 WS-FIRST-NUMBER PIC 9(3). 000600 01 WS-SECOND-NUMBER PIC 9(3). 000700 01 WS-TOTAL PIC ZZZ9.
SAMPLE PROGRAM “ACCEPT_NUM”000900 PROCEDURE DIVISION. 001000 0000-MAINLINE. 001100 DISPLAY 'ENTER A NUMBER: '. 001200 ACCEPT WS-FIRST-NUMBER. 001300* 001400 DISPLAY 'ANOTHER NUMBER: '. 001500 ACCEPT WS-SECOND-NUMBER. 001600* 001700 COMPUTE WS-TOTAL = WS-FIRST-NUMBER + WS-
SECOND-NUMBER. 001800 DISPLAY 'THE TOTAL IS: ', WS-TOTAL. 001900 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 http://www.engin.umd.umich.edu/CIS/co
urse.des/cis400/cobol/seccob.html Newcomer, Lawrence R.. Theory and Problems
of Programming with Structured COBOL.McGraw-Hill, Inc. 1984.
http://www.fourmilab.ch/documents/univac/cards.html