Introduction Cobol
Introduction Cobol
Introduction Cobol
CHAPTER 1 OBJECTIVES
To familiarize you with:
1. The reasons for COBOLs popularity as a business-oriented language. 2. Some general programming practices and techniques. 3. A history of COBOLs evolution and its current ANS version. 4. An overview of how a COBOL program is structure.
Structured COBOL Programming, Stern & Stern, 9th edition
computer to process data. Software is the term used to describe all types of programs. An application program converts input data to output information.
EMPLOYEE FILE
PAYROLL REPORT
Written by Programmers or Software Developers Programs that perform tasks required by users A set of programs that fulfill a business requirement is an Information System
Structured COBOL Programming, Stern & Stern, 9th edition
Applications Programs
from a PC, workstation, or terminal. Batch Processing applications process large volumes of input at periodic intervals.
Daily Weekly Monthly etc.
Applications Programs
Applications programs that are written for a
specific user are called customized programs. Programs that are relatively standard are application packages that might be purchased.
Off The Shelf (OTS) may be less costly depending on the amount of customization needed
Symbolic Programs
Symbolic Programs
COBOL is a symbolic programming language used for commercial applications. As is C++, Visual Basic etc.
A compiler coverts symbolic language into
machine code
6.
Determine Program Specifications Design Program Using Program Planning Tools Code and Enter Program Compile Program Test Program Document Program
Structured COBOL Programming, Stern & Stern, 9th edition
I/O Specifications
The I/O specifications establish record names, field names, data sizes and types to be used in your program. For auxiliary storage specifications can take the form of an 01 level print out or a simply chart as follows.
Used in developing the Data Division. Payroll-Record
Type
Name Address Pay-Rate Alphanumeric Alphanumeric Numeric
Size
30 23 5.2 or 7 with 2 decimals
Etc.
Design the Program Using Program Planning Tools using Common Tools:
Hierarchy Charts
Charts showing relationships among sections in a program A block diagram providing a pictorial representation of the logic to be used in a program English-like expressions to depict the logic of the program
Structured COBOL Programming, Stern & Stern, 9th edition
Flowcharts
Pseudocode
HIERARCHY CHART
100-CALCULATE-VEHICLE-REGISTRATION-FEES
200-INITIALIZE 210-PROCESS-RECORDS
300-GET-DATE
900-PRINT-HEADERS
310-FIND-RATE
320-PRINT-DETAILS
The first phase of problem solving is to use a top down design. Begin with a very general problem statement and break it down into smaller and smaller pieces until you know you have pieces you can solve. The hierarchy chart establishes the Paragraph names you will use in pseudo code and in your programs Procedure Division. It outlines a very general program flow and shows the relationship between modules/paragraphs. Answers the question WHAT needs to be done? Structured COBOL Programming, Stern & Stern, 9th edition
900-PRINT-HEADERS
REMEMBER
The sooner you start coding the longer it will take you to complete the project!!!!!
Coding
Program testing Acceptance test Maintenance
1
2 5
Structured COBOL Programming, Stern & Stern, 9th edition
2X
4X 10X 40X
20
program requirements have been fully specified and the logic has been carefully planned.
DEBUGGING TECHNIQUES
Desk Checking
Using the printed source list of the diagnostic messages to find and correct the errors
DEBUGGING TECHNIQUES
Program Walkthroughs
Program
Often the most difficult part of debugging. The preparation of test data is an extremely critical aspect of debugging.
Structured COBOL Programming, Stern & Stern, 9th edition
COBOL is a Standard Language COBOL is a common programming language available on most computers.
Structured COBOL Programming, Stern & Stern, 9th edition
WHEN IT BEGAN
Developed as a standard business-oriented language for which all major manufacturers would provide compilers. ANS established the first standards version in 1968. COBOL 85 the current standard
http://www.ansi.org
2002+ Standard
Use of COBOL
About 200 billion lines of COBOL source code in
use 5 billion new lines added each year Used by 42.7% of application programmers in medium to large U.S. companies $200 million in expected revenues for 2001
programs
Interactive programs Accept input data from keyboard Input data processed immediately Output (results) displayed on screen immediately
Structured COBOL Programming, Stern & Stern, 9th edition
Structured Programming
Eliminates use of GO TO statements
programming
Structured Programming
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
Structured COBOL Programming, Stern & Stern, 9th edition
Top-Down Programming
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
Top-Down Programming
For COBOL program Code main modules or routines first Code intermediate modules next Details deferred to minor modules and coded last
Program Specifications
System Flowchart
Input/Output Specifications Hierarchy Chart Psuedo code Narrative as comments in program
System Flowchart
INPUT PROCESSING OUTPUT
Student-File
Attendance Report
START
OPEN FILES
WRITE HEADINGS
TRUE
5
PROCESS RECORDS END OF FILE REACHED?
10 11
12
CLOSE FILES
STOP
STOP
Structured COBOL Programming, Stern & (b) Detail of PROCESS-RECORDS Stern, 9th edition
Pseudo Code
Open files Initialization Read first record Write heading DO while data remains IF engineering major with more than 110 credits Write students name ENDIF ENDDO Close files Termination Stop
Structured COBOL Programming, Stern & Stern, 9th edition
Processing
Hierarchy of Data
Bit - binary 0 or 1 Byte / Character - 8 bits Field - a basic fact about some entity
Record - a collection of related facts File - a collection of related records Database - an organizations set of files
Fields
(Facts)
Name: Credits: Major: John Adams 90 Political Science
Records
(Set of Fields)
Jphn Adams 90 Political Science
Amelia Earhart
120
Aviation
Orville Wright
115
Engineering
Art
Structured Programming, Figure 1.1 Fields, Records, and Files COBOL9th edition Stern & Stern,
Programming Structures
Sequence
Selection Iteration/Repetition
design of a program in any language is called structured programming. Structured Programming is a technique using logical control constructs that make programs easier to read, debug, and modify if changes are required.
Structured COBOL Programming, Stern & Stern, 9th edition
Modular Programming
Each module/paragraph must meet the following
characteristic
COMPLETENESS taken together the modules completely satisfy the program specifications COHESIVE a paragraph must perform one and only one task COUPLING paragraphs are loosely coupled that is a paragraph does not depend on other paragraphs
Structured COBOL Programming, Stern & Stern, 9th edition
TO-less programming since programmatic branches do not use GO TO statements. In COBOL this means writing programs using PERFORM statements
Incremental testing
Structured COBOL Programming, Stern & Stern, 9th edition
program.
The following chart shows the relationships among modules in a program:
100-MAIN MODULE
200INITIALIZE
Structured COBOL Programming, Stern & Stern, 9th edition
210-WAGE ROUTINE
Each block on the Hierarchy chart needs to be represented in pseudocode Paragraph names are prepared in numerical sequence
100-Main-Module 200-Initialize 210-Wage-Routine 220-Finalize-Program Etc
3.
Identification Division
Identifies program to OS Provides documentation
Environment Division
Defines files Establishes Logical (program) and physical (computer) relationship
Data Division
Describes all input and output data As well as scratch pad data (working storage)
Procedure Division
All the program logic
Structured COBOL Programming, Stern & Stern, 9th edition
Figure 1.6
Identification Division
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Environment Division
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT-FILE ASSIGN TO A:\CHAPTR02\SENIOR.DAT ORGANIZATION IS LINE SEQUENTIAL. SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD STUDENT-FILE RECORD CONTAINS 43 CHARACTERS DATA RECORD IS STUDENT-IN. 01 STUDENT-IN. 05 STU-NAME PIC X(25). 05 STU-CREDITS PIC 9(3). 05 STU-MAJOR PIC X(15). Structured COBOL Programming, Stern & Stern, 9th edition
Data Division
Figure 1.6
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
FD
01
PRINT-FILE RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. PRINT-LINE PIC X(132).
PIC X(2)
VALUE SPACES.
01
01
Figure 1.6
41
42
43
PROCEDURE DIVISION. 42 100-PREPARE-SENIOR-REPORT. 43 OPEN INPUT STUDENT-FILE 44 OUTPUT PRINT-FILE Procedure Division 45 READ STUDENT-FILE 46 AT END MOVE NO TO DATA-REMAINS-SWITCH 47 END-READ 48 PERFORM 200-WRITE-HEADING-LINE 49 PERFORM 210-PROCESS-RECORDS 50 UNTIL DATA-REMAINS-SWITCH = NO 51 CLOSE STUDENT-FILE 52 PRINT-FILE 53 STOP RUN. 54 55 200-WRITE-HEADING-LINE. 56 MOVE HEADING-LINE TO PRINT-LINE 57 WRITE PRINT-LINE. 58 59 210-PROCESS-RECORDS. 60 IF STU-CREDITS > 110 AND STU-MAJOR = ENGINEERING 61 MOVE STU-NAME TO PRINT-NAME 62 MOVE DETAIL-LINE TO PRINT-LINE 63 WRITE PRINT-LINE 64 END-IF 65 READ STUDENT-FILE 66 AT END MOVE NO TO DATA-REMAINS-SWITCH Structured COBOL Programming, Stern & 67 END-READ. Stern, 9th edition
End