Presentation is loading. Please wait.

Presentation is loading. Please wait.

PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.

Similar presentations


Presentation on theme: "PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert."— Presentation transcript:

1 PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College “Copyright @ 2000 John Wiley & Sons, In. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express permission of the copyright owner is unlawful. Request for further information should be addressed to the permissions Department, John Wily & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.”

2 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals

3 Structured COBOL Programming, Stern & Stern, 9th Edition OBJECTIVES To Familiarize You With: 1. The Basic Structure of a COBOL program. 2. General Coding and Format Rules. 3. IDENTIFICATION and ENVIRONMENT DIVISION Entries.

4 Structured COBOL Programming, Stern & Stern, 9th Edition CONTENTS Basic Structure of a COBOL Program –Coding a Source Program –Coding Rules –Types of COBOL Entries Coding Requirements of the IDENTIFICATION DIVISION –Paragraphs in the IDENTIFICATION DIVISION Coding Requirements of the IDENTIFICATION DIVISION –Understanding Instruction Formats as They Appear in Reference Manuals.

5 Structured COBOL Programming, Stern & Stern, 9th Edition CONTENTS The Sections of the ENVIRONMENT DIVISION –CONFIGURATION SECTION. –INPUT-OUTPUT SECTION. Assigning Files to Devices in the ENVIRONMENT DIVISION –Overall Format –More Detailed Device Specifications Required for Some Computers –SELECT Statements for PCs

6 BASIC STRUCTURE OF A COBOL PROGRAM

7 Structured COBOL Programming, Stern & Stern, 9th Edition Coding a Source Program Traditional COBOL coding sheets have 20 lines with spaces set aside in columns 4--6 for sequence numbers. Each COBOL instruction is coded on a single line using 80 characters per line.

8 Structured COBOL Programming, Stern & Stern, 9th Edition Coding a Source Program Every line written on the coding sheet should be keyed in with one line each on a terminal or PC keyboard. The entire program is referred to as the COBOL source program.

9 Structured COBOL Programming, Stern & Stern, 9th Edition CODING RULES The main body of the form is subdivided into 72 positions or columns. Column 7 of a COBOL program has three primary purposes: 1. By coding an * (asterisk) in column 7, an entire line can be designated as a comment. 2. It can be used to force the printing of subsequent instructions on the next page of the source listing. 3. It can be used for the continuation of nonnumeric literals.

10 Structured COBOL Programming, Stern & Stern, 9th Edition DEBUGGING TIP Use uppercase letters for instructions; – use lowercase letters for comments. Page-Eject with a Slash (/) in Column 7 can also be used to skip to the next page when the source listing is being printed.

11 Structured COBOL Programming, Stern & Stern, 9th Edition CODING RULES: Areas A and B Positions 8--72 of a standard COBOL program contain program statements: –Column 8 is labeled the A area –Column 12 is labeled the B area Entries in Area A, may begin in position 8, 9, 10, or 11. –Most often, Area A entries begin in position 8. If an entry is to be coded in Area B, it may begin anywhere after position 11.

12 Structured COBOL Programming, Stern & Stern, 9th Edition TYPES OF COBOL ENTRIES Divisions, sections, and paragraphs begin in Area A. Examples include: DIVISIONS IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. SECTIONS FILE SECTION. WORKING-STORAGE SECTION.

13 Structured COBOL Programming, Stern & Stern, 9th Edition TYPES OF COBOL ENTRIES Divisions, sections, and paragraphs begin in Area A. Examples include: PARAGRAPHS PROGRAM-ID. 200-CALC-RTN. Statements and sentences begin in Area B; for example: SELECT PAYROLL ASSIGN TO DISK. ADD AMT-IN TO TOTAL.

14 Structured COBOL Programming, Stern & Stern, 9th Edition TYPES OF COBOL ENTRIES MARGIN RULES 1. Division, section, and paragraph-names begin in Area A. 2. All other statements, clauses, and sentences begin in Area B.

15 Structured COBOL Programming, Stern & Stern, 9th Edition CODING REQUIREMENTS OF THE IDENTIFICATION DIVISION

