COBOL 128 Software System - VTDAvtda.org/docs/computing/Abacus/Abacus_COBOL128... · Any references...

of 169 /169
COBOL 128 Software System By K. A. Alexander Published by Abacus ;mHHHI Software

Embed Size (px)

Transcript of COBOL 128 Software System - VTDAvtda.org/docs/computing/Abacus/Abacus_COBOL128... · Any references...

  • COBOL 128 Software System

    By K. A. Alexander

    Published by

    Abacus ;mHHHI Software

  • Copyright Notice

    Abacus Software makes this package available for use on a single computer only. It is unlawful to copy any portion of this software package onto any medium for any purpose other than backup. It is unlawful to give away or resell copies of this package. Any unauthorized distribution of this product deprives the authors of their deserved royalties. For use on single-site multiple computers, please contact Abacus Software to make arrangements.

    Wananty

    Abacus Software makes no warnings, expressed or implied, as to the fitness of this software package for any particular purpose. In no event will Abacus Software be liable for consequential damages. Abacus Software will replace any copy of this software which is unreadable, if returned within 30 days of purchase. Thereafter, there will be a nominal charge for replacement.

    First printing Printed in U.S.A. Copyright © 1984 Copyright© 1986

    July 1986

    K.A. Alexander, Visionary Software Abacus Software, Inc. P.O. BOX 7219 Grand Rapids, MI. 49510

    ISBN# 0-916439-78-X

  • ( COBOL 128 Supplement )

  • Abacus Software COBOL 128

    I COBOL 64 AND COBOL 128 - DIFFERENCES

    The manuals for COBOL 64 and COBOL 128 are the same. There are a few minor differences in the two versions:

    COBOL64 COBOL128

    CORD program overlay in memory COED IT program overlay in memory COSYN program overlay in memory COSYNP program overlay in memory load procedure RUN "VSLOADER" monitor or television 40 or 80 column monitor/TV

    Any references to COBOL 64 throughout this manual also apply to COBOL 128.

    II CONVERTING COBOL 64 CODE TO COBOL 128

    To convert a COBOL 64 programs to run on the Commodore 128 using COBOL 128, follow the procedures listed below.

    1. With COBOL 64 on a C-64 (C-128 in C-64 mode), create a sequential file of the program by using the CRUNCH option from the MAIN MENU. The filename is prefixed by the letters cs (for COBOL Sequential).

    2. Load and run COBOL 128. Replace the COBOL 128 distribution diskette with a diskette containing the sequential file.

    3. Enter CRIP (for CRUNCH input).

    4. Now enter the filename without the cs prefix followed by .

  • Abacus Software COBOL 128

    5. The crunched file is then converted to a format compatible to COBOL 128.

    III CONVERTING COBOL 128 CODE TO COBOL 64

    To convert a COBOL 128 programs to run on the Commodore 64 using COBOL 64, follow the procedures listed below.

    1. With COBOL 128 on a C-128, create a sequential file of the program by using the CRUNCH option from the MAIN MENU. The filename is prefixed by the letters cs (for COBOL Sequential).

    2. Load and run COBOL 64. Replace the COBOL 64 distribution diskette with a diskette containing the sequential file.

    3. Enter CRIP (for CRUNCH input).

    4. Now enter the filename without the cs prefix followed by .

    5. The vs ED IT program overlay will now run. When VSEDIT is done, press any key to continue.

    6. The crunched file is then converted to a format compatible toCOBOL64.

  • PREFACE

    It is assumed that the readers of this manual are familiar with the Commodore 64 computer and general programming techniques.

    The names used in this publication are not of individuals living or otherwise. Any similarity or likeness of the names used in this publication with the names of any individuals, living or otherwise, is purely coincidental and not intentional.

    Abacus Software believes that the information described in this manual is accurate and reliable, and much care has been taken in its preparation. However, no responsibility, financial or otherwise, is accepted for any consequences arising out of the use of this material. The information contained herein is subject to change.

    ACKNOWLEDGEMENT

    COBOL is an industry language and is not the property of any company or group of companies, or of any organization or group of organizations.

    No warranty, expressed or implied, is made by any contributor or by the CODASYL Programming Language Committee as to the accuracy and functioning of the programming system and language. Moreover, no responsibility is assumed by any contributor, or by the committee, in connection therewith.

    The authors and copyright holders of the copyrighted material used herein,

    Flow-matic (trademark of Sperry Rand Corporation). Programming for the UNIVAC I and II, Data Automation Systems copyrighted 1958, 1959, by Sperry Rand Corporation; IBM Commercial Translator Form Number F 28-8013, copyrighted 1959 by IBM;FACT, DSI 27A5260-2760, copyrighted 1960 by Minneapolis-Honeywell,

    have specifically authorized the use of this material in whole or in part, in the COBOL specifications. Such authorization extends to the reproduction and use of COBOL specifications in programming manuals or similar publications.

  • TABLE OF CONTENTS

    Chapter 1 - Introduction Chapter 2 - The Nature of COBOL IN GENERAL Chapter 3 - COBOL Advantages Chapter 4 - COBOL 64 Implementation Notes Chapter 5 - Hardware Consideration Chapter 6 - COBOL 64 Source Language

    Section 1--Program Organization Section 2--Language Concepts Section 3--Editing Format Section 4--IDENTIFICA TION DIVISION Section 5--ENVIRONMENT DIVISION Section 6--DAT A DIVISION Section 7--PROCEDURE DIVISION

    ACCEPT ACCEPT-1-KEY ADD CLOSE DEBUG-BREAK DEBUG-TRACE-OFF DEBUG-TRACE-ON DISPLAY DIVIDE EXIT FILTER-NUMERIC GOTO IF MOVE MULTIPLY OPEN PERFORM READ SET STOP RUN SUBTRACT WRITE

    Chapter 7 -- Start Up/Operating Instructions

    1 2 4 5 6 7 7 9

    29 32 34 47 75 85 86 87 89 89 89 90 90 91 93 93 95 96 98

    102 103 105 108 110 112 113 115

    119

  • Chapter 8 -- Main Menu 120 CRUNCH 121 DEBUG 122

    START-PROO 123

    """' RESUME-PROO 124 SINGLE-ON 124 SINGLE-OFF 124 EXIT 124 BREAK 1 125 BREAK2 125 BREAK3 125 OPTIONS 125 TRACE-ON-LINE 125 TRACE-OFF-LINE 125 TRACE-FAST 126 TRACE-SLOW 126 TRACE-ON 126 TRACE-OFF 127 RESET-OPTIONS 127

    EDIT 128 COBOL 64 Statements 128 ...,,, DIRECTORY 129 LIST 130 DELETE 130 SYNTAX 131 AUTO 132 SAVE 132 RESEQUENCE 133 PRINT-ON 133 PRINT-OFF 133 EXIT 133

    GET 134 NEW-NAME 134 NEW-PROO/EDIT 134 PRINT-ON 135 PRINT-OFF 135 RUN 135 SAVE 136

    APPENDIX A - Sample Program/Exercises 137 """" APPENDIX B - Reserved Words 143 APPENDIX C - Language Summary 144 APPENDIX D - Sample Programs 146

  • Abacus Software COBOL 64

    CHAPTERl

    INTRODUCTION

    This manual provides a complete description of the COBOL 64 System as implemented for use on the Commodore 64 computer or equivalent. The COBOL 64 programming language is designed along the guidelines of the American National Standards Institute (ANSI) X3.23-1974.

    The language is an easy to learn subset of the ANSI 1974 standard Level 1 with appropriate extensions to utilize COMMODORE 64 features as well as providing high level program debugging capabilities. With COBOL 64 there is no need for the user to be concerned with machine language, memory addressing or hexadecimal notation. All debugging is performed at the source language (symbolic) level as opposed to the machine language level.

    The COBOL 64 software system is a combination of an Editor, Compiler, Interpreter and Symbolic Debugger. These features have been designed with ease of learning and ease of use in mind to provide a powerful programming development tool for general business applications.

    Commodore 64 is a registered trademark of Commodore Business Machines, Inc.

    1

  • Abacus Software COBOL 64

    CHAPTER2

    THE NATURE OF COBOL IN GENERAL

    COBOL is the most widespread commercial programming language in use today. The reasons for its vast success will be discussed below.

    The word COBOL is an abbreviation for .Common B.usiness Qriented Language. It is a Business Oriented computer language designed for commercial applications. The rules governing the use of the language make it applicable for commercial problems.

    COBOL is a computer language that is common to many computers. That is most computers can process a COBOL program with minor variations.

    The universality of COBOL, therefore, allows computer users greater flexibility. A company is free to use computers of different manufacturers while retaining a single programming language. "'111 Similarly, conversion from one model computer to a more advanced or newer one presents no great problem. Computers of a future generation will also be equipped to use COBOL.

    Since its creation in 1959, the COBOL language has undergone extensive refinement in an effort to make it more standardized The American National Standards Institute (ANSI), an association of computer manufacturers and users, has developed an industry-wide standard COBOL.

    Thus the meaning of the word COBOL suggests two of its basic advantages. It is common to most computers, and it is commercially oriented. There are, however, additional reasons why it is such a popular language.

    COBOL is an English-like language. All instructions are coded using English words rather than complex codes. To add two numbers together, for example, we use the word ADD. Another example of a COBOL statement is:

    2

  • Abacus Software COBOL 64

    MULTIPLY HOURS-WORKED BY HOURLY-WAGE GIVING GROSS-WAGES

    The rules for programming in COBOL conform to many of the

    rules for writing in English, making it a relatively simple language

    ~ to learn. It, therefore, becomes significantly easier to train

    programmers. In addition, COBOL programs are written and

    tested in far less time than programs written in other computer

    languages.

    Thus the English-like quality of COBOL makes it easy to write programs. Similarly, this quality makes COBOL programs easier

    to read. Such programs can generally be understood by non-data

    processing personnel. The business executive who knows little

    about computers can better understand the nature of a programming

    job simply by reading a COBOL program.

    3

  • Abacus Software COBOL 64

    CHAPTER3

    COBOL ADVANTAGES

    The long list of COBOL advantages is derived chiefly from its intrinsic quality of permitting the programmer to state the problem solution in English prose, and thus provide automatic program and system documentation. When users adopt well-chosen data-names before attempting to program a system, maximum documentational advantages of the language described herein are obtained.

    To a computer user, COBOL 64 offers the following major advantages:

    1. Expeditious means of program implementation providing a high degree of programmer productivity.

    2. Accelerated programmer training and simplified retraining requirements.

    3. Reduced conversion costs when changing from a computer of one manufacturer to that of another.

    4. Significant ease of program modification/enhancements due to the high level of readability.

    5. Documentation which facilitates nontechnical management participation in data processing activities.

    6. A comprehensive source program diagnostic capability which includes tracing, break points and single step features.

    4

  • Abacus Software COBOL 64

    CHAPTER4

    COBOL 64 IMPLEMENTATION NOTES

    A program written in COBOL 64, called a source program, is accepted as input by the COBOL 64 software system. The system verifies that each source statement is syntactically correct, and then converts them into an intermediate condensed representation.

    The intermediate program can then be executed on the Commodore 64 System using the COBOL 64 Interpreter. The interpreter causes the system hardware to perform the operations specified by the intermediate program and thus the source program.

    5

  • Abacus Software COBOL 64

    CHAPTERS

    HARDWARE CONSIDERATIONS

    COMMODORE 64 Computer or equivalent (BASIC V2) One to four Commodore 1541 disk drives or equivalent One optional Commodore 1525 printer or equivalent

    6

  • Abacus Software COBOL 64

    CHAPTER6

    SECTION 1 PROGRAM ORGANIZATION

    COBOL 64 SOURCE PROGRAM DIVISIONS

    Every COBOL 64 source program must contain these four di visions in the following order:

    IDENTIFICATION ENVIRONMENT DATA PROCEDURE

    The IDENTIFICATION DIVISION identifies the program. In addition to required information, the programmer may include such optional pieces of information as the date written and programmer's name for documentation purposes. This division is completely machine-independent.

    The ENVIRONMENT DIVISION specifies the equipment being used. It contains computer descriptions and some information about the files the program will use.

    The DATA DIVISION contains not only file and record descriptions describing the data files that the program manipulates or creates, but also the individual logical records which comprise these files. The characteristics or properties of the data are described in relation to a standard data format rather than an

    equipment-oriented format. Therefore, this division is to a large extent, computer-independent. While compatibility among

    computers cannot be absolutely assured, careful planning in the data layout will permit the same data descriptions, with minor

    modification, to apply to more than one computer.

    The PROCEDURE DIVISION specifies user-supplied steps for computer execution. These steps are expressed in terms of

    meaningful English words, statements, sentences, and paragraphs.

    This division of a COBOL 64 program is often referred to as the

    7

  • Abacus Software COBOL 64

    "program". In reality, it is only part of the total program, and alone is insufficient to describe the entire program. This is true because repeated references must be made (either explicitly or implicitly) to information appearing in the other divisions. This division, more than any other, allows the user to express thoughts in meaningful English. Concepts of verbs to denote actions, and sentences to describe procedures are basic, as is the use of conditional statements to provide alternative paths of action.

    REQUIRED HEADERS

    The standard for COBOL 64 requires that a program consist of certain divisions, sections, and fixed paragraph names known as headers.

    The following elements are the minimum required for a COBOL 64 program:

    IDENTIFICATION DIVISION. PROGRAM-ID. MINIMUM.

    ENVIRONMENT DIVISION. CONFIGURATION SECTION.

    SOURCE-COMPUTER C64. OBJECT-COMPUTER C64.

    DATA DIVISION. PROCEDURE DIVISION. STARTUP.

    STOP RUN.

    8

  • Abacus Software COBOL 64

    SECTION 2 LANGUAGE CONCEPTS

    GENERAL

    As stated in Section 1, COBOL 64 is a language based on English and is composed of words, statements, sentences, and paragraphs. The following paragraphs define the rules to be followed in the creation of this language. The use of the different constructs formed from the created words is covered in subsequent sections of this document.

    LANGUAGE DESCRIPTION NOTATION

    A nearly universal form of notation exists for COBOL reference manuals. This manual uses that notation as described in the paragraphs that follow.

    The apostrophe ( ' ) is used to delimit characters with specific meaning. Other than its use in this manual as a delimiter, it has no specific use in the COBOL language.

    KEYWORDS

    All underlined upper-case words are key words and are required when utilizing related functions. Omissions of key words will cause error conditions at compilation time. An example of key words follows:

    IF data-name IS [NOT] {NUMERIC }

    ALPHABETIC

    The key words are I F , N o T , N u ME R I c , and ALPHABETIC.

    9

  • Abacus Software COBOL 64

    OPTIONAL WORDS

    All upper case words not underlined are optional words included for readability only and may be included or ...__.. excluded in the source program. In the preceding example, .,, the optional word is IS.

    GENERIC TERMS

    All lower-case words represent generic terms which are used to represent COBOL w~rds, literals, PI CT URE character-strings, comment-entries, or a complete syntactical entry that must be supplied in that format position by the programmer. Where generic terms are repeated in a general format, a number or letter appendage to the term serves to identify that term for explanation or discussion.

    Identifier-1 and identifier-2 are generic terms in this example:

    MOVE identifier-1 TO identif ier-2

    BRACES

    The following symbols are braces: { } . When words or phrases are enclosed in braces, a choice of one of the entries must be made. In the previous example in the subsection titled Keywords, either NUMER I c or ALPHABETIC must be included in the statement.

    BRACKETS

    The following symbols are brackets: [ ] . Words and phrases enclosed in brackets represent optional portions of a statement. A programmer wishing to include the optional """'11 feature may do so by including the entry shown between brackets. Otherwise, the optional portion may be omitted. [NOT J in the example titled Keywords, is optional.

    10

  • Abacus Software COBOL 64

    LEVEL-NUMBERS

    When specific level-numbers appear in data description

    entry formats those specific level-numbers are required when such entries are used in a COBOL 64 program. In

    this document, the form O 1, O 2, ... , O 9 is used to

    indicate level-numbers 1 through 9.

    ELLIPSIS

    The presence of the ellipsis (three consecutive

    periods( ... ) within any format indicates the position at

    which repetition may occur at the programmer's option.

    The portion of the format that may be repeated is defined in the following paragraph.

    The ellipsis applies to the words between the determined

    pair of delimiters. Given the ellipsis in a clause or statement format, scanning right to left, determine the right

    bracket or right brace immediately to the left of the ... ;

    continue scanning right to left and determine the logically

    matching left bracket or left brace.

    11

  • Abacus Software COBOL 64

    CHARACTER SET

    The COBOL 64 character set for the COBOL 64 System consists of the following 46 characters:

    O through 9 A through Z

    blank or space + plus sign - minus sign or hyphen * asterisk I slash $ currency sign . period or decimal point " quotation mark ( left parenthesis ) right parenthesis

    CHARACTERS USED FOR WORDS

    The character set for words consists of the following 3 7 characters:

    0 through 9 A through z - (hyphen)

    PUNCTUATION CHARACTERS

    The following characters may be used for program punctuation:

    " quotation mark ( left parenthesis ) right parenthesis

    space or blank . period

    12

  • Abacus Software COBOL 64

    EDITING CHARACTERS

    The COBOL 64 System accepts the following characters in editing:

    $ currency sign

    * asterisk (check protect)

    ' comma

    I slash B space or blank insert 0 zero insert + plus sign

    minus sign CR credit DB debit z zero suppress

    period

    LANGUAGE STRUCTURE

    The individual characters of the language are concatenated to form character-strings and separators. A separator may be concatenated with another separator or with a character-string.

    A character-string may only be concatenated with a separator. The concatenation of character-strings and separators forms the text of a source program.

    SEPARATORS

    A separator is a string of one or more punctuation characters. The rules for formation of separators are:

    1. The punctuation character space is a separator. Anywhere a space is used as a separator, more than one space may be used.

    2. The punctuation character period is a separator when immediately followed by a space.

    13

  • Abacus Software COBOL 64

    3. The punctuation character quotation mark is a separator. An opening quotation mark must be immediately preceded by the separator space, a closing quotation mark must be immediately followed by one of the separators space or "'11111 period followed by a space. Quotation marks may appear only in balanced pairs delimiting nonnumeric literals except when the literal is continued.

    4. The punctuation characters right and left parentheses are separators. Parentheses may appear only in balanced pairs of left and right parentheses delimiting subscripts or indices. The right parentheses must be followed by a space.

    5. The separator space may optionally immediately follow any separator except the opening quotation mark. In this case, a following space is considered as part of the nonnumeric literal and not as a separator.

    Any punctuation character which appears as part of the specification of a PI CT URE character-string or numeric literal is not considered as a punctuation character, but rather as a symbol used in the specification of that PICTURE character-string or numeric literal. PICTURE character-strings are delimited only by the separators space or period followed by a space.

    The rules established for the formation of separators do not apply to the characters which comprise the contents of nonnumeric literals, comment-entries, or comment lines.

    CHARACTER-STRINGS

    A character-string is a character of sequence of contiguous characters which forms a COBOL 64 word, literal, PICTURE character-string, or comment-entry. A character-string is delimited by separators.

    14

  • Abacus Software COBOL 64

    DEFINITION OF WORDS

    A COBOL 64 word is created from a combination of not more than 30 characters, selected from the following:

    O through 9 A through z - (hyphen)

    A word is ended by a valid separator. A word may not begin or end with a hyphen. (A literal constitutes an exception to these rules, as explained in a paragraph entitled Literals in this section.) A word must begin with an alphabetic character.

    A user-defined word is a COBOL 64 word that must be supplied by the user to satisfy the format of a clause or statement

    TYPES OF WORDS

    COBOL 64 contains the following word types:

    nouns (user-defined words) verbs reserved words.

    15

  • Abacus Software

    NOUNS

    Nouns are divided into special categories:

    File-name Record-name Data-name Program-name Index-name Paragraph-name

    COBOL 64

    The length of a noun must not exceed 30 characters. For purposes of readability, a noun may contain one or more hyphens. However, the hyphen must neither begin nor end the noun (this does not apply to literals).

    All nouns within a given category must be unique, because no other noun in the same source program has identical spelling or punctuation. All user-defined words must begin with an alphabetic character.

    File-Name

    A file-name is a noun assigned to designate a set of data items. The contents of a file are divided into logical records made up of any consecutive set of data items.

    Record-Name

    A record-name is a noun assigned to identify a logical record. A record can be subdivided into a set of data items, each distinguishable by a data-name.

    Data-Name

    A data-name is a noun assigned to identify elements within 'tfllll a record or work area and is used in COBOL 64 to refer to an element of data, or to a defined data area containing data elements.

    16

  • Abacus Software COBOL 64

    Index-Name

    An index-name is a word that names an index associated with a specific table (refer to Indexing in this section). An index is a register, the contents of which represent the character position of the first character of an element of a table with respect to the beginning of the table.

    Paragraph-Name

    Verbs

    A paragraph-name is a word which names a paragraph in the PROCEDURE DIVISION.

    A verb in COBOL 64 is a single word that denotes action, such as ADD, WRITE, or MOVE. All allowable verbs in COBOL 64, with the exception of the word IF, are English verbs. The usage of the COBOL 64 verbs takes place within the PROCEDURE DIVISION.

    17

  • Abacus Software COBOL 64

    RESERVED WORDS

    A reserved word is a COBOL 64 word that is one of a specified list of words which may be used in COBOL 64 source programs, but must not appear in the programs as user-defined words. Refer to Appendix B, Reserved Words.

    These rules apply to the entire COBOL 64 source program; no exceptions exist for specific divisions or statements.

    There are two types of reserved words:

    KEY WORDS

    Key words Optional words

    A key word is a word whose presence is required in a source program. Within each format, such words are upper-case and underlined.

    Key words are of three types:

    1. Verbs such as ADD and READ.

    2. Required words which appear in statement and entry formats.

    3. Words which have a specific functional meaning such as SECTION.

    OPTIONAL WORDS

    Optional words are included in the COBOL 64 language to improve the readability of the statement formats. These optional words may be included or omitted. For example, IF A IS GREATER THAN B •.• is equivalent to IF A GREATER B ••• ; the inclusion or omission of the words Is and THAN does not influence the logic of the statement.

    18

  • Abacus Software COBOL 64

    LITERALS

    A literal is an item of data whose value is implied by an ordered set of characters of which the literal is composed. There are two classes of a literal: numeric and nonnumeric.

    NUMERIC LITERAL

    A numeric literal is a character-string whose characters are selected from the digits O through 9, the plus sign (+),the minus sign (-), and/or the decimal point. Numeric literals may be from 1 to 18 digits in length. The rules for the formation of numeric literals are as follows:

    1. A numeric literal must contain at least one digit

    2. A numeric literal must not contain more than one sign character. If a sign is used, it must appear as the leftmost character of the literal. If the literal is unsigned, the literal is positive.

    3. A numeric literal must not contain more than one decimal point. The decimal point is treated as an assumed decimal point, and may appear anywhere within the literal except as the rightmost character. If the literal contains no decimal point, the literal is an integer. An integer is a numeric literal which contains no decimal point.

    If a literal conforms to the rules of the formation of numeric literals, but is enclosed in quotation marks, it is a nonnumeric literal and is treated as such by the system.

    4. The value of a numeric literal is the algebraic quantify represented by the characters in the numeric literal. Every numeric literal belongs to category numeric. Refer to the P I c Tu RE clause in Section 6 for additional information. The size of a numeric literal in standard data format characters is equal to the number

    19

  • Abacus Software COBOL 64

    of digits specified by the user. The following are examples of numeric literals:

    NONNUMERIC LITERAL

    51678 .005 +2.629 -.8479

    6287.92

    A nonnumeric literal may be composed of any allowable character. The beginning and ending of a nonnumeric literal are both denoted by a quotation mark. Any character enclosed within quotation marks is part of the nonnumeric literal. Subsequently, all spaces enclosed within the quotation marks are considered part of the literal. Two consecutive quotation marks within a nonnumeric literal cause a single quotation mark to be inserted into the literal string.

    All other punctuation characters are part of the value of the nonnumeric literal rather than separators; all nonnumeric literals belong to category alphanumeric. Refer to the PICTURE clause in Section 6.

    A nonnumeric literal cannot exceed 120 characters. Examples of nonnumeric literals are:

    Literal on Source Program Level Literal Stored by System

    "THE TOTAL PRICE" "-2080.479" "A""B"

    THE TOTAL PRICE -2080.479 A"B

    Literals that are used for arithmetic computation must be expressed as numeric literals and must not be enclosed in quotation marks as nonnumeric literals. For example, _...... " 4 . 4 " and 4 . 4 are not equivalent. The system stores the ..._,, nonnumeric literal as 4 . 4, whereas the numeric literal would be stored as 0044 ifthe PICTURE were 999V9,

    20

  • Abacus Software COBOL 64

    with the assumed decimal point located between the two fours.

    '-" LOGICAL RECORD AND FILE CONCEPTS

    The purpose of defining file information is to distinguish between the physical aspects of the file and the conceptual characteristics of the data contained within the file.

    PHYSICAL ASPECTS OF A FILE

    The physical aspects of a file describe the data as it appears on the input or output media and include such features as:

    1. The grouping of logical records within the physical limitations of the file medium.

    2. The means by which the file can be identified.

    CONCEPTUAL CHARACTERISTICS OF A FILE

    The conceptual characteristics of a file are the explicit definition of each logical entity within the file itself. In a COBOL 64 program, the input or output statements refer to one logical record.

    It is important to distinguish between a physical record and a logical record. A COBOL 64 logical record is a group of related information, uniquely identifiable, and treated as a unit.

    A physical record is a physical unit of information whose size and recording mode are adapted to a particular computer for the storage of data on a input or output device. The size of a physical record is hardware dependent and has no direct relationship to the size of the file of information contained on a device.

    The concept of a logical record is not restricted to file data but is carried over into the definition of working storage.

    21

  • Abacus Software COBOL 64

    Working storage may be grouped into logical records and defined by a series of record description entries.

    RECORD CONCEPTS

    The record description consists of a set of data description entries which describe the characteristics of a particular record. Each data description entry consists of a level-number followed by a data-name, if required, followed by a series of independent clauses, as required.

    CONCEPT OF LEVELS

    A level concept is inherent in the structure of a logical record. This concept arises from the need to specify subdivisions of a record for the purpose of data reference. Once a subdivision has been specified, it may be further subdivided to permit more detailed data referral.

    DATA DESCRIPTION CONCEPTS

    The most basic subdivisions of a record, those not further subdivided, are called elementary items; consequently, a record is said to consist of a sequence of elementary items, or the record itself may be an elementary item.

    In order to refer to a set of elementary items, the elementary items are combined into groups. Each group consists of a named sequence of one or more elementary items. Groups, in tum, may be combined into groups of two or more groups. An elementary item may belong to more than one group.

    22

  • Abacus Software COBOL 64

    LEVEL-NUMBERS

    A system of level-numbers shows the organization of elementary items and group items. Since records are the most inclusive data items, level-numbers for records start at 01. Less inclusive data items are assigned higher (not necessarily successive) level-numbers not greater in value than 10. There is a special level-number 77 which is an exception to this rule. Separate entries are written in the source program for each level-number used.

    A group includes all group and elementary items following it until a level-number less than or equal to the level-number of that group is encountered. All items which are immediately subordinate to a given group item must be described using identical level-numbers greater than the level-number used to describe that group item. Refer to Section 6 under LEVEL-NUMBER for additional information.

    CONCEPT OF CLASSES OF DATA

    The five categories of data items (refer to the PICTURE clause in Section 6) are grouped into three classes: alphabetic, numeric, and alphanumeric. For alphabetic and numeric, the classes and categories are synonymous. The alphanumeric class includes the categories of alphanumeric edited, numeric edited, and alphanumeric (without editing). Every elementary item, except for an index data item, belongs to one of the classes and also to one of the categories. The class of a group item is treated as alphanumeric regardless of the class of elementary items subordinate to that group item. Table 2-1 shows the relationship of the class and categories of data items.

    23

  • Abacus Software COBOL 64

    Table 2-1. Classes of Data

    LEVEL OF ITEM

    Elementary

    Nonelementary (Group)

    ALGEBRAIC SIGNS

    CLASS

    Alphabetic

    Numeric

    Alphanumeric

    Alphanumeric

    CATEGORY

    Alphabetic

    Numeric

    Numeric Edited Alphanumeric Edited Alphanumeric

    Alphabetic Numeric Numeric Edited Alphanumeric Edited Alphanumeric

    Algebraic signs fall into two categories: operational signs, ""1IJI which are associated with signed numeric data items and signed numeric literals to indicate algebraic properties; and editing signs, which appear on edited reports to identify the sign of the item.

    Operational signs are represented as defined under symbol 's' of the p ICTURE clause. Refer to the p ICTURE clause, General Rule 8, the ' s ' symbol in Section 6. Editing signs are inserted into a data item through the use of the sign control symbols of the PICTURE clause.

    24

  • Abacus Software COBOL 64

    STANDARD ALIGNMENT RULES

    The standard rules for positioning data within an elementary item depend on the category of the receiving item. These rules are:

    1. If the receiving data item is described as numeric:

    a. The data is aligned by decimal point and is moved to the receiving character positions with zero fill or truncation on either end as required.

    b. When an assumed decimal point is not explicitly specified, the data item is treated as if it had an assumed decimal point immediately following the rightmost character and is aligned as in step la above.

    2. If the receiving data item is a numeric edited data item, the data moved to the edited data item is aligned by decimal point with zero fill or truncation at either end as required within the receiving character positions of the data item, except where editing requirements cause replacement of the leading zeros.

    3. If the receiving data item is alphanumeric (other than a numeric edited data item), alphanumeric edited or alphabetic, the sending data is moved to the receiving character positions and aligned at the left-most character position in the data item with space fill or truncation to the right, as required.

    25

  • Abacus Software COBOL 64

    SUBSCRIPTING

    Subscripts can be used only when reference is made to an individual element within a list or table of like elements that have not been assigned individual data-names (refer to the ~ OCCURS clause in Section 6).

    The subscript can be represented either by a numeric literal that is an integer or by a data-name. The data-name must be a numeric elementary item that represents an integer. When the subscript is represented by a data-name, the data-name may not be subscripted.

    The subscript may be signed and, if signed, must be positive. The lowest possible subscript value is 1. This value points to the first element of the table. The next sequential elements of the table are pointed to by subscripts whose values are 2, 3, and so forth. The highest permissible subscript value, in any particular case, is the maximum number of occurrences of the item as specified in the OCCURS clause.

    At the time of execution of a statement which refers to a subscripted table element, each subscript specified is validated. That is, its value must not be less than one or more than the maximum number of occurrences as specified by the corresponding OCCURS clause. If the subscript value is not within this range, an abnormal termination of the program occurs.

    The subscript or set of subscripts that identifies the table element is delimited by the balanced pair of separators, left parenthesis and right parenthesis, following the table element data-name. The table element data-name appended with a subscript is called a subscripted data-name or an identifier.

    When more than one subscript is required, they are written in the order of successively less inclusive dimensions of the data organization. The maximum number of subscripts is 3.

    26

  • Abacus Software COBOL 64

    General Format:

    data-name ( subscript-1 [ subscript-2 [ subscript-3 J J )

    Example:

    I n the following record description, to reference the first year, TOTAL-PER-YEAR (1) is written. If data-name YE AR contains the number of the year desired, TOTAL-PER-YEAR (YEAR) is written. If the data item MONTH contains the specific month desired within the year specified by YEAR, TOTAL-PER-MONTH (YEAR MONTH) is written.

    01 YEAR-TABLE. 02 TOTAL-PER-YEAR OCCURS 10 TIMES.

    05 TOTAL-PER-MONTH OCCURS 12 TIMES PIC 999.

    77 YEAR PIC 99.

    77 MONTH PIC 99.

    ~ INDEXING

    References can be made to individual elements within a table of like elements by specifying indexing for that reference. An index is assigned to that level of the table by using the INDEXED BY phrase in the definition of a table. A name given in the INDEXED BY phrase is known as an index-name and is used to refer to the assigned index. The value of an index corresponds to the occurrence number of an element in the associated table. An index-name can be given a value by the execution of a SET statement

    The advantage to indexing is derived by faster execution time when multiple references to the same table element is required. In subscripting a multiply function is needed each time a reference is made. In indexing the multiply only occurs during execution of the SET statement and not each time a reference is made.

    27

  • Abacus Software COBOL 64

    An index-name has the same internal representation as an index data item. If a value to be stored in an index-name or in an inde~ data item exceeds the largest value that can be held in that index-name or index data item, the value is truncated according to the rules for the occurrence of a size """1111 error condition in an arithmetic statement without a s I z E . . ERROR phrase.

    An index-name assigned to one table may not be used to index another table.

    Direct indexing is specified by using an index-name in the form of a subscript. When more than one index-name is required, they are written in the order of successively less inclusive dimensions of the data organization as in subscripting.

    At the time of execution of a statement which refers to an indexed table element, the value of each direct index must not be less than a value which corresponds to the beginning of the first occurrence of the table element. Also, the index must not be greater than a value which · corresponds to the beginning of the last occurrence of the """1111 table element as specified by the corresponding OCCURS clause. If the index value is not within this range, the execution of the program is terminated.

    Subscripting is permitted where indexing is permitted.

    28

  • Abacus Software COBOL 64

    SECTION 3 EDITING FORMAT

    The rules for spacing given in the following description of the reference format take precedence over all other rules for spacing.

    FIELD DEFINITIONS

    The same format is used for all four divisions of a COBOL 64 program. These divisions must appear in proper order: IDENTIFICATION, ENVIRONMENT, DATA, and PROCEDURE. The following paragraphs describe the various fields of this coding form.

    SEQUENCE AREA (Record Positions 1-6)

    A sequence number, consisting of six digits in the sequence area, must be used for each source program line.

    INDICATOR AREA (Record Position 7)

    Column 7 has the following functions:

    1. If column 7 contains an asterisk(*), the remainder of the record is considered to be a comment and, is not compiled.

    2. If column 7 contains a slash {/ ), the printout is advanced to the top of the next page before printing, and the record is considered to be a comment record. This feature is not available at this time.

    3. The presence of a hyphen (-) indicates that the last nonnumeric literal on the previous record is not complete and is continued on this record beginning in Area B (positions 12 through 80).

    29

  • Abacus Software COBOL 64

    N onnumeric literals can be split into two or more records. On the initial record starting from the quotation mark, all information through position 80 is taken as part of the literal, and on the next record a quotation mark must be used to indicate the start of the second part of the literal. ..,,,,,

    AREA A (Positions 8-11)

    DIVISION, SECTION, and PARAGRAPH headers must begin in AREA A. A division header consists of the division name (IDENTIFICATION, ENVIRONMENT, DATA, or PROCEDURE), followed by a space, then the word DIVISION followed by a period.

    In the ENVIRONMENT and DATA DIVISIONS, a section header consists of the section-name, followed by a space, and then the word SECTION followed by a period.

    A paragraph header consists of the paragraph-name followed by a period. The first sentence of the paragraph may appear on the same line as the paragraph header. ..,,,,

    Within the IDENTIFICATION and ENVIRONMENT divisions, the section and paragraph headers are fixed and only the headers shown in this manual are permitted. Within the PROCEDURE DIVISION, the paragraph headers are defined by the user.

    Within the DATA DIVISION, the level indicator FD and the level numbers 01 and 77 must each begin in Area A, followed by the associated name and appropriate descriptive information.

    30

  • Abacus Software COBOL 64

    AREA B (Positions 12-80)

    All entries which are not DIV Is I ON' SE c TI ON' or PARAGRAPH headers; level numbers 01 and 77, or level indicator FD must start in Area B.

    When level-numbers are to be indented, each new level-number may begin any number of spaces to the right of AreaA.

    BLANK LINES

    A blank line is one that contains no entries in the Indicator Area, Area A, and Area B. A blank line may appear anywhere in the source program except immediately preceding a continuation line.

    PUNCTUATION

    The following rules of punctuation apply in COBOL 64 source programs:

    1. A sentence must be terminated by a period followed by a space. A period must not appear within a sentence unless it is within a nonnumeric literal or is a decimal point in a numeric literal or PICTURE string.

    2. Two or more names in a series must be separated by a space.

    3. A space must never be embedded in a name; hyphens are to be used instead. A hyphen must not start or terminate a name. For example:

    PAY-DAY -PAYDAY

    31

    (correct) (wrong)

  • Abacus Software COBOL 64

    SECTION 4 IDENTIFICATION DIVISION

    GENERAL

    The first division of the COBOL 64 source program is the IDENTIFICATION DIVISION whose function is to identify the source program and the resultant output. In addition, the date the program was written and other pertinent information can be included in the IDENTIFICATION DIVISION.

    IDENTIFICATION DIVISION STRUCTURE

    The structure of this division follows:

    IDENTIFICATION DIVISION.

    [PRQGEAM-ID. program-name.

    [AUTHOR. [comment-entry] ... ]

    [INSTALLATION. [comment-entry] ... ]

    [DATE-WRITTEN. [comment-entry] ... ]

    [SECURITY. [comment-entry] ... ]

    The following rules must be observed in the formation of theIDENTIFICATION DIVISION:

    1. The IDENTIFICATION DIVISION must begin with the reserved words IDENTIFICATION DIVISION followed by a period and a space.

    2. All paragraph-names must begin in positions 8 through 11 (Area A).

    3. The comment-entry must be on the same line as the paragraph name.

    32

  • Abacus Software COBOL 64

    4. The comment-entry can consist of any combination of words and literals allowed by the COBOL 64 Editor.

    ~ PROGRAM-ID PARAGRAPH

    The PROGRAM-ID paragraph gives the name by which a program is identified.

    PROGRAM-ID. program-name.

    The following rules must be observed to form PROGRAM-ID paragraphs.

    1. The program-name must conform to the rules for formation of a user-defined word.

    2. The PROGRAM- ID paragraph contains the name of the program and must be present in every program.

    3. The program-name identifies the source program and all listings pertaining to a particular program.

    4. The program-name must be followed by a period and a space.

    33

  • Abacus Software COBOL 64

    SECTION 5 ENVIRONMENT DIVISION

    GENERAL

    The ENVIRONMENT DIVISION is the second division of a COBOL 64 source program. Its function is to specify the computer being used for the program compilation, specify the computer to be used for program execution, and associate files with the computer hardware devices. Furthermore, this di vision is also used to specify input-output areas to be utilized for each file declared in a program.

    ENVIRONMENT DIVISION ORGANIZATION

    The ENVIRONMENT DIVISION consists of two sections. The CONFIGURATION SECTION contains the overall specifications of the computer. The INPUT-OUTPUT SECTION deals with files to be used in the object program. .,,,.,

    ENVIRONMENT DIVISION STRUCTURE

    The structure of this division follows:

    ENVIRONMENT DIYISTON,

    CONFIGURATION SECTION,

    SOURCE-COMPUTER. source-computer-entry

    OBJECT-COMpUTEB, object-computer-entry

    [SPECIAI,-NAMES. special-names-entry]

    [INPUT-OUTPUT SECTION,

    FIT.E-CONTBOL, {file-control-entry } .. , J

    34

  • Abacus Software COBOL 64

    The following rules must be observed in the formulation of the ENVIRONMENT DIVISION.

    1. The ENVIRONMENT DIVISION must begin with the reserved words ENVIRONMENT D IVI s ION followed by a period and a space.

    2. All entries must begin in Area A (columns 8 through 11).

    CONFIGURATION SECTION

    The CONFIGURATION SECTION contains information concerning the system to be used for program compilation (SOURCE-COMPUTER), the system to be used for program execution (OBJECT-COMPUTER), and the SPECIAL-NAMES paragraph. The SPECIAL-NAMES paragraph is used to define a special currency sign or decimal point in place of commas.

    SOURCE-COMPUTER PARAGRAPH

    The SOURCE-COMPUTER paragraph identifies the computer upon which the program is to be compiled.

    General Format:

    SOURCE-COMPUTER. computer-name.

    Syntax Rule:

    1. The computer-name must be equal to c 6 4 followed by a period and a space.

    '-". Example:

    SOURCE-COMPUTER. C64.

    35

  • Abacus Software COBOL 64

    OBJECT-COMPUTER PARAGRAPH

    The OBJECT-COMPUTER paragraph identifies the computer on which the program is to be executed. "'111

    General Format:

    OBJECT-COMPUTER. computer-name.

    Syntax Rules:

    1. Computer-name must be equal to c 6 4 followed by a period and a space.

    SPECIAL-NAMES PARAGRAPH

    The s PE c I AL-NAME s paragraph provides a means of defining a special currency sign or the decimal point in ..,,,, place of commas.

    General Format:

    [CURRENCY SIGN .IS. literal]

    [DECIMAL-POINT .IS. COMMA] .

    36

  • Abacus Software COBOL 64

    SPECIAL-NAMES

    "-"' Syntax Rules:

    1. The literal which appears in the CURRENCY SIGN IS literal clause is used in the P I c Tu RE clause to represent the currency symbol. The literal is limited to a single character enclosed in quotation marks and must not be one of the following characters:

    a. Digits 0 through 9.

    b. Alphabetic characters: A B c D L P R s v x z space

    c. Special characters: * + - , . ; ( ) " I =

    If the CURRENCY SIGN IS clause is not present, the default value dollar sign ( $) is used in the PI CT URE clause.

    Forexample: CURRENCY SIGN IS "E"

    2. The clause DECIMAL-POINT IS COMMA means that the functions of the comma and period are exchanged in the character-string of the PICTURE clause and in the FILTER-NUMERIC verb. This does not apply to numeric literals.

    37

  • Abacus Software COBOL 64

    INPUT-OUTPUT SECTION

    The INPUT-OUTPUT section contains information concerning files to be used by the program, and the manner """1JIJ of recording used.

    FILE CONCEPTS

    In the following paragraphs, concepts of File Types, Organization, Access Mode, I-0 Status, INVALID KEY and AT END are discussed pertaining to Sequential and Relative files.

    SEQUENTIAL 1-0

    Sequential I -o provides a capability to access records of a file in established sequence. The sequence is established as a result of writing the records to the file.

    Sequential I-0 provides full facilities for the FI LE-CONTROL and FD entries as specified in the formats of this manual. Within the PR o c ED u RE DIVISION, Sequential I-0 provides full capabilities for the CLOSE, OPEN, READ and WRITE statements.

    RELATIVE 1-0

    Relative I-0 provides the capability to access records of a disk file in either a random or sequential manner. Each record in a relative file is uniquely identified by an integer value greater than zero which specifies the record's logical ordinal position in the file.

    Relative I-0 has full facilities for the FILE-CONTROL and FD entries as specified in the formats of this manual. """1111 Within the PROCEDURE DIVISION, the I-0 provides full capabilities for the CLOSE, OPEN, READ, and WRITE statements.

    38

  • Abacus Software COBOL 64

    ORGANIZATION

    Sequential Files are organized such that each record in the file except the first has a unique predecessor record, and each record except the last has a unique successor record. These predecessor-successor relationships are established by the order of WRITE statements when the file is created. Once established, the predecessor-successor relationships do not change except in the case where records are added to the end of the file.

    Relative File organization is permitted only on disk storage devices. A Relative File consists of records which are identified by relative record numbers. The file may be thought of as composed of a serial string of areas, each capable of holding a logical record. Each of these areas is denominated by a relative record number. Records are stored and retrieved based on this number. For example, the tenth record is the one addressed by relative record number 10 and is in the tenth record area, whether or not records have been written in the first through the ninth record areas. The maximum size of a relative logical record is 254 characters.

    ACCESS MODE

    The ACCESS MODE clause specifies the manner in which records are accessed in a file. Sequential and Relative File access methods are discussed in the following paragraphs.

    SEQUENTIAL FILES

    In the sequential access mode, the sequence in which records are accessed is by the ascending order of ordinal location within the file.

    39

  • Abacus Software COBOL 64

    RELATIVE FILE

    In the sequential access mode, the sequence in which records are accessed is the ascending order of the relative ""'111 record numbers of all records which currently exist within the file.

    In the random access mode, the sequence in which records are accessed is controlled by the programmer. The desired record is accessed by placing its relative record number in a relative key data item.

    I-0 STATUS

    If the FILE STATUS clause is specified in a file control entry, a value is placed into the specified two-character data item during the execution of an OPEN, CLOSE, READ, or WRITE statement to indicate to the COBOL 64 program the status of that input-output operation.

    The usage of this feature is strongly recommended. The testing of 1-0 status after each 1-0 statement will avoid a good deal of confusion when debugging.

    STATUS KEY 1

    The leftmost character position of the FILE STATUS data item is known as status key 1 and is set to a value which indicates one of the following conditions upon completion of the input-output operation.

    VALUE

    0 1 2 3 9

    CO ND ID ON

    Successful Completion At End Invalid Key Permanent Error COBOL 64-Defined Condition:

    The above conditions are defined in following text.

    40

  • Abacus Software COBOL 64

    SUCCESSFUL COMPLETION

    The input-output statement was successfully executed.

    AT END

    The sequential READ statement is unsuccessfully executed as a result of an attempt to read a record when no next logical record exists in the file.

    INVALID KEY

    The input-output statement was unsuccessfully executed as a result of one of the following:

    1. A READ statement when the contents of the ACTUAL KEY data item are less than 1 or greater than the ordinal number of the last record ever written to the file, or trying to READ a relative file record which was never written to.

    2. A WRITE statement when the contents of the ACTUAL KEY data item are less than 1 or greater than the last record allowed to be written because of the specification of a maximum file size.

    PERMANENT ERROR

    The input-output statement was unsuccessfully executed as the result of a boundary violation for a sequential file or as the result of an input-output error, such as data check parity error.

    41

  • Abacus Software COBOL 64

    STATUS KEY 2

    The rightmost character position of the FILE STATUS data item is known as status key 2 and is used to further "1111 describe the results of the input-output operations. This .. character contains a value as follows:

    1. If no further information is available concerning the input-output operation, then status key 2 contains a value of 0.

    2. When status key 1 contains a value of 2 indicating an INVALID KEY condition, status key 2 is used to designate the case of that condition as follows:

    a. A value of 3 in status key 2 indicates no record found. An attempt is made to access a record, identified by a key, but that record does not exist in the file.

    b. A value of 4 in status key 2 indicates a boundary violation. An attempt was made to write beyond W the externally defined boundaries of the file.

    3. When status key 1 contains a value of 9 indicating a COBOL 64-defined condition, the value of status key 2 indicates the condition as follows:

    42

  • Abacus Software COBOL 64

    STATUSKEY2

    VALUE CONDIDON

    0 This is a Commodore exception which is displayed on the screen. See your Commodore User's Guide for additional information.

    1 Attempted to OPEN or CLOSE when file was already opened or closed.

    2 Device not present or powered on.

    3 Attempted READ or WRITE when file was not opened or not opened properly. A READ must be opened INPUT or 1-0. A WRITE must be opened OUTPUT or 1-0.

    4 Attempted READ when previous READ resulted in an end of file condition.

    VALID COMBINATIONS OF STATUS KEYS 1 and 2

    The valid permissible combinations of the values of status key 1 and status key 2 are shown in Table 5-1.

    TABLE 5-1. STATUS KEY COMBINATIONS

    STATUS KEYl

    0 1 2 2 3 9 9 9 9 9

    STATUS KEY2

    0 0 3 4 0 0 1 2 3 4

    Successful completion AT END INVALID KEY, no record found INVALID KEY, boundary violation Permanent error Commodore error OPEN CLOSE error Devise not present/ready READ or WRITE with OPEN error READ after end of file

    43

  • Abacus Software COBOL 64

    FILE-CONTROL PARAGRAPH

    The F ILE - c ONT RO L paragraph names each file and allows specification of other file-related information.

    General Format:

    FIJ.E-CONTROI .• {file-control-entry }

    FILE CONTROL ENTRY

    The file control entry names a file and may specify other file-related information.

    INPUT-OUTPUT SECTION

    FILE-CONTROL

    ~ filename

    ~TO

    lc OBGANIZAIION IS SEOUENITAI] ~ = MODE IS SEOI!ENTI8!, ~

    ORGANIZATION rs REI.ATTYE

    PRINTER-J525

    { SEOUENTJAJ[REI.ATiyE KEY rs data-name-~}

    ~MODE rs .BANUQM REI.ATTYE KEY rs data-name-2

    [FILE ~ IS data-name-1 J .

    44

  • Abacus Software COBOL 64

    Syntax Rules:

    1. The SELECT clause must be specified first in the file control entry. The clauses which follow the SELECT clause may appear in any order.

    2. Each file described in the DATA DIVISION must be named only once with a file-name in the FILE-CONTROL paragraph. Each file specified in the file control entry must have a file description entry in the DATA DIVISION.

    3. If the ACCESS MODE clause is not specified, the ACCESS MODE IS SEQUENTIAL clause is implied.

    4. Data-name-1 must be defined in the DAT A DI v Is I ON as a two-character data item of the category alphanumeric and must not be defined in the FILE SECT ION or the COMMUN I CAT I ON SECTION.

    5. If no ORGANIZATION IS clause is specified, the ORGANIZATION IS SEQUENTIAL clause is implied.

    6. The RELATIVE KEY phrase may be specified only for disk storage files.

    7. Data-name-2 must not be defined in a record description entry associated with that file-name.

    8. The data item referenced by data-name-2 must be defined as an unsigned integer.

    45

  • Abacus Software COBOL 64

    General Rules:

    1. The AS s I GN clause specifies the association of the file referenced by file-name to a storage medium. For ..,,, Relative and Indexed Files, the storage medium must be DISK-1541.

    2. The ORGANIZATION clause specifies the logical structure of a file. The file organization is established at the time a file is created and cannot subsequently be changed.

    3. When the access mode of a Relative File is sequential, records in the file are accessed in the order of ascending relative record numbers of existing records in the file.

    4. When the FILE STATUS clause is specified, a value is moved by the COBOL 64 system into the data item specified by data-name-1 after the execution of every statement that references that file either explicitly or ..,,., implicitly. This value indicates the status of execution of the statement. Refer to I-0 Status in this section for additional information.

    5. If the access mode of a Relative File is random, the value of the RELATIVE KEY data item indicates the record to be accessed.

    6. All records stored in a Relative File are uniquely identified by relative record numbers. The relative record number of a given record specifies the record's logical ordinal position in the file. The first logical record has a relative record number of 1, and subsequent logical records have relative record numbers of 2, 3, 4, and so forth.

    7. In a Relative File, the data item specified by data-name-2 is used to communicate a relative record number between the program and the COBOL 64 system.

    46

  • Abacus Software COBOL 64

    SECTION 6 DAT A DIVISION

    GENERAL

    The DATA DIVISION describes the data that the object program is to accept as input, to manipulate, to create, or to produce as output. Data to be processed belongs to these three categories:

    1. That which is contained in files and enters or leaves the internal memory of the computer from a specified area or areas.

    2. That which is developed internally and placed into intermediate or working storage, or placed into specific format for output reporting purposes.

    3. Constants which are defined by the user.

    DATA DIVISION ORGANIZATION

    The DATA DIVISION, which is one of the required divisions in a program, is subdivided into sections. These are FILE and WORKING-STORAGE.

    The FILE SECTION defines the structure of data files. Each file is defined by a file description entry and one or more record descriptions. Record descriptions are written immediately following the file description entry.

    The WORKING-STORAGE SECTION describes records and noncontiguous data items which are not part of external data files but are developed and processed internally. It also describes data items whose values are preassigned in the source program.

    47

  • Abacus Software COBOL 64

    DATA DIVISION STRUCTURE

    The following structure shows the general format of the sections of the DATA DIVISION, and defines the order of presentation in the source program.

    ~ DIVISION.

    [

    I.11.E SECT ION .

    [file-description-entry [record-description-entry]

    WORKING-STORAGE SECTION.

    [ 77-level-description-entrJ record-description-entry J ...

    FILE SECTION

    ... ] ..]

    In a COBOL 64 program, the file description entry (FD) represents the highest level of organization in the FI LE SECTION. The FILE SECTION header is followed by a file description entry consisting of a level indicator (FD), a file-name, and a series of independent clauses. The FD clauses specify the size of the logical records, the presence or absence of label records and the value of label items. The entry is terminated by a period.

    RECORD DESCRIPTION

    A record description consists of a set of data description entries which describe the characteristics of a particular record. Each data description entry consists of a level-number followed by a data-name (if required), followed by a series of independent clauses as required.

    48

  • Abacus Software COBOL 64

    Examples:

    01 DATA-ITEM-ONE 03 LINE-COUNTER

    PICTURE IS X(lO). PIC 999.

    A record description has a hierarchical structure and, therefore, the clauses used with an entry may vary considerably, depending upon whether or not it is followed by subordinate entries. The structure of a record description is defined in Concepts of Levels, Section 2, while the elements allowed in a record description are shown in the data description structure.

    FILE DESCRIPTION STRUCTURE

    The file description entry furnishes information concerning the physical structure and identification pertaining to a given file.

    [[!2, file-name

    [VALUE QI. FILE-ID IS literal-1)

    {record-description-entry } ... )

    49

  • Abacus Software COBOL 64

    LABEL RECORDS

    The LABEL RECORDS clause specifies whether labels are present.

    Syntax Rules:

    This clause is required. The clause is treated as documentation only.

    VALUE OF

    The VALUE OF clause specifies the file identification of a disk file.

    Syntax Rules:

    Literal-1 must be a nonnumeric literal not greater than 19 characters. The first three characters must be @ O : if the "replace" feature is desired. Note that relative files cannot be "replaced". See your Commodore user's guide for more detailed information.

    General Rules:

    1. For an input file, the appropriate label routine checks to see if the disk drive contains a file name equal to the value of literal-1.

    For an output file, at the appropriate time, the value of literal-1 is used to create the disk file name.

    Example: VALUE OF FILE-ID IS "MY-FILE"

    50

  • Abacus Software COBOL 64

    DATA DESCRIPTION STRUCTURE

    A data description entry specifies the characteristics of a particular item of data.

    General Format:

    level-number { data-name-1}

    FILLER

    [ {

    PICTURE} J PIC IS character-string

    [ ~ IS l !fillliL

    OCCURS integer-2 TIMES

    [INDEXED BY index-name-1 [index-name-2)

    [~ IS literal-1 J

    [~ IS ~ literal-2] .

    51

  • Abacus Software COBOL 64

    Syntax Rules:

    1. The level-number may be any number from 01 through 10 or 77.

    2. The clauses may be written in any order with one exception: the data-name-1 or FILLER clause must immediately follo~ the level-number.

    3. The P I c TURE clause must be specified for every elementary item except an index data item, in which case, use of this clause is prohibited. The PICTURE clause and character-string must be on the same line.

    General Rules:

    1. The PICTURE clauses must not be specified except for an elementary data item.

    DATA-NAME OR FILLER

    A data-name specifies the name of the data being described. The word FILLER specifies an elementary item of the logical record that cannot be referred to explicitly.

    General Format:

    {data-name}

    FILLER

    52

  • Abacus Software COBOL 64

    Syntax Rules:

    1. In the FILE and WORKING-STORAGE SECTIONS, a data-name or the key word FILLER must be the first word following the level-number in each data description entry.

    General Rules:

    1. The key word FILLER may be used to name an elementary item in a record. Under no circumstances can a FILLER item be referred to explicitly.

    2. The key word FILLER is not allowed with a level 77 item or with a VALUE clause.

    LEVEL-NUMBER

    The level-number shows the hierarchy of data within a logical record. In addition, it is used to identify entries for working storage items.

    General Format:

    level-number

    Syntax Rules:

    1. A level-number is required as the first element in each data description entry.

    2. Data description entries subordinate to an FD must have level-numbers with the values 01 through 10. Refer to the FD file description in the paragraph entitled File Description Structure.

    3. Data description entries in the WORKING-STORAGE SECTION must have level-numbers with the values 01 through 10.

    53

  • Abacus Software COBOL 64

    General Rules:

    1. The level-number 01 identifies the first entry in each record description. Less inclusive groupings are given higher numbers (not necessarily successive) up to a "1111 limit of 10.

    2. A special level-number has been assigned to entries where there is no real concept of level: the level-number 77 is assigned to identify noncontiguous working storage data items.

    3. Multiple level 01 entries subordinate to any given level indicator (FD) represent implicit redefinitions of the same area.

    Examples:

    The following is an example of record layout which corresponds to Figure 6-3 showing a record description -........ and the use of level numbers. "119"'

    STUDENT NO.

    01

    STUDENT RECORD

    NAME LAST FIRST

    STUDENT-REC. 03 STUDENT-NO 03 STUDENT-NAME.

    05 LAST-NAME 05 FIRST-NAME

    03 GRADE 03 BIRTH-DATE.

    05 BIRTH-MONTH 05 BIRTH-DAY 05 BIRTH-YEAR

    GRADE BIRTH DATE mth day yr

    PIC 9 ( 6) .

    PIC x (8) • PIC x (5) . PIC 99.

    PIC 99. PIC 99. PIC 99.

    Figure 6-3 Level Numbers

    54

  • Abacus Software COBOL 64

    OCCURS

    The OCCURS clause eliminates the need for separate entries for repeated data items and supplies information required for the application of subscripts or indices.

    General Format:

    ~ integer-2 TIMES

    [TNQEXEQ BY index-name-1 [ index-name-2) ... ]

    Syntax Rules:

    1. An INDEXED BY phrase is required if the subject of this entry, or an entry subordinate to this entry, is to be referred to by indexing.

    2. The OCCURS clause cannot be specified in a data description entry that has an 01or77 level-number.

    3. Index-name-1, index-name-2,... must be unique words within the program.

    4. Integer-2 cannot be zero and cannot be greater than 9,999.

    General Rules:

    1. The OCCURS clause is used in defining tables and other homogeneous sets of repeated data items. Whenever the OCCURS clause is used, the data-name which is the subject of this entry must be either subscripted or indexed whenever it is referred to in a statement. Further, if the data-name associated with the OCCURS clause is the name of a group item, then all data-names belonging to the group must be subscripted or indexed when used as operands. Refer to Subscripting, Indexing, and Identifier in Section 2.

    55

  • Abacus Software COBOL 64

    2. Except for the OCCURS clause, all data description clauses associated with an item whose description includes an OCCURS clause apply to each occurrence of the item described.

    3. The VALUE clause is not allowed with the OCCURS clause.

    PICTURE

    The PICTURE clause describes the general characteristics and editing requirements of an elementary item.

    General Format:

    PICTURE

    IS character-string PIC

    Syntax Rules:

    1. A PI c TURE clause can be specified only at the elementary item level.

    2. A character-string consists of certain allowable combinations of characters in the COBOL 64 character set used as symbols. The allowable combinations determine the category of the elementary item.

    3. The maximum number of characters allowed in the character-string is 30.

    4. The PICTURE clause must appear in every elementary """'1111 item except those items whose USAGE is declared as . . . INDEX.

    56

  • Abacus Software COBOL 64

    5. PIC is an abbreviation for PICTURE.

    General Rules:

    1. There are five categories of data that can be described with a PI c TURE clause; alphabetic, numeric, alphanumeric, alphanumeric edited, and numeric edited.

    2. To define an item as alphabetic:

    a. The PICTURE character-string can only contain the symbol ' A ' .

    b. The item contents, when represented in standard data format, must be any combination of the 26 letters of the English alphabet and the space from the computer character set

    3. To define an item as numeric:

    a. The PICTURE character-string can only contain the symbols '9 ', 's ',and 'V'. The number of digit positions that can be described by the PI c TURE character-string must range from 1 to 18 inclusive.

    b. If unsigned, the item contents must be a combination of the numerals ' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , and ' 9 ' ; if signed, the item may also contain a ' + ' or ' - ' .

    4. To define an item as alphanumeric:

    a. The PI c TURE character-string is restricted to certain combinations of the symbols 'A ' , ' x ' , ' 9 ' , and the item is treated as if the character-string contained all X's. AP ICTURE character-string which contains all A's or all 9 's does not define an alphanumeric item.

    57

  • Abacus Software COBOL 64

    b. The item contents are allowable characters in the computers.

    5. To define an item as alphanumeric edited:

    a. The PICTURE character-string is restricted to certain combinations of the following symbols: ' A ' , ' x ' , ' 9 ' , ' B ' , ' O ' , and ' I ' .

    1) The character-string must contain at least one ' B ' and at least one ' x ' or at least one ' o ' (zero) and at least one 'x ' or at least one 'I ' (stroke) and at least one 'x'.

    2) The character-string must contain at least one ' O ' (zero) and at least one ' A' or at least one 'I' (stroke) and at least one 'A'.

    b. The contents are allowable characters in the computer character set.

    6. To define an item as numeric edited:

    a. The PICTURE character-string is restricted to certain combinations of the symbols ' B ' , ' I ' , 'V', 'Z', '0', '9', ',', '.', '*', ' + ' , ' - ' , ' CR ' , ' DB ' , and the currency symbol ($ ). The allowable combinations are determined from the order of precedence of symbols and the editing rules.

    1) The number of digit positions that can be represented in the PICTURE character-string must range from 1 to 18 inclusive.

    2) The character-string must contain at least one '0', 'B', '/', 'Z', '*', '+',

    ' ' ' ' - ' 'CR' ' 'DB' ' or currency symbol.

    58

  • Abacus Software COBOL 64

    b. The contents of the character positions of these symbols that are allowed to represent a digit in standard data format must be one of the numerals.

    7. The size of an elementary item, where size means the number of character positions occupied by the elementary item in standard data format, is determined by the number of allowable symbols that represent character positions. An integer which is enclosed in parentheses following the symbols: 'A' , ' ' 'X', '9', 'Z', '*', 'B', '/', '0', ' + ' , ' - ' , or ' $ ' indicates the number of consecutive occurrences of the symbol. The maximum value of this integer is 9 , 9 9 9. The following symbols may appear only once in a given PICTURE: ' s ' , ' v ' , ' . ' , ' CR', and ' DB ' .

    8. The functions of the symbols used to describe an elementary item are explained as follows:

    'A'

    'B'

    'S,

    Each letter ' A ' in the character-string represents a character position which can contain only a letter of the alphabet or a space.

    Each letter 'B' in the character-string represents a character position into which the space character will be inserted.

    The letter ' s ' is used in a character-string to indicate the presence of an operational sign in the internal representation of a numeric data item. It must be the first (leftmost) character in the character-string.

    When an operational sign is specified the sign is maintained and expected in the zone of the most significant (leftmost) character. When the data item is the receiving field in an arithmetic statement the four zone bits are set to binary 0101 for negative values and to binary 0100 for positive values. When the data item

    59

  • Abacus Software COBOL 64

    'V'

    is used in an algebraic comparison or operation to supply an algebraic value, only the most significant zone being a binary 0101 will cause the value of the data item to be considered negative. Only the zone values 0100 and 0101 will qualify the data item as ""1111 being NUMERIC if tested by the NUMERIC class condition.

    The letter 'v' is used in a character-string to indicate the location of the assumed decimal point and may only appear once in a character-string. The ' v ' does not represent a character position and is not counted in the size of the elementary item. When the assumed decimal point is to the right of the rightmost symbol in the string, the ' v ' is redundant.

    'X'

    'z'

    '9'

    '0'

    Each letter 'x' in the character-string is used to represent a character position which contains any allowable character in the character set

    Each letter ' z ' in a character-string may only be used to represent the leftmost leading numeric character positions which are replaced by a space character when the contents of that character positions are zero. Each ' z .. is counted in the size of the item.

    Each numeral '9' in the character-string represents a character position which contains a numeral and is counted in the size of the item.

    Each numeral ' O ' in the character-string represents a character position into which the numeral zero is inserted. The ' O ' is counted in the item.

    60

  • Abacus Software COBOL 64

    'I'

    ' '

    ' '

    Each stroke ' I ' in the character-string represents a character position into which the stroke character is inserted. The '/' is counted in the size of the item.

    Each comma ' , ' in the character-string represents a character position into which the character ' , ' is inserted. This character position is counted in the size of the item. The insertion character ' , ' must not be the last character in the PICTURE character-string.

    When the character period ' . ' appears in the character-string it is an editing symbol which represents the decimal point for alignment purposes and in addition, represents a character position into which the character ' . ' is inserted. The character ' . ' is counted in the size of the item. For a given program the functions of the period and comma are exchanged if the clause DECIMAL-POINT IS COMMA is stated in the SPECIAL-NAMES paragraph. In this exchange the rules for the period apply to the comma and the rules for the comma apply to the period when appearing in a PI c TURE clause. The insertion character ' . ' must not be the last character in the PICTURE character-string.

    ' + ' ' - ' ' CR ' 'DB '

    '*'

    These symbols are used as editing sign control symbols and when used, represent the character position into which the editing sign control symbol will be placed. The symbols are mutually exclusive in any one character-string and each character used in the symbol is counted in determining the size of the data item.

    Each asterisk ' * ' in the character-string represents a leading numeric character position into which an asterisk is placed when the contents of that position are zero. Each '*' is counted in the size of the item.

    61

  • Abacus Software COBOL 64

    'cs' The currency symbol ' $ ' in the character-string represents a character position into which a currency symbol is placed. The currency symbol in a character-string is represented by either the dollar sign ""1/1 '$' or by the character specified in the CURRENCY SIGN clause in the SPECIAL-NAMES paragraph. The currency symbol is counted in the size of the item.

    EDITING RULES:

    1. There are two general methods of performing editing in the PI c TURE clause, either by insertion or by suppression and replacement. The four types of insertion editing available are:

    a. Simple insertion b. Special insertion c. Fixed insertion d. Floating insertion

    There are two types of suppression and replacement editing:

    a. Zero suppression and replacement with spaces b. Zero suppression and replacement with asterisks

    2. The type of editing which may be performed upon an item is dependent upon the category to which the item belongs. Table 6-1 specifies which type of editing may be performed upon a given category:

    62

  • Abacus Software COBOL 64

    Table 6-1. Editing for Each Item Category

    Category Type of Editing

    Alphabetic None None None

    Numeric Alphanumeric Alphanumeric Edited Numeric Edited

    Simple insertion ' O ' , ' B ' , and ' I ' All, subject to Editing Rule 3

    3. Floating insertion, and editing by zero suppression and replacement, are mutually exclusive in a PICTURE clause. Only one type of replacement may be used with zero suppression in a PICTURE clause.

    4. Simple Insertion Editing. The ' , ' (comma), 'B ' (space), 'O' (zero), and 'I' (stroke) are used as the insertion characters. The insertion characters are counted in the size of the item and represent the position in the item into which the character is inserted.

    5. Special Insertion Editing. The ' . ' (period) is used as the insertion character. In addition to being an insertion character it also represents the decimal point for alignment purposes. The insertion character, used for the actual decimal point, is counted in the size of the item. The use of the assumed decimal point, represented by the symbol ' v' and the actual decimal point, represented by the insertion character, in the same P I c TURE character-string is disallowed. The result of special insertion editing is the appearance of the insertion character in the item in the same position as shown in the character-string.

    6. Fixed Insertion Editing. The currency symbol and the editing sign control symbols, ' + ' , ' - ' , ' CR ' , 'DB', are the insertion characters. Only one currency symbol and only one of the editing sign control symbols can be used in a given P I c Tu RE character-string. The symbols 'CR' or 'DB' always represent two character positions in determining the

    63

  • Abacus Software COBOL 64

    size of the item and must represent the rightmost character positions counted in the size of the item. The symbol '+' or ' - ' when used, must be either the leftmost or rightmost character position to be counted in the size of the item. The currency symbol must be the leftmost character position to be counted in the size of the item except that it can be preceded by either a '+' or '-' symbol. Fixed insertion editing results in the insertion character occupying the same character position in the edited item as in the P I c Tu RE character-string. Editing sign control symbols produce the results shown in Table 6-2 depending upon the value of the data item.

    Table 6-2. Editing of Sign Control Symbols

    Result Editing Symbol in Data Item Data Item

    p I c TURE Character-String Positive or Zero Negative

    + + space

    CR 2 spaces CR DB 2 spaces DB

    7. Floating Insertion Editing. The currency symbol and editing sign control symbols '+' or ' - ' are the floating insertion characters and are mutually exclusive in a given PICTURE character-string.

    Floating insertion editing is indicated in a P I c TURE character-string by using a string of at least two of the floating insertion characters. This string of floating insertion characters may contain any of the fixed insertion symbols or have fixed insertion characters immediately to the right. These simple insertion characters are part of the floating string.

    The leftmost character of the floating insertion string represents the leftmost limit of the floating symbol in the data item. The rightmost character of the floating

    64

    ...,,

  • Abacus Software COBOL 64

    string represents the rightmost limit of the floating symbols in the data item.

    The second floating character from the left represents the leftmost limit of the numeric data that can be stored in the data item. Nonzero numeric data may replace all the characters at or to the right of this limit

    In a PI c TURE character-string, there are only two ways of representing floating insertion editing. One is to represent any or all of the leading numeric character positions on the left of the decimal point by the insertion character. The other is to represent all of the numeric character positions in the P I c Tu RE character-string by the insertion character.

    If the insertion characters are only to the left of the decimal point in the PI CT URE character-string, the result is that a single floating insertion character is placed into the character position immediately preceding either the decimal point or the first nonzero digit in the data represented by the insertion symbol string, whichever is farther to the left in the PICTURE character-string. The character positions preceding the insertion character are replaced with spaces.

    If all numeric character positions in the PICTURE character-string are represented by the insertion character, the result depends upon the value of the data. If the value is zero, the entire data item will contain spaces. If the value is not zero, the result is the same as when the insertion character is only to the left of the decimal point.

    To avoid truncation, the minimum size of the PICTURE character-string for the receiving data item must be the number of characters in the sending data item, plus the number of nonfloating insertion characters being edited into the receiving data item, plus one for the floating insertion character.

    65

  • Abacus Software COBOL 64

    8. Zero Suppression Editing. The suppression of leading zeroes in numeric character positions is indicated by the use of the alphabetic character ' z ' or the character '*' (asterisk) as suppression symbols in a PICTURE ""1111 character-string. These symbols are mutually exclusive in a given PICTURE character-string. Each suppression symbol is counted in determining the size of the item. If ' z ' is used the replacement character is the space, and if the asterisk is used the replacement character will be ' * ' .

    Zero suppression and replacement is indicated in a PI CT URE character-string by using a string of one or more of the allowable symbols to represent leading numeric character positions which are to be replaced when the associated character position in the data contains a zero. Any of the simple insertion characters embedded in the string of symbols or to the immediate right of this string are part of the string.

    In a PI c TURE character-string, there are only two ..,,,, ways of representing zero suppression. One is to represent any or all of the leading numeric character positions to the left of the decimal point by suppression symbols. The other is to represent all of the numeric character positions in the PICTURE character-string by suppression symbols.

    If the suppression symbols appear only to the left of the decimal point, any leading zero in the data which corresponds to a symbol in the string is replaced by the replacement character. Suppression terminates at the first nonzero digit in the data represented by the suppression symbol string or at the decimal point, whichever is encountered first.

    If all numeric character positions in the PICTURE character-string are represented by suppression _... symbols, and the value of the data is not zero, the ~ result is the same as if the suppression characters were only to the left of the decimal point. If the value is zero and the suppression symbol is ' z ' , the entire

    66

  • Abacus Software COBOL 64

    data item will be spaces. If the value is zero and the suppression symbol ' * ' , the data item will be all asterisks except for the actual decimal point

    9. The symbols ' + ' , ' - ' , ' * ' , ' z ' , and ' $ ' , when used as floating replacement characters, are mutually exclusive within a given character-string.

    10. At least one of the symbols ' A ' , ' x ' , ' z ' , ' 9 ' or ' * ' , or at least two of the symbols ' + ' , ' - ' or 'cs' must be present in a PICTURE string.

    67

  • Abacus Software COBOL 64

    Examples:

    The following Table 6-3 demonstrates the editing function of the PICTURE Clause.

    Table 6-3. Editing Application of the PICTURE Clause

    Source Area Receiving Area

    Editing Picture Data Picture Edited Data

    9(5) 12345 00999.00 00345.00 9(3)V99 12345 999.BB 123.

    S9 (5) (+) 12345 $$$$$$.99CR $12345.00 S99V9 (3) (-) 12345 ------.99 -12.34

    S9 (5) (-) 12345 $$$$$$.99CR $12345.00CR S9(5)V (-) 12345 -ZZZZ9.99 -12345.00

    9(5) 12345 BBB99.99 45.00 S9(5) (+) 12345 ZZZZ9.99- 12345.00 S9(5) (-) 12345 ZZZZ9.99- 12345.00-

    9(3)V99 12345 999.00 123.00 S9(5) (-) 00123 --99999.99 -00123.00 S9(5) (+) 12345 ZZZZ9.99+ 12345.00+

    9(3)V99 00001 $$$,$$$.$$ $.01 9(5) 00000 $ZZ,ZZZ.ZZ 9(5) 12345 $$$,$$9.99 $12,345.00 9(3)V99 00001 $ZZ,ZZZ.99 $ .01 9(3)V99 12345 $$$,$$9.99 $123.45 9(3)V99 00012 $ZZ,ZZ9.99 $ 0.12 9(5) 00123 $**,**9.99 $***123.00 9(5) 00000 $** *** ** , . *******.** 9(5) 0