Structured COBOL Programming - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Structured COBOL Programming

Description:

Identify the Advantages and Disadvantages of COBOL ... Are more English-like and less cryptic. Can be easily transferred from one. Examples ... – PowerPoint PPT presentation

Number of Views:292
Avg rating:3.0/5.0
Slides: 32
Provided by: nsm1N
Category:

less

Transcript and Presenter's Notes

Title: Structured COBOL Programming


1
Structured COBOL Programming
  • _at_ IUP
  • Computer Science Department
  • Text by
  • Shelly, Cashman, Foreman
  • Notes by
  • Dr. William W. Oblitey

2
Introduction to COBOL and Program Development
  • Chapter Objectives
  • Identify the Advantages and Disadvantages of
    COBOL
  • Understand the difference between record input
    and output
  • List the steps required by the Programming
    Process
  • Name the Logic Structures used in a Structured
    Program

3
Chapter Objectives
  • Describe Top-down Design and Top-down Programming
  • Name the four divisions of a COBOL program
  • Specify the purpose of each COBOL division
  • Identify valid COBOL words
  • Describe the format of a line of COBOL source code

4
Introduction
  • COBOL
  • Common Business Oriented Language
  • First released in 1960 by CODASYL
  • Conference of Data Systems Language
  • Purpose was to provide a High-Level Programming
    Language for the business world.

5
High-Level Vs. Low-Level Languages
  • High-Level Language
  • The program statements are not closely related to
    the internal characteristics of the machine.
  • Are more English-like and less cryptic
  • Can be easily transferred from one
  • Examples
  • COBOL, C, C, Java, VB, etc.

6
High vs. Low-Level Languages
  • Low-Level Language
  • Uses symbolic notation to represent machine
    instructions
  • Is closely related to the internal architecture
    of the machine
  • Cannot be transferred from, one machine system to
    another
  • Examples
  • Machine language, Assembly language

7
COBOLs Survival
  • COBOL is widely accepted
  • Has been in use for over 35 years
  • Many businesses have great investment in COBOL
    programs.
  • COBOL is available on every computer platform
  • Object-COBOL is available
  • COBOL Versions 68, 74, 85, 90?

8
Advantages of COBOL
  • COBOL was designed to be machine-independent,
    English-like, and self-documenting
  • COBOL has had ANSI support since 1960
  • ANSI
  • American National Standards Institute
  • COBOL Compiler
  • Translates COBOL source code into machine
    language

9
Disadvantages of COBOL
  • COBOL programs are wordy
  • They are longer than those produced in most other
    languages
  • Is not popularly employed for coding scientific
    applications

10
Information Processing
  • Information Processing
  • The production of information by processing data
    on a computer.
  • Stream Input/Output
  • This is typical with C, Java, VB, etc
  • Program reads data and assigns it to variables
  • Record Input/Output
  • This is typical with COBOL
  • COBOL groups data into fields and records
  • (See Fig. 1, pg. 4)

11
Record Blocking
  • Increases the efficiency of record I/O
  • Blocking
  • Grouping the records transmitted from secondary
    memory to the CPU as needed by the program
  • Records are supplied one at a time to the program
    through READ statements
  • The block is a physical record and each record
    within the block is a logical record

12
Steps in the Programming Process
  • Understand the Problem
  • Design the Program
  • Code the Program
  • Test the Program
  • Document the Program

13
Step 1 - Understanding the Problem
  • Be sure that you have a complete understanding of
    the purpose of the program
  • read the specifications
  • Establish and maintain a channel of communication
    with the client
  • Determine what the output of the program should
    be
  • Examine the input
  • Determine what mathematical calculations are
    needed

14
Step 2 - Design the Program
  • Develop the sequence of steps you will need to
    solve the problem
  • Should not involve a computer
  • Tools needed are spacing chart, flowcharts,
    hierarchy charts, and pseudocode.
  • Make use of the top-down design approach to
    problem solving

15
Step 2 -- Design Tools
  • Spacing chart
  • Consists of rows and columns that can be used to
    design the appearance of a screen or a printed
    report
  • Flowchart
  • A graphical representation of the steps needed to
    solve a problem
  • Hierarch chart
  • Demonstrates the relationship between the
    paragraphs used in the program and how the
    solution is organized
  • Pseudocode
  • An English-like representation of the actions
    needed to solve the problem.

16
Step 3 - Coding the Program
  • Design the logic and then translate it into COBOL
    code
  • Source code
  • These are the instructions you write for the
    computer to carry out.
  • It is your code before it is translated into
    machine language
  • You write source code with a text editor
  • A language sensitive editor helps you by placing
    the cursor in the correct column positions and
    pointing out syntax errors
  • Syntax errors caused by not using the language
    correctly

17
Step 4 - Testing the Program
  • After writing the program, you need to compile
    it.
  • Compilation
  • translating the source code (program) to machine
    code
  • This is done by the compiler
  • If syntax errors show up, you should correct them
    and recompile until you obtain a clean compile

