1 / 36

Business Programming in COBOL

Business Programming in COBOL. Fall, 2004 Karen Ketler. COBOL. CO mmon (machine independent) Business Oriented Language. History - 1959. Conference initiated by Department of Defense

arden
Download Presentation

Business Programming in COBOL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Business Programming in COBOL Fall, 2004 Karen Ketler

  2. COBOL • COmmon (machine independent) • Business • Oriented • Language

  3. History - 1959 • Conference initiated by Department of Defense • Brought Together IBM Other Computer Manufacturers Industry Computer Users Governmental Agencies • Goal: To develop a business-oriented language that would be machine (hardware) independent

  4. Need for Machine Independent Language • Once an organization purchased a particular (e.g., IBM) hardware system, all programs were written in a language geared to that particular hardware system • When it was time to purchase a bigger/better computer system, organizations were already committed to the previous computer vendor • OR they would have to rewrite all of their software programs

  5. Complex Mathematics Unique Processing Little Input Little Output (Solution is usually an answer to a mathematical problem) Simpler Mathematics Repetitious Processing (Multiply Pay Rate by Hours for every employee Much Input (every employee) Much output (payroll check for every employee) Business versus Scientific ApplicationsScientific Business

  6. COBOL Coding Form • Upper Part • Identifies program and programmer • Aids data entry operator in interpreting the programmer’s handwriting • Example: • 2 or Z • O or 0 • Graphic Ø O 2 Z • Punch: zero letter two letter

  7. COBOL Coding Form • Lower Part • Column(s) Description 1 - 6 Sequence Number 7 Comment or Continuation 8 - 11 Margin A 12 - 72 Margin B 73 - 80 Program Identification

  8. Sequence Number • Columns 1 - 6 • Originally used when COBOL statements were punched on cards • Uncoordinated Programmers (such as your instructor) were apt to drop a card deck • A machine called a sorter, was used to resequence the deck in proper order according to columns 1 - 6 • SEQUENCE NUMBERS ARE NO LONGER USED

  9. Comment or Continuation • * in column 7 indicates a COMMENT line • Used for documentation • 1 in column 7 indicates first continuation of a preceding line: 2 indicates the second continuation and so forth • Continuation is rarely used today • Any COBOL statement can be divided into two lines by breaking the statement at any blank (not inside apostrophes)

  10. Margin A and B • Margin A: Columns 8 through 11 • Margin B: Columns 12 through 72 • Certain statements must begin in either Margin A or Margin B • Refer to sample program Examples of Statements Beginning in Margin A Margin B IDENTIFICATION DIVISION SELECT FILE SECTION LABEL RECORDS… 01 03 IF/THEN/PERFORM

  11. Program Identification • Columns 73 - 80 (Usually consists of the program name) • Remember the uncoordinated programmer who needs the sequence numbers in columns 1 - 6? • What if two clumsy programmers bumped into each other, each carrying a card deck? • Identifications codes were used to separate the cards into the two decks • Then, the sequence numbers were used to put each deck in order • IDENTIFICATION CODES (Columns 73 - 80) are no longer used

  12. Four Divisions of a COBOL Program • IDENTIFICATION DIVISION. • ENVIRONMENT DIVISION. • DATA DIVISION. • PROCEDURE DIVISION.

  13. IDENTIFICATION DIVISION • Identifies and documents the program including • Program Name • Author • Date Written • Date Modified • Purpose of Program

  14. ENVIRONMENT DIVISION • Two Sections of the Environment Division • CONFIGURATION SECTION. • Identifies the computer hardware for which the program was originally written • Today, this section is merely used for documentation purposes • Can be OMITTED • INPUT-OUTPUT SECTION • Identifies the peripheral devices needed for the program • Examples: tape drive, disk drive, printer

  15. DATA DIVISION • Three Sections of the Data Division • File Section • Describes the input/output files used in the program • Working-Storage Section • Describes the layout of the input and output files • refer to handouts #6, #8a and #8b • Also used to describe any calculated or miscellaneous fields • Linkage Section • Used to link data items between programs • Will not be used until the advanced classes

  16. PROCEDURE DIVISION • Is divided into paragraphs and statements which contain the logic of the program • COBOL is ENGLISH-Like • In English, a paragraph consists of sentences • In COBOL, a paragraph consists of statements • A statement is a command or an instruction such as OPEN READ WRITE IF STOP

  17. The IDENTIFICATION DIVSION

  18. Three Required Entries of the IDENTIFICATION DIVISION • The header: IDENTIFICATION DIVISION • Must be the first line of the COBOL program • Begins in MARGIN A • PROGRAM-ID. • Must be the second line of the COBOL program • Begins in MARGIN A • program name • Follows the PROGRAM-ID. Entry • Begins in MARGIN B

  19. Three Required Entries of the IDENTIFICATION DIVISION • Example: • IDENTIFICATION DIVISION. • PROGRAM-ID. Program-name. • Anything is small characters (such as Program-name) is a programmer-supplied (made up) name.

  20. Rules for selecting a program-name • 1 - 30 characters • A through Z, 0 through 9, and - (Hyphen) • Hyphen cannot be first or last character of the program-name. • At least one letter must be in the program-name • No embedded blanks • No reserved words (such as READ or IDENTICIFICATION or DIVISION) • Refer to Appendix for a list of reserved words

  21. Program-names • VALID program-names • PROG1 • PROG-1 • PROGRAM1 • INVALID program-names • PROG 1 • PROG-1- • PROGRAM • Some older compilers limit the program-name to eight characters

  22. OPTIONAL STATEMENT IN THE IDENTIFICATION DIVISION • All IDENTIFICATION DIVISION statements (OPTIONAL and REQUIRED) begin in MARGIN A. • The following statements are optional. Select the ones you desire. Be sure they are in the following sequence (but you need not use all of them.) • AUTHOR. Comment. • INSTALLATION. Comment. • DATE-WRITTEN. Comment. • DATE-COMPILED. Comment • SECURITY. Comment • The comments are for documentation only. They may contain any character including the period; but they must end in a period. • Comments can be more than one sentence/line. However, all comment lines must begin in MARGIN B.

  23. The AUTHOR Statement • Identifies the original programmer/team • More than one comment line can be used • The AUTHOR statement begins in MARGIN A • All comments begin in MARGIN B. • Examples • AUTHOR. K. J. KETLER. • AUTHOR. TEAM #1 - KETLER, ADAMS & SMITH. • AUTHOR. TEAM #1 • KAREN KETLER • JOHN ADAMS • BOB SMITH.

  24. The INSTALLATION Statement • Commonly used by consulting firms which write programs for their clients. • EXAMPLES: • AUTHOR. ABC, INC. • INSTALLATION. E.I.U. • AUTHOR. JOHN DOE • ABC, INC. • INSTALLATION. E.I.U. • CHARLESTON, ILLINOIS.

  25. The DATE-WRITTEN Statement • Identifies when the program was originally written • It can be dated such as 09/01/99 or SEPTEMBER 1, 1999 or FALL, 1999. • The comment must end in a period. • Examples: • DATE-WRITTEN. 09/01/99. • DATE-WRITTEN. SEPTEMBER 1, 1999. • DATE-WRITTEN. FALL, 1999.

  26. The DATE-COMPILED Statement • Identifies when the program was most recently compiled/changed • NO comment is needed. • The computer automatically supplies the date. • Example: • DATE-COMPILED.

  27. The SECURITY statement • Identifies whether or not the program contains confidential routines. • REMEMBER: the security statement is merely a comment. NO security is provided by the statement. • Example: • SECURITY. TOP SECRET. • NO PEEKING ALLOWED.

  28. The REMARKS statement • Used ONLY by older compilers at the end of the IDENTIFICATION DIVISION. • NO longer valid • Programmers still include documentation describing the program in the form of comment statements at the end of the IDENTIFICATION DIVISION. • Put an * in COLUMN 7 and then describe the program. • Example: • * THIS PROGRAM USES THE STUDENT ADDRESS • * FILE AND PRINTS THE STUDENTS’ NAMES , • * ADDRESSES, AND PHONE NUMBERS.

  29. Sample IDENTIFICATION DIVISION • IDENTIFICATION DIVISION. • PROGRAM-ID. PROG-1. • AUTHOR. KAREN J. KETLER. • INSTALLATION. E. I. U. • DATE-WRITTEN. SEPTEMBER, 1998. • DATE-COMPILED. • SECURITY. NO PEEKING ALLOWED. • THIS MEANS YOU!. • * THIS PROGRAM USES THE STUDENT ADDRESS • * FILE AND PRINTS THE STUDENTS’ NAMES, • * ADDRESSES AND PHONE NUMBERS.

  30. The ENVIRONMENT DIVSION

  31. ENVIRONMENT DIVISION • CONFIGURATION SECTION. • Widely used in the early 1960s • Used to document what hardware system the hardware was originally written for. • Organizations were skeptic about COBOL’s multi-system commonality during the 1960s • Generally not used today. • INPUT-OUTPUT SECTION. • Must be used with File Processing which is typical in most business applications (versus scientific applications) - See Slide 4 • Otherwise, it is optional

  32. CONFIGURATION SECTION • Identifies the source and object computer for which the program was originally written • Source computer: The computer with which the program is compiled. • Object computer: The computer on which the program is executed • Usually, but not always, the same • Example of when they are different: • State Farm: Programmers write and compile programs on the mainframe system at corporate headquarters • But, the program is executed on the small computers in the agents offices.

  33. CONFIGURATION SECTION • Example: • ENVIRONMENT DIVISION. • CONFIGURATION SECTION. • SOURCE-COMPUTER. IBM-9381. • OBJECT-COMPUTER. IBM-9381. • The entry after Source (Object) Computer is optional. For documentation only

  34. INPUT-OUTPUT SECTION • Identifies the files and the peripheral devices (such as a printer or disk drive) needed by the program • Most Important Statement: SELECT • SELECT file-name ASSIGN TO device.

  35. SELECT Statement • File Name • Created by programmer • Same rules as the program-name • Usually includes the word FILE in the name. • Device • DA-S-jclname for disk drive • UR-S-jclname for printer • jclname • 1 - 8 characters; A-Z, 0-9 • First character alphabetic • Only used in SELECT statement and in a JCL line (//) at the end of the COBOL program • Links the file name in COBOL with the actual data

  36. Sample ENVIRONMENT DIVISION • ENVIRONMENT DIVISION. • INPUT-OUTPUT SECTION. • FILE-CONTROL. • SELECT DISK-FILE ASSIGN TO DA-S-DISK. • SELECT PRINT-FILE ASSIGN TO UR-S-PRINT.

More Related