Professional Documents
Culture Documents
1-1
Why COBOL is a popular business-oriented language. Programming practices and techniques History of COBOL Use of the current ANSI standard versions of COBOL Four divisions of a COBOL program
1-2
Computer Programming: An Overview Applications Program Development Process Nature of COBOL History of COBOL and the ANS Versions
1-3
Techniques for Improving Program Design Sample Programs Entering and Running a COBOL Program on Your Computer
This is particular to our system Well be using the Alpha which is a VAX Telnet into it, youll love the editor.
1-4
Machine language Only language computer understands All programs executed on computer must be in machine language Machine language programs difficult to write
1-5
Symbolic language (like COBOL) English-like languages used to write programs Easier than writing programs in machine language Must be translated or compiled into machine language to run on computer
1-6
1.
2. 3. 4. 5. 6.
Determine Program Specifications Design Program Using Program Planning Tools Code and Enter Program Compile Program Test Program Document Program
1-7
1-8
Record layout forms describe format of input and output data Data names of each data item in record Location of each data item in record Size of each data item Number of decimal positions (for numeric data items) Note that this is different than what you are used to in C++
1-9
Printer spacing charts describe Spacing Layout of printed output Heading, detail, total lines Error messages
110
Program planning tools used to map out structure and logic of program Flowcharts use block diagrams to represent logic Pseudocode uses English-like statements Hierarchy charts show relationships among sections of program
111
Programmer writes and enters program into computer Program written in symbolic language (like COBOL) Called source program
You all already know this
112
Compiler is program that Checks source program for rule violations Translates source program into object program Next class well try this out
Translated by compiler
113
Test or debug program to ensure it contains no errors Check for two types of errors
Compile-Time Errors Execution Errors
114
Errors detected by compiler during translation from COBOL to machine language Detects violations of programming rules
Misspelled reserved words Missing punctuation
115
116
Desk checking Correcting syntax errors Program walkthroughs Executing the program
117
Documentation - formal set of procedures and instructions to specify how to use program Written for
Those working with output Computer operators who run program Maintenance programmers who make modifications to program
This was a big part of the design of COBOL, Self documenting code
118
119
Distinct Features of COBOL The language is simple No pointers No user defined types No user defined functions Structure like data types File records are also described with great detail, as are lines to be output to a printer COBOL is self documenting
120
Advantages -Simple -Portable -Maintainable Disadvantages -very wordy -very rigid format -not designed to handle scientific applications
121
Developed in 1959 as standard language to meet needs of business Committee to develop language convened by Department of Defense Included representatives from academia, business, computer manufacturers
122
1960s
1968
wide variations in COBOL compilers first COBOL standard set by American National Standards Institute (ANSI)
1974 1985
123
1985 currently the most widely used The book mentions 2008 as the latest standard but looks like 2002 may be So the book mentions 2008 conventions, seems they work on our compiler.
124
Likely to remain important language Older COBOL programs need to be updated Still used by many for new program development Mostly maintaining existing code, thats why youre here.
125
About 200 billion lines of COBOL source code in use New lines added each year Used by many application programmers in medium to large U.S. companies How about the Y2K Problem?
126
Two techniques used to develop programs that are easier to understand, test, debug and modify
127
128
Program divided into paragraphs Main paragraph or module controls logic flow using PERFORM statements Main module "performs" other modules when instructions in that module required Each module can be written and tested independently of others
129
Another technique to make programs easier to understand, test, debug and modify Develop program like term paper
Develop outline first Add details for each of main steps Add further refinement for more complex steps Use of stubs
For COBOL program Code main modules or routines first Code intermediate modules next Details deferred to minor modules and coded last
130
Interactive programs Accept input data from keyboard Input data processed immediately Output (results) displayed on screen immediately
131
Batch programs Process large volumes of input at periodic intervals Input data read in from files Output written to files
132
Every COBOL program contains up to four separate divisions in the following order: IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION Specific to COBOL
133
IDENTIFICATION DIVISION
Identifies program to operating system Provides documentation about program
ENVIRONMENT DIVISION
Defines file-names Describes devices used to store them Not included in fully interactive programs
134
DATA DIVISION
Describes input and output format of data in files Defines any constants and work areas
PROCEDURE DIVISION
Contains instructions to read input, process it and create output
135
Purpose
to compute employee WAGES
Processing
compute WAGES as HOURS x RATE
136
IDENTIFICATION DIVISION. PROGRAM-ID. WAGES1. DATA DIVISION. WORKING-STORAGE SECTION. 01 HOURS PIC 99. 01 RATE PIC 99V99. 01 WAGES PIC 999.99. 01 MORE-DATA PIC XXX VALUE 'YES'. PROCEDURE DIVISION. 100-MAIN. PERFORM UNTIL MORE-DATA = 'NO' DISPLAY 'ENTER HOURS AS A TWO DIGIT NUMBER' ACCEPT HOURS DISPLAY 'ENTER RATE IN NN.NN FORMAT (2 DECIMAL DIGITS)' ACCEPT RATE MULTIPLY RATE BY HOURS GIVING WAGES DISPLAY 'WAGES ARE ', WAGES DISPLAY 'IS THER MORE DATA (YES OR NO)?' ACCEPT MORE-DATA END-PERFORM STOP RUN.
137
IDENTIFICATION DIVISION
One required entry, PROGRAM-ID Names the program
DATA DIVISION
Describes and defines storage for all data Data defined in WORKING-STORAGE SECTION for interactive program
138
Keyed input fields (HOURS, RATE) Output fields (WAGES) Other fields used for processing (MOREDATA)
139
140
RATE with PIC 99V99 includes V to show assumed decimal point position User enters data with decimal point WAGES includes actual decimal point
Shown when value displayed on screen Program uses V to align data
141
MORE-DATA with PIC XXX is nonnumeric field Assigned initial contents of YES by use of VALUE clause Value must be in quotation marks since MORE-DATA is nonnumeric field
142
Set of instructions to be executed by program Organization of instructions planned before coding begins Pseudocode, an English-like description of program instructions, used for planning Describes program logic and order in which instructions will be executed
143
PROCEDURE DIVISION includes one paragraph 100-MAIN List of instructions that follow make up paragraph Period follows last statement in paragraph (STOP RUN.) Main processing controlled by PERFORM END-PERFORM loop
144
145
146
Statements in loop executed in order they are listed DISPLAY displays value in quotes or value of field on screen ACCEPT stores value user enters from keyboard in field MULTIPLY performs calculation to find WAGES
147
In batch mode, data comes from input file instead of keyboard Data for each employee stored in a record in file on disk Employee name, hours and rate data called fields Page 30
148
Calculated results (Wages) stored in file instead of displayed on screen For each input record
Record created and stored in output file Includes employee name, hours, rate and computed wages File intended for printing so spacing added between fields for readability
149
150
FILE SECTION describes format of input and output files Fields in records described using PICTURE clause Decimal point not stored in input records
Use V for implied decimal for alignment
151
Contains instructions to be executed by computer Instructions executed in order they appear Includes two paragraphs with period at end of each
152
OPENs files to be used by program Repeatedly READs in records (PERFORM END-PERFORM) until there are no more Calls second paragraph 200-WAGE-ROUTINE to process each record CLOSEs files after all records read Ends program (STOP RUN)
153
Reads one record into program storage area Record must be in storage to use it Takes one of two actions depending on whether record was read
154
155
First MOVE initializes PRINT-REC to blanks Then MOVEs name, hours, wages to output fields Calculates WAGES with MULTIPLY statement, MOVES it to output field WRITEs data in employee output record to print file
156
To type in and run a COBOL program on your computer system, you need to know how to:
Log on and off of the computer Name COBOL files on the computer Use a text editor to key in, modify and save files Compile a COBOL source program to translate it into machine language Link or load the object program Run the object program
157
158
COBOL programs divided into four divisions IDENTIFICATION DIVISION identifies program to operating system ENVIRONMENT DIVISION required for batch programs that operate on files DATA DIVISION defines formats for all input, output and work areas needed
FILE SECTION required for batch programs that operate on files WORKING-STORAGE SECTION for work fields or fields used in interactive programs
159
PROCEDURE DIVISION
Contains instructions to process input and produce output Divided into paragraphs or modules
160