16 Structured COBOL Programming, Stern & Stern, 9th Edition Paragraphs in the IDENTIFICATION DIVISION IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry]...] [INSTALLATION. [comment-entry]...] [DATE-WRITTEN. [comment-entry]...] [DATE-COMPILED. [comment-entry]...] [SECURITY. [comment-entry]...]

17 Structured COBOL Programming, Stern & Stern, 9th Edition Rules for Interpreting Instruction Formats 1. Uppercase words are COBOL reserved words 2. Underlined words are required. 3. Lowercase words represent user- defined entries. 4. Braces { } denote that one of the enclosed items is required.

18 Structured COBOL Programming, Stern & Stern, 9th Edition Rules for Interpreting Instruction Formats 5. Brackets [ ] mean the clause or paragraph is optional. 6. If punctuation is specified in the format, it is required. 7. Dots … or ellipses ( … ) means additional entries of the same type may be optionally added.

19 Structured COBOL Programming, Stern & Stern, 9th Edition COBOL 2000+ CHANGES All paragraphs AUTHOR through SECURITY will be deleted from the COBOL 2000+ standard since they can be easily replaced with comments.

20 QUESTIONS?

21 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 1. If an entry must begin in Area A, it may begin in position _____ ; if an entry must begin in Area B, it may begin in position _____. Solution: 8, 9, 10, or 11; 12, 13, 14, and so on

22 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 2. The four divisions of a COBOL program must appear in order as _____ ; _____ ; _____ ; and, _____. Solution: IDENTIFICATION; ENVIRONMENT; DATA; PROCEDURE

23 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 3. What entries must be coded beginning in Area A? Solution: Division, section, and paragraph-names

24 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 4. Most entries such as PROCEDURE DIVISION instructions are coded in Area _____. Solution: B

25 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 5. _____ and _____ must each appear on a separate line. All other entries may have several statements on the same line. Solution: Division names; section names

26 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 6. The first two entries of a COBOL program must always be _____ and _____. Solution: IDENTIFICATION DIVISION. PROGRAM-ID. program-name.

27 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 7. Each of the preceding entries must be followed by a _____, which, in turn, must be followed by a ____. Solution: period; space or blank

28 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 8. The first two entries of a program are both coded beginning in Area _____. Solution: A

29 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 9. Code the IDENTIFICATION DIVISION for a program called EXPENSES for a corporation, Dynamic Data Devices, Inc., written July 15, 1997. This program has a security classification and is available to authorized personnel only. It produces a weekly listing by department of all operating expenses.

30 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 9. Suggested solution: IDENTIFICATION DIVISION. PROGRAM-ID. EXPENSES. AUTHOR. N. B. STERN. INSTALLATION. DYNAMIC DATA DEVICES, INC. DATE-WRITTEN. 7/15/97. DATE-COMPILED. SECURITY. AUTHORIZED PERSONNEL ONLY.

31 Structured COBOL Programming, Stern & Stern, 9th Edition SELF-TEST 10. The DATE-COMPILED paragraph usually does not include a comment entry because _____. Solution: the computer itself can supply the date of the compilation (The current date is stored in main memory.)

32 Structured COBOL Programming, Stern & Stern, 9th Edition THE SECTIONS OF THE ENVIRONMENT DIVISION The ENVIRONMENT DIVISION is the only machine-dependent division of a COBOL program. Entries in this division will depend upon: –(1) the computer system and –(2) the specific devices or hardware used in the program.* * Interactive programs that use keyed data as input and display screen output will not need this division.

33 Structured COBOL Programming, Stern & Stern, 9th Edition THE CONFIGURATION SECTION –Supplies information about the computer on which the COBOL program will be compiled and executed. SOURCE-COMPUTER: –The computer that will be used for compiling the program. OBJECT-COMPUTER: - The computer that will be used for executing or running the program. *SOURCE- COMPUTER and OBJECT-COMPUTER are coded primarily as documentation entries.