18
Step 5Documenting the Program
  • Documentation is necessary to allow people to
    figure out how to use your program and/or fix it
    when future errors show up or modifications are
    necessary.
  • Program documentation can take many forms
  • External documentation
  • Notes and Manuals for other programmers
  • Comments lines and meaningful data names
  • These help with program readability and enhances
    the self-documenting nature of COBOL code.

19
Structured Programming
  • Structured programming uses the three basic logic
    control structures
  • Sequence, selection, iteration
  • A logic control structure is a way in which
    statements in a program can be executed.
  • Advantages offered
  • Programs appear neater and are more readable
  • Reliability and efficiency of programs are
    improved
  • Reduces time spent on debugging, testing, and
    modifying programs
  • Increases programmer productivity

20
Logic Control Structures
  • Sequence Structure
  • Here, one imperative statement is executed after
    another (Fig. 1-3, pg. 8)
  • Imperative statement
  • One that demands an action to be executed
  • Selection Structure
  • Here, code is executed based on the result of a
    condition (Fig. 1-4, pg. 8)
  • Iteration (Looping) Structure
  • Here, a set of instructions are executed until
    some predetermined condition is met. (Fig. 1-6,
    pg. 9)

21
Top-Down Design/Programming
  • Methodologies for solving large problems
  • Top-Down Design
  • Breaks a large, complex problem into smaller,
    less complex units
  • Also called Divide and Conquer strategy
  • Top-Down Programming
  • The high-level modules are coded as soon as they
    are designed. (See fig. 1-8, pg. 11)

22
Divisions of a COBOL Program
  • All COBOL programs are divided into four
    divisions (see fig. 1-9, pg. 11)
  • IDENTIFICATION DIVISION
  • ENVIRONMENT DIVISION
  • DATA DIVISION
  • PROCEDURE DIVISION
  • Each division has a function in the overall
    development and execution of the program

23
IDENTIFICATION DIVISION
  • Provides the computer with basic information
    about the program
  • Has only one required entry
  • The division header contains the reserved words
    IDENTIFICATION DIVISION
  • The reserved word PROGRAM-ID is used to name the
    program.
  • The program name is selected by the programmer.
  • Periods are required at end of each division .

24
IDENTIFICATION DIVISION
  • The COBOL language processor looks for periods to
    terminate various elements of the program.
  • The asterisk () is used to convey documentation
    in the program.
  • Comment
  • The is placed in column 7 and is ignored by the
    COBOL compiler. (see Fig. 1-16, pg. 16)

25
ENVIRONMENT DIVISION
  • This is the most hardware-dependent part of a
    COBOL program
  • Defines Input and Output
  • Contains the INPUT-OUTPUT SECTION and the
    FILE-CONTROL paragraph.
  • The INPUT-OUTPUT SECTION
  • Designates the data files that the program uses.
  • Each data file is associated with a hardware
    input-output device

26
DATA DIVISION
  • Defining files, records, and fields
  • Also defines variables for use as counters,
    accumulators, and flags
  • It is used to describe the data to be processed
    by the program
  • Its first two sections are the FILE SECTION and
    the WORKING-STORAGE SECTION.

27
The PROCEDURE DIVISION
  • Contains the program logic processing steps
  • Contains procedures, which are actions to be
    carried out by the program
  • It s made up of separate modules called
    paragraphs.
  • Statements in the PROCEDURE DIVIDION begin with
    action verbs (see Fig. 1-10, pg. 12)

28
The Paragraph Name
  • A paragraph name is user-defined.
  • It must end with a period.
  • No blanks are allowed in the name.
  • Hyphens may be used to separate the words that
    make up the paragraph name.
  • Recommended to start the name with a module
    level number.
  • Following the paragraph name are COBOL statements
    These designate operations to take place and
    thus begin with verbs. (see Fig. 1-11, pg. 13)

29
Overall Program Execution
  • COBOL statements are not executed directly
  • They are converted into machine language
  • The statements in the program are called source
    code
  • The statements that the computer executes is
    called the object code
  • Execution of a program begins with the first
    statement following the PROCEDURE DIVISION and
    continues statement by statement until the end of
    the program is encountered.

30
COBOL Coding Format
  • The Coding form this is divided into four major
    fields (see fig. 1-13, pg. 14)
  • Usage Columns
  • Sequence numbers 1 6
  • Indicator area (/,,-) 7
  • Area A (Headers) 8 11
  • Area B (statements) 12 72
  • Program identification 73 80

31
Program Preparation
  • Line numbers in the program are NOT entered by
    the programmer. They are generated by the
    compiler.
  • Area A and Area B entries
  • Columns 8 11 is area A
  • Columns 12 72 is area B
  • These columns are significant because COBOL
    entries must start in specific columns.
Write a Comment
User Comments (0)
About PowerShow.com