600 likes | 620 Views
Learn the history, principles, and development process of COBOL. Understand program specifications, design techniques, testing, and documentation in COBOL programming. Discover the nature, advantages, and limitations of COBOL.
E N D
An Introduction to Structured Program Design in COBOL Chapter 1
Chapter Objectives To familiarize you with • 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
Chapter Contents • Computer Programming: An Overview • Applications Program Development Process • Nature of COBOL • History of COBOL and the ANS Versions
Chapter Contents • Techniques for Improving Program Design • Sample Programs • Entering and Running a COBOL Program on Your Computer • This is particular to our system • We’ll be using the “Alpha” which is a VAX • Telnet into it, you’ll love the editor.
Program Languages Machine language • Only language computer understands • All programs executed on computer must be in machine language • Machine language programs difficult to write
Program Languages 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
Program Development Process • Determine Program Specifications • Design Program Using Program Planning Tools • Code and Enter Program • Compile Program • Test Program • Document Program
1. Program Specifications • Systems analysts, users and programmers develop specifications • Specifications include: • Description of input and output data • Step-by-step processing required to convert input to output
1. Program Specifications 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. Program Specifications Printer spacing charts describe • Spacing • Layout of printed output • Heading, detail, total lines • Error messages
2. Design the Program 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
3. Code and Enter Program • Programmer writes and enters program into computer • Program written in symbolic language (like COBOL) • Called source program • You all already know this
4. Compile Source Program Compiler is program that • Checks source program for rule violations • Translates source program into object program • Next class we’ll try this out Source program in symbolic language Translated by compiler Object program in machine language
5. Test Program • Test or debug program to ensure it contains no errors • Check for two types of errors • Compile-Time Errors • Execution Errors
Compile-Time Errors • Errors detected by compiler during translation from COBOL to machine language • Detects violations of programming rules • Misspelled reserved words • Missing punctuation • Also called syntax errors
Execution Errors • Detected when program is run • Logic error causes incorrect output • Sequence of instructions incorrect • Wrong instruction coded • Run-time error if computer cannot execute instruction • Attempt to divide by zero • Attempt to read a file that cannot be found
Debugging Techniques • Desk checking • Correcting syntax errors • Program walkthroughs • Executing the program
6. Document the Program • 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
Nature of COBOL • Business-oriented language • Standard language • English-like language • Relatively easy to understand
Nature of COBOL • 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
Nature of COBOL • Advantages • -Simple • -Portable • -Maintainable • Disadvantages • -very wordy • -very rigid format • -not designed to handle scientific applications
History of COBOL • 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
Standard Versions of COBOL • 1960s • 1968 • 1974 • 1985 • wide variations in COBOL compilers • first COBOL standard set by American National Standards Institute (ANSI) • second ANSI standard to make COBOL more efficient, standardized • this ANSI standard incorporated structured programming techniques
Current and Future Standards • 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.
Future of COBOL Likely to remain important language • Older COBOL programs need to be updated • Still used by many for new program development • Mostly maintaining existing code, that’s why you’re here.
Use of COBOL • 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?
Improving Program Design Two techniques used to develop programs that are easier to understand, test, debug and modify • Structured Programming • Top-Down Programming
Structured Programming • Eliminates use of GO TO statements • Allowed skipping to different sections of program without returning to starting point • Program logic easier to follow with "GO-TO-less" 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
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 • Use of stubs For COBOL program • Code main modules or routines first • Code intermediate modules next • Details deferred to minor modules and coded last
Interactive vs Batch Programs • Cobol suited for developing both types of programs Interactive programs • Accept input data from keyboard • Input data processed immediately • Output (results) displayed on screen immediately
Interactive vs Batch Programs Batch programs • Process large volumes of input at periodic intervals • Input data read in from files • Output written to files
Overview of the Four Divisions • Every COBOL program contains up to four separate divisions in the following order: IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION • Specific to COBOL
Overview of the Four Divisions • 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
Overview of the Four Divisions • 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
Sample Interactive Program • Purpose • to compute employee WAGES • Input from keyboard • HOURS and RATE • Processing • compute WAGES as HOURS x RATE • Output displayed on screen • WAGES • Sample on Page 17 of book
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.
Sample Interactive Program • 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
Data Defined in Sample Program • Keyed input fields (HOURS, RATE) • Output fields (WAGES) • Other fields used for processing (MORE-DATA)
PICTURE Clause • 01 level begins definition of each field • PICTURE or PIC clause describes • Type of data • Numeric (PIC 9) • Nonnumeric (PIC X) • Size of field - determined by number of 9’s or X’s
PICTURE Clauses • RATE with PIC 99V99 includes V to show assumed decimal point position • User enters data with decimal point • Program uses V to align data • WAGES includes actual decimal point • Shown when value displayed on screen
Giving Field Initial Value • 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
PROCEDURE DIVISION • 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
PROCEDURE DIVISION • 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
PERFORM … END-PERFORM • Repeats set of instructions as long as user enters YES in response to prompt "IS THERE MORE DATA (YES/NO)?" • MORE-DATA initially contains YES so instructions in loop executed first time
PERFORM … END-PERFORM • When user enters NO as response • MORE-DATA set to "NO" and loop ends • After loop, STOP RUN is executed, ending program
PERFORM … END-PERFORM 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
Sample Batch Program • 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
Sample Batch Program • 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
COBOL Divisions • All four divisions included for batch programs • IDENTIFICATION DIVISION first with required PROGRAM-ID paragraph • ENVIRONMENT DIVISION • INPUT-OUTPUT SECTION assigns input and output files to specific devices