intro cobol 50 by 3dMq16

VIEWS: 8 PAGES: 51

									COBOL History
COBOL (Common Business Oriented Language)
was one of the earliest high-level programming
languages. It was developed in 1959 by a group of
computer professionals called the Conference on
Data Systems Languages (CODASYL). Since 1959
it has undergone several modifications and
improvements. In an attempt to overcome the
problem of incompatibility between different
versions of COBOL, the American National
Standards Institute (ANSI) developed a standard
form of the language in 1968. This version was
known as American National Standard (ANS)
COBOL.                                           1
In 1974, ANSI published a revised version of (ANS)
COBOL, containing a number of features that were
not in the 1968 version. In 1985, ANSI published
still another revised version that had new features
not in the 1974 standard. The language continues
to evolve today. Object-oriented COBOL is a
subset of COBOL 97, which is the fourth edition in
the continuing evolution of ANSI/ISO standard
COBOL. COBOL 97 includes conventional
improvements as well as object-oriented features.
Like the C++ programming language, object-
oriented COBOL compilers are available even as
the language moves toward standardization.
                                                  2
Areas of Application
COBOL is ideally suited for the solution of business
problems. For example, if a company wanted to
keep track of its employees’ annual wages, COBOL
would be ideal language for implementation. It is
interesting to note that COBOL was the first
programming language whose use was mandated
by the Department of Defense (DoD).


                                                   3
        It’s not dead!


• millions of lines of COBOL code
  presently exist
• heavy need for year 2000
• new standards in ‘98



                                    4
    Introduction to COBOL
  and Program Development
• 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
        COBOL’s 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
                                               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
                                                            16
    to solve the problem.
    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 5–Documenting 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
   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.

                                                21
  Divisions of a COBOL Program
• All COBOL programs are divided into four
  divisions.
• IDENTIFICATION DIVISION
• ENVIRONMENT DIVISION
• DATA DIVISION
• PROCEDURE DIVISION
• Each division has a function in the overall
  development and execution of the program
                                            22
 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 .
                                                      23
  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.

                                                    24
       IDENTIFICATION DIVISION
• Identifies the program
• Example



 IDENTIFICATION DIVISION.
 PROGRAM-ID. PRGM01.




                                 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
       2.0 ENVIRONMENT DIVISION

  • There are two sections in this division
  • Configuration section (Hardware details;
    this section is NOT NEEDED)
  • Input-Output section(File details)


INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES-FILE ASSIGN TO DISK.
SELECT PRNT-FILE ASSIGN TO PRINTER.
                                               27
                 DATA DIVISION
• This DIVISION typically contains two sections
   – FILE SECTION, and
   – WORKING-STORAGE SECTION
• File section deals with Input and Output file
  descriptions
   – FD - File description (starts in Area A)
   – 01 - to describe the record layout (also in area A)
• Working Storage section
   – Is the section where the input and output records are
     manipulated and all other variables needed are defined.
   – Typically contains the variables, heading lines and detail
      record                                                 28
          COBOL Language Elements

• In a COBOL program, you’ll find the
  following words
  – Words
     • Reserved words
     • User Defined words
  – Constants or Literals
     • Non-Numeric
     • Numeric
     • Figurative constants
  – Note: Reserve words, and User Defined words
    are case NON-sensitive                    29
        COBOL Language Elements

• Reserved words
• User Defined words
  – These are data names for storage, paragraph,
    and section names
  – Examples:
    • EMPLOYEE-NAME-OUT
    • WS-END-OF-FILE-INDICATOR




                                               30
      COBOL Language Elements

– Rules:
  • max 30 characters
  • A-Z, 0-9, and hyphen (-)
  • must start and end with A-Z, or 0-9
    (paragraph ad section name are the only
    user defined words that are allowed to start
    with 0-9)
  • cannot begin or end with hyphen
  • must be at least one alphabetic character
  • cannot be a reserved word                    31
         COBOL Language Elements
• Non-Numeric Literals
  – these are string constants
  – Examples:
     • “Summary of Loans Report”
     • “ABC”
  – Rules:
     • max 160 characters
     • quotation marks are required before and
        after (single or double - compiler option)
     • contents between the quotes are case-
                                                     32
        sensitive
         COBOL Language Elements

• Numeric Literals
  – these are hard-coded numbers
  – Examples:
     • 12.45
     • -1
  – Rules:
     • max 18 digits
     • +, - must appear on the left of the number


                                                    33
      Non-Edited Picture Characters

• X Alpha-numeric (1 byte)
• 9 Numeric (1 bytes)
• S Operational SIGN (does not take up any
    space)
     • e.g.   05 WS-CREDIT PIC S9(3)
• V Implied Decimal Point
     • e.g.   05 WS-SALARY PIC 9(5)V9(02)




                                             34
    Example Input file and File Description
Data File of SALEFILE
•   111111111MOOING MARTY               001451255000
•   222222222PATSY POTATO                450003569050
•   333333333ROWDY RODENT                205001259020
•   444444444STARING STACEY              000090000650
The File Description:
FD SALES-FILE
      RECORD CONTAINS 80 CHARACTERS
      DATA RECORD IS SALES-REC.
01 SALES-REC.
     05 EMPLOYEE-NUM-IN    PIC 9(09).
     05 NAME-IN            PIC X(20).
     05 QUANTITY-IN        PIC 9(05).
     05 AMOUNT-IN          PIC 9(05)V99.
     05 FILLER             PIC X(39)
    Note the use of X and 9 and numbers in parentheses   35
  Example Input file and File Description
Main Memory


    Program Executable Code
                                                                Disk
     ENVIRONMENT DIVISION.
     INPUT-OUTPUT SECTION.
     FILE-CONTROL.
         SELECT SALES-FILE    ASSIGN       TO DISK-SALEFLE.
     DATA DIVISION.                                           SALEFLE
     FILE SECTION.
     FD FD SALES-FILE
                                                                file
           RECORD CONTAINS 80 CHARACTERS
           DATA RECORD IS SALES-REC.


    Buffer                             .
    01 SALES-REC.
         05 EMPLOYEE-NUM-IN        PIC      9(09).
         05 NAME-IN                PIC      X(20).
         05 QUANTITY-IN            PIC      9(05).
         05 AMOUNT-IN              PIC      9(05)V99.
         05 FILLER                 PIC      X(39)
                                                               AS400
    Working Storage                                           Operating
                                                               System
                                                                          36
            Working Storage Section
• Purpose
  – to save, or store temporary data for use in the
    program
• Records and variables
  – consist of Group and Elementary items
  – Elementary items MUST HAVE a PIC clause
  – Group items may consist of one or more
    elementary item, or other Group items
  – Group items are consider alphanumeric
    always
  – To show groupings, LEVEL numbers are used 37
         Working Storage Section
– Rules:
   • In sequence (from smaller numbers to larger)
   • But don’t have to be consecutive
   • Also, not required to jump by any given
      interval; can be random
   • Record level is 01 level
   • Valid numbers are 01 through 49 inclusive
   • 66, 77, 88 have special purpose usage



                                               38
        Working Storage Section

– VALUE clauses are ONLY allowed in Working
  Storage (not allow in FILE section).
– Used to initial elementary data items
– Cannot be used for group items
– can take a
   • literal
   • Figurative constant
   • the word ALL


                                              39
       Working Storage Section
– Examples:
01 WS-RPT-TITLE.
    05 WS-RPT-TITLE PIC X(20)VALUE
       ‘SALES REPORT’.
    05 WS-CHRISTMAS-DAY.
      10 XMAS-YR PIC 9(04) VALUE 2002.
      10 XMAS-MM PIC 9(02) VALUE 12.
      10 XMAS-DD PIC 9(02) VALUE 25.
01 DRAW-LINE PIC X(133) VALUE ALL “*”.


                                    40
   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


                                          41
         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.


                                                42
     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.

                                               43
       COBOL Coding Format
• The Coding form – this is divided into four
  major fields :
  Usage               Columns
Sequence numbers         1–6
Indicator area (*,-)      7
Area A (Headers)         8 – 11
Area B (statements)     12 – 72
Program identification 73 – 80

                                                44
        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.

                                          45
46
         Procedure Division
• Its very important to be precise while dealing
  with the procedure division.
• This is the only division that requires
  hierarchy chart, pseudocode, and program
  flowcharts.
• Hierarchy chart: Overview of the process.
• Pseudocode: Near COBOL code without
  syntax.
• Flowchart: Graphical representation of
  program flow.
                                                   47
           Hierarchy Chart

• Level1           MAIN-RTN



• Level2 HDG-RTN   READ-RTN   DETAIL-RTN



• Level3                      READ-RTN



                                           48
             Pseudocode
MAIN PROCESS
       OPEN FILES
       WRITE HEADINGS
       READ FIRST RECORD
       PROCESS RECORDS UNTIL NO MORE RECORDS
       CLOSE FILES
       STOP PROCESSING
WRITE HEADINGS
        MOVE AND WRITE HEADING LINE 1
       MOVE AND WRITE HEADING LINE 2
PROCESS RECORDS
       MOVE AND WRITE DETAIL RECORDS
        READ NEXT RECORD


                                               49
F   PROGRAM
                START
    FLOW
L             OPEN FILES
O
W               READ-
                 RTN
C
                 HDG-
H                RTN

A              UNTIL WS-
                EOF=‘Y’
                           CLOSE
                           FILES
R
                DETAIL-
T                RTN
                           STOP

                                   50
   What should you do?
• Ask questions
• Read chapter
• Do exercises at end
  of chapter
• Think!
• Ask questions!




                         51

								
To top