34 Structured COBOL Programming, Stern & Stern, 9th Edition The CONFIGURATION SECTION All section names, like division names, are coded in Area A. The CONFIGURATION SECTION, if coded, will follow the ENVIRONMENT DIVISION entry in Area A. SOURCE-COMPUTER and OBJECT- COMPUTER, as paragraph-names, would also be coded in Area A.

35 Structured COBOL Programming, Stern & Stern, 9th Edition CONFIGURATION SECTION EXAMPLE ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM AS400. OBJECT-COMPUTER. DEC ALPHA.

36 Structured COBOL Programming, Stern & Stern, 9th Edition INPUT-OUTPUT SECTION The INPUT-OUTPUT SECTION optionally follows the CONFIGURATION SECTION – It supplies information concerning the input and output devices used in the program by means of a FILE-CONTROL paragraph. In the FILE-CONTROL paragraph, a file- name is designated and assigned to a device for each file used in the program.

37 Structured COBOL Programming, Stern & Stern, 9th Edition INPUT-OUTPUT SECTION The FILE-CONTROL paragraph consists of SELECT statements –each is coded in Area B followed by a period. A SELECT statement – defines a file-name. – assigns a device name to that file*. A file is the major collection of data for a given application.

38 Structured COBOL Programming, Stern & Stern, 9th Edition INPUT-OUTPUT SECTION Batch processing applications have an input file and an output file. Interactive processing allows input using a keyboard; – therefore, it is not necessary to establish an input file.

39 Structured COBOL Programming, Stern & Stern, 9th Edition INPUT-OUTPUT SECTION If the output is printed or saved on disk, an output file must exist in the ENVIRONMENT DIVISION. If the output is displayed on a screen, then no file declaration is necessary in the ENVIRONMENT DIVISION. - When this is the case, the ENVIRONMENT DIVISION may be entirely omitted.

40 ASSIGNING FILES TO DEVICES IN THE ENVIRONMENT DIVISION

41 Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT The instruction format for the SELECT statement follows: SELECT file-name-1 ASSIGN TO implementor-name-1 [ORGANIZATION IS LINE SEQUENTIAL] –The implementor-name is a machine- dependent device specification that is typically provided by the computer center.

42 Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT REVIEW OF INSTRUCTION FORMAT RULES 1. Uppercase words are reserved words; lowercase words are user-defined. 2. Underlined words are required in the statement. 3. Two lines are used for a SELECT statement – the second line is indented for “ readability”

43 Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT File-Name Rules 1. The file-name assigned to each device must conform to the rules for forming user-defined words. 2. A user-defined word is a word chosen by the programmer to represent some element in a program such as a file-name:

44 Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT Rules for Forming User-Defined Words (Such as File-Names) 1. 1 to 30 characters. 2. Letters, digits, and hyphens (-) only. 3. No embedded blanks –It is best to use hyphens to separate words (e.g., EMPLOYEE-NAME) 4. At least one alphabetic character.

45 Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT 5. May not begin or end with a hyphen. 6. No COBOL reserved words such as DATA, DIVISION, etc. A full list of reserved words appears in Appendix A and in the COBOL Syntax Reference Guide.

46 Structured COBOL Programming, Stern & Stern, 9th Edition THE NET If you do not have a COBOL Syntax Reference Guide, it can be downloaded from: http://www.wiley.com/cobol/

47 Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT A SELECT statement must be specified for each file in the program,. If a program requires a disk file as input and produces a printed report as an output file, two SELECT statements will be specified. –one file-name will be assigned to the disk file –the other to the print file.

48 Structured COBOL Programming, Stern & Stern, 9th Edition DEBUGGING TIP File names assigned by the programmer should be meaningful. Examples: SALES-IN SALES-REPORT-OUT

49 Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT Implementor-Names or Device Specifications Most systems enable the programmer to access frequently used devices by special device names.

50 Structured COBOL Programming, Stern & Stern, 9th Edition OVERALL FORMAT Implementor-Names or Device Specifications The following are common shorthand device specifications that you may be able to use with your system: PrinterSYSLST or SYS$OUT or PRINTER Disk DISC or DISK followed by a disk file-name

51 Structured COBOL Programming, Stern & Stern, 9th Edition SELECT Statements for PCs 1. Device Specification For input or output files on disk, PC versions of COBOL use device names that specify: (1) The drive on which the disk file appears followed by a colon (e.g., C:, D:, etc.). If your file is in a subdirectory, you must specify that as well (e.g., C:\COBOL).

52 Structured COBOL Programming, Stern & Stern, 9th Edition SELECT Statements for PCs (2) The file-name for that disk file, where the rules for forming file- names are dependent on the operating system. –The device name for these PC versions of COBOL is usually enclosed in quotes: SELECT EMPLOYEE-FILE ASSIGN TO 'C:EMPFILE'. SELECT INVENTORY-FILE ASSIGN TO 'C:\INVENTORY\INVFILE.DAT'.

53 Structured COBOL Programming, Stern & Stern, 9th Edition SELECT Statements for PCs PCs using Windows 3.x or DOS have file-names that are 1 to 8 characters with an optional 1- to 3-character file extension Example: “MYFILE.DAT”

54 Structured COBOL Programming, Stern & Stern, 9th Edition SELECT Statements For PCs PC Disk files are most often created so that they resemble text files. This is done by using a SELECT statement followed by: ORGANIZATION IS LINE SEQUENTIAL. Example: SELECT SALES-FILE ASSIGN TO 'C:\SALES.DAT' ORGANIZATION IS LINE SEQUENTIAL.

55 Structured COBOL Programming, Stern & Stern, 9th Edition COBOL 2000+ CHANGES 1. COBOL 2000+ will eliminate strict adherence to margin rules – Coding rules for Margins A and B will become recommendations, not requirements. 2. The PROGRAM-ID paragraph will be the only one permitted in the IDENTIFICATION DIVISION; – all other entries (e.g., AUTHOR through SECURITY) can be specified as a comment. 3. The maximum length of user-defined names will increase from 30 to 60 characters.

56 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SLIDES END HERE CHAPTER SUMMARY COMES NEXT

57 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY I. The IDENTIFICATION DIVISION A. The IDENTIFICATION DIVISION and its paragraphs are used for documentation and do not affect the execution of the program. B. The first two items to be coded in a program are: IDENTIFICATION DIVISION. PROGRAM-ID. program-name. C. A program name that is up to eight characters, letters and digits only, is acceptable on all computers.

58 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY D. All other paragraphs and identifying information in this division are optional and may include: AUTHOR. INSTALLATION. DATE-WRITTEN. DATE-COMPILED. SECURITY.

59 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY E. Comments can be included in the IDENTIFICATION DIVISION, as well as all other divisions, by coding an * in position 7. –This makes the entire line a comment. –We encourage you to use comments throughout your programs for documentation. F. A slash (/) in column 7 will cause the subsequent lines to be printed on the next page of the source listing.

60 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY II. The ENVIRONMENT DIVISION A. The format for the ENVIRONMENT DIVISION is: ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. computer-name OBJECT-COMPUTER. computer-name INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name-1 ASSIGN TO implementor-name-1

61 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY II. The ENVIRONMENT DIVISION Note: The entire ENVIRONMENT DIVISION is optional for COBOL 85. Fully interactive programs that use keyed data as input and screen displays as output need not have an ENVIRONMENT DIVISION.

62 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY B. The CONFIGURATION SECTION is usually optional and we recommend you omit it. It supplies documentary information on the computer(s) being used. C. The INPUT-OUTPUT SECTION is also optional but must be included if files are assigned to devices in a program. We will always include the INPUT- OUTPUT SECTION for batch processing.

63 Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY D. The ENVIRONMENT DIVISION is the only division of a COBOL program that may vary depending on the computer used. –Obtain the exact device specifications or disk file-name rules from your computer center or your instructor.

64 Structured COBOL Programming, Stern & Stern, 9th Edition THE NET If you do not have a COBOL Syntax Reference Guide, it can be downloaded from: http://www.wiley.com/cobol/


Download ppt "PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert."

Similar presentations


Ads by Google