1 / 16

CODING A COBOL SOURCE PROGRAM (see prelab.cob)

CODING A COBOL SOURCE PROGRAM (see prelab.cob). Coding-Program Sheet-Form. Columns 1-6 Column 7 Columns 8-11  Area A Columns 12-72  Area B Columns 73-80. The starting place for divisions, sections and paragraphs. The starting place for statements and sentences. * Comment / next page

Download Presentation

CODING A COBOL SOURCE PROGRAM (see prelab.cob)

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. CODING A COBOL SOURCE PROGRAM (see prelab.cob) Coding-Program Sheet-Form Columns 1-6 Column 7 Columns 8-11  Area A Columns 12-72  Area B Columns 73-80 The starting place for divisions, sections and paragraphs The starting place for statements and sentences * Comment / next page - Nonnumeric literal Program identification Page and line numbers Chps.2&3 Coding a COBOL Source Program

  2. SOURCE CODE ENTRIES Division Section Paragraph Sentence Statement _____ IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE in this order **B** some divisions are subdivided into sections **C** some sections are subdivided into paragraphs **E** all other entries in the are considered statements _____ a statement or series of statements that end with a period Chps.2&3 Coding a COBOL Source Program

  3. SOURCE CODE ENTRY DETAILS Divisions and Sections • Begins in Area A • Ends with a period • Must appear on a line with no other entries Paragraphs • Begins in Area A • Ends with a period, which must be followed by at least one space • May appear on a line by itself or with other entries Sentences and Statements • Begins in Area B • Sentences end with a period, which must always be followed by at least one space • May appear on lines by themselves or with other entries Chps.2&3 Coding a COBOL Source Program

  4. A GENERIC COBOL PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. xxxxxxx. * ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. * select statements * DATA DIVISION. FILE SECTION. * file descriptions (fd) for each file specified in a select statement WORKING-STORAGE SECTION. * specifies storage locations for other user-defined variables * PROCEDURE DIVISION. 100-start-program. * must contain at least one paragraph * also contains actual executable COBOL statements * STOP RUN. * this statement is highly recommended * not always the last physical statement in a COBOL program! Chps.2&3 Coding a COBOL Source Program

  5. USER-DEFINED DATA NAMES EXAMPLES: Abc-123 abc-123 123abc stop-run kitty- -half 0123456789 TOO-LONG? SECTION NEW EMPLOYEE • 1-30 characters • Letters, digits, hyphens only • Can not start or end with a hyphen • No blanks • At least one alphabetic character • Not a COBOL reserve word • Paragraph names may be all numeric • Should be meaningful Chps.2&3 Coding a COBOL Source Program

  6. SYMBOLS • Punctuation • Period denotes the end of a COBOL entry • Quotes surround non-numeric literals • () encloses subscripts or expressions • Arithmetic • + - * / ** • Relational • = > < >= <= Chps.2&3 Coding a COBOL Source Program

  7. RULES FOR INTERPRETING INSTRUCTION FORMATS • Uppercase words are COBOL reserved words that have a special meaning to the compiler • Underlined words are required in the paragraph • Lowercase words represent user-defined entries • Braces { } denote that one of the enclosed items is required • Bracets [ ] mean the clause or paragraph is optional • If punctuation is specified in the format (ex. period), it is required • The use of dots or ellipses (…) means that additional entries of the same type may be included if desired *** see inside page of book cover Chps.2&3 Coding a COBOL Source Program

  8. IDENTIFICATION DIVISION • Required • Has no effect on the execution of a program • Identifies the program to the computer SYNTAX DEFINITION IDENTIFICATIONDIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry]…] [INSTALLATION. [comment-entry]…] [DATE-WRITTEN. [comment-entry]…] [DATE-COMPILED. [comment-entry]…] [SECURITY. [comment-entry]…] Chps.2&3 Coding a COBOL Source Program

  9. ENVIRONMENT DIVISION • Describes the specific computer equipment that will be used • Only required if using file I/O SYNTAX DEFINITION ENVIRONMENTDIVISION. optional [INPUT-OUTPUTSECTION. FILE-CONTROL. SELECT file-name-1 ASSIGN TO implementor-name-1 [ORGANIZATION IS LINESEQUENTIAL]. …] optional CONFIGURATION SECTION. SOURCE-COMPUTER. OBJECT-COMPUTER. Computer and model number supplied by the manufacturer for the SOURCE and OBJECT computer. Chps.2&3 Coding a COBOL Source Program

  10. DATA DIVISION VOCABULARY file – a major collection of data consisting of records record – a set of related fields treated as a unit field – a group of consecutive characters used to represent a unit of information level number – a number from 01-49 that denotes the hierarchy of data with records; also 77 and 88 group item – a field that is further subdivided into elementary items or fields; does NOT have a pic clause elementary item – a field that contains a picture clause; a field that is not further subdivided • Describes the input and output file formats • Describes any constants and work areas necessary SYNTAX DEFINITION DATADIVISION. FILESECTION. record descriptions (FDs) WORKING-STORAGESECTION. constants and user-defined data names Chps.2&3 Coding a COBOL Source Program

  11. DATA DIVISION About FDs Format: FD file-name-1. 01 record-name-1 … Notes: FD is coded in Area A; matches SELECT The 01 level is termed the record description  specifies the format of a record; shows the number, order and relationship of fields in the record; starts in Area A There can be multiple 01 levels for each FD (but not recommended to start with until you understand COBOL better!) NO VALUE clauses ALLOWED!!! Example FD input-file. 01 input-rec. 05 full-name. 10 first-name pic x(10). 10 middle-init pic x. 10 last-name pic x(20). 05 ssn pic 9(9). 05 address. 10 street-addr. 15 apt-num pic xx. 15 str-num pic 9(5). 15 str-name pic x(20). 05 city pic x(15). 05 state pic xx. 05 zip-code pic 9(5). Chps.2&3 Coding a COBOL Source Program

  12. DATA DIVISION About Level Numbers: 01-49, 77, 88 01 is always coded in Area A; defined as records 02-49 is usually coded starting in Area B; are used to describe fields within a record All fields coded on the same level are independent items Higher level numbers are subordinate to lower level numbers 77 level numbers are considered independent items 88 level numbers are conditional names (discussed more later) FILLER is a COBOL reserve word that denotes a memory location without a name. It is also an optional portion of the COBOL code. 01 ws-page-rec. 03 filler pic x(14) 03 page-header pic x(11) value “Page Header”. 03 pic x(15) Chps.2&3 Coding a COBOL Source Program

  13. DATA DIVISION PICTURE CLAUSES Specifies SIZE and TYPE of data A - alphabetic X - alphanumeric 9 – numeric V – implied decimal point; can only be used for numeric data; does not hold a place in memory EXAMPLES PICTURE X(20) PIC 9(9) PIC A(10) PIC 999 PIC XXXXX pic 999v9999 pic 9(6)v9(2) PIC aaaa note: no spaces allowed… TYPES OF DATA FIELDS Alphabetic – letters or blanks Alphanumeric – any character Numeric – only digits Edited Numeric – later :o) VALUE CLAUSE specifies the initial value for an elementary item ALL Specifies a character or sequence of characters to repeat until the memory location is filled Chps.2&3 Coding a COBOL Source Program

  14. DATA DIVISION TYPES OF DATA Data-name/Identifier – information that is stored and can change Constant – information that stays the same TYPES OF CONSTANTS Numeric literal 1 to 18 digits + or – sign may be used to the left of the number decimal point; cannot be the rightmost character (looks like a period!) note: commas NOT permitted Non-numeric literal Must be enclosed in quotation marks From 1 to 160 characters Any character (see App A) may be used except the quotation mark Case Sensitive Figurative constant – a reserve word SPACES, SPACE – can be moved to A or X defined fields (not 9) ZERO, ZEROS, ZEROES – can be moved to 9 or X fields (not A) ex. “YES” “yes” “END OF REPORT” Chps.2&3 Coding a COBOL Source Program

  15. DATA DIVISION Summary and other Important Information Fields are defined (type,size) in the data division Access the fields in the procedure division (next slide!) Group items are always considered alphanumeric A value clause is never required; however, if omitted, no assumption can be made about the initial contents of the field (use a MOVE instruction to guarantee an initial value) Indent nicely for readability Use descriptive user-defined names Use prefixes/suffixes in records to help you remember the reason for using the user-defined item Continuation of non-numeric literals are a pain. I recommend that you do not attempt this :o) as there are ways around it! Chps.2&3 Coding a COBOL Source Program

  16. PROCEDURE DIVISION • Contains the instructions necessary for reading input, processing it, and creating output SYNTAX DEFINITION Statements (examples) PROCEDUREDIVISION. Paragraph-name-1. statements… SEQUENTIAL TOP-DOWN APPROACH Sequence of statements Top-down approach for coding paragraphs It’s the sequence of the statements that solves the problem you are writing the program for :o) Open Move Read Write Compute Perform Close Stop Run Chps.2&3 Coding a COBOL Source Program

More Related