COBOL

23
COBOL COmmon Business Oriented Language Work began in 1959 and has never stopped

description

COBOL. CO mmon B usiness O riented L anguage 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. - PowerPoint PPT Presentation

Transcript of COBOL

Page 1: COBOL

COBOLCOmmon BusinessOrientedLanguage

Work began in 1959 and has never stopped

Page 2: COBOL

CODASYL Conference on Data Systems Languages Primarily BusinessWanted a language designed for their needs.The resulting language reflected business needs and the computing environment.

Page 3: COBOL

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.

Page 4: COBOL

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.

Page 5: COBOL

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.

Page 6: COBOL

Punch Card

Page 7: COBOL

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)

Page 8: COBOL

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

Page 9: COBOL

Divisions and Sections

Sections subdivide four primary divisions

Provides a top level organization for programs. More later.

Page 10: COBOL

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.

Page 11: COBOL

IDENTIFICATION DIVISION

ENVIRONMENT DIVISION

DATA DIVISION

PROCEDURE DIVISION

FOUR PROGRAM DIVISIONS

Page 12: COBOL

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.

Page 13: COBOL

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.

Page 14: COBOL

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.

Page 15: COBOL

PROCEDURE DIVISION The computer is actually instructed

as to what processing is to be carried out. The directions closely resemble English sentences.

Page 16: COBOL

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.

Page 17: COBOL

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.

Page 18: COBOL

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.

Page 19: COBOL

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.

Page 20: COBOL

SAMPLE PROGRAM “ACCEPT_NUM SAMPLE RUN”ENTER A NUMBER: 7 ANOTHER NUMBER: 7 THE TOTAL IS: 14

Page 21: COBOL

COMPARED TO OTHER LANGUAGES “ THE GOOD SIDE” Self-Documenting Reserved Words Based on English Readability Easy to learn Business Oriented Non-proprietary(portable)

Page 22: COBOL

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