Eds Cobol Training

download Eds Cobol Training

of 120

Transcript of Eds Cobol Training

  • 8/7/2019 Eds Cobol Training

    1/120

    03-23-05

    30 Sept 2005

    page 1 EDS Internal

    COMMON BUSINESS ORIENDTED LANGUAGECOMMON BUSINESS ORIENDTED LANGUAGE

    E D S India A D U.

  • 8/7/2019 Eds Cobol Training

    2/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 2 EDS Internal

    OBJECTIVESOBJECTIVES

    Understand the standard format of the COBOL program.

    Write COBOL programs using modular design techniques

    Compile, Link edit and Execute the soure code.

  • 8/7/2019 Eds Cobol Training

    3/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 3 EDS Internal

    INTRODUCTIONINTRODUCTIONBE

    COBOL stands for COMMON BUSINESS ORIENTED LANGUAGE.

    COBOL can be referred as

    High-level programming language oriented towards businessapplications

    Procedural language

    Problem oriented and Machine independent

  • 8/7/2019 Eds Cobol Training

    4/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 4 EDS Internal

    HISTORYHISTORY

    Developed in 1959 as standard language to meet businessneed.

    Committee was formed to maintain the COBOL.

    Included representatives from academia, business,computer manufacturers.`

  • 8/7/2019 Eds Cobol Training

    5/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 5 EDS Internal

    STANDARD VERSIONS OF COBOLSTANDARD VERSIONS OF COBOL

    1960s Versions of COBOL compilers

    1968 First COBOL standard set by American nationalStandards Institute (ANSI) known as COBOL-68

    1974 Second COBOL known as COBOL-74 was approvedby ANSI.

    1985 ANSI approved the COBOL-85 in which structured

    programming techniques were incorporated.

  • 8/7/2019 Eds Cobol Training

    6/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 6 EDS Internal

    CHARACTERSTICSCHARACTERSTICS

    COBOL self documenting.

    COBOL is simple

    COBOL is non proprietary (Portable)

    COBOL is maintainable

  • 8/7/2019 Eds Cobol Training

    7/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 7 EDS Internal

    LANGUAGE CONSTRUCTIONLANGUAGE CONSTRUCTION

    COBOL is like English language

    Character is the lowest component

    Word is made up of one or more characters.

    Clause consists of word and characters.

    Statement is syntactically valid combination of words andclauses.

  • 8/7/2019 Eds Cobol Training

    8/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 8 EDS Internal

    LANGUAGE CONSTRUCTIONLANGUAGE CONSTRUCTION

    Statement is syntactically valid combination of words andclauses.

    Sentence is a sequence of one or more statements

    terminated by period.

    Paragraph consists of one or more statements

    Section consists of one or more paragraphs.

  • 8/7/2019 Eds Cobol Training

    9/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 9 EDS Internal

    LANGUAGE CONSTRUCTIONLANGUAGE CONSTRUCTION

    Division consists of one or more paragraphs.

    Program is made up of divisions.

  • 8/7/2019 Eds Cobol Training

    10/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 10 EDS Internal

    CHARACTER SETCHARACTER SET

    Set of 51 characters

    0,. 9

    A,.Z

    b

    +, -, *, /, (,), =, $, ., ,

    DIGITS

    LETTERS

    SPACE/BALNK CHARACTER

    SPECIAL SYMBOLS

  • 8/7/2019 Eds Cobol Training

    11/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 11 EDS Internal

    WORDSWORDS

    User defined words

    Words declared by programmer like paragraphnames, identifiers etc.

    Reserved words

    Words that are having specific meaning to thecompiler

  • 8/7/2019 Eds Cobol Training

    12/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 12 EDS Internal

    CODING FORMATCODING FORMAT

    Columns

    1 6 Sequence numbers identifying pages or lines of aprogram

    7 Continuation, comment or starting of a new page

    872 Program statements

    73-80 Remarks.

    in column 7

    * designates the entire line is as a comment

    / forces page break when printing source listing

    - to indicate a continuation of non numeric literalcolumns 8 72 divided into two areas.

  • 8/7/2019 Eds Cobol Training

    13/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 13 EDS Internal

    CODING FORMATCODING FORMAT

    AREA A - Columns 8 to 11

    AREA B - Columns 12 to 72

    Division, Section and Paragraph names must all begin inArea A and end with a period.

  • 8/7/2019 Eds Cobol Training

    14/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 14 EDS Internal

    DIVISIONSDIVISIONS

    COBOL program contains up to 4 separate divisions in thefollowing order

    IDENTIFICATION DIVISION

    ENVIRONMENT DIVISION DATA DIVISION

    PROCEDURE DIVISION

  • 8/7/2019 Eds Cobol Training

    15/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 15 EDS Internal

    IDENTIFICATION DIVISIONIDENTIFICATION DIVISION

    First division of a COBOL program

    Identifies the program name to the Operating system

    Provides documentation about program

    Should begin in Area A.

  • 8/7/2019 Eds Cobol Training

    16/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 16 EDS Internal

    IDENTIFICATION DIVISIONIDENTIFICATION DIVISION

    Syntax

    IDENTIFICATION DIVISION.PROGRAM-ID. PROGRAM NAME.

    AUTHOR.COMMENT ENTRY

    .INSTALLATION.COMMENT ENTRY.DATE-WRITTEN.COMMENT ENTRY.DATE-COMPILED.COMMENT ENTRY.SECURITY.COMMENT ENTRY.

  • 8/7/2019 Eds Cobol Training

    17/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 17 EDS Internal

    IDENTIFICATION DIVISIONIDENTIFICATION DIVISION

    Paragraph PROGRAM-ID followed by user defined name ismandatory. Other paragraphs are optional

    Security here does not pertian to the operating systemsecurity, but the information that is passed to the user ofthe program about the Security features of the program.

  • 8/7/2019 Eds Cobol Training

    18/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 18 EDS Internal

    ENVIRONMENT DIVISIONENVIRONMENT DIVISION

    Machine dependent division

    The division is optional but for file handling it is essential

    Should begin in Area A.

    Division is terminated by a period.

    Describes the computers used, devices, peripherals etc.

    Contains two sections namely, CONFIGURATION andINPUT-OUTPUT

  • 8/7/2019 Eds Cobol Training

    19/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 19 EDS Internal

    CONFIGURATION SECTIONCONFIGURATION SECTION

    Describes the computer to be used for compiling andexecuting the program.

    Consists of the following paragraphs

    SOURCE COMPUTER

    OBJECT COMPUTER

    SPECIAL NAMES.

  • 8/7/2019 Eds Cobol Training

    20/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 20 EDS Internal

    SOURCE COMPUTERSOURCE COMPUTER

    Used to specify the name of computer for compiling theCOBOL program.

    The With Debugging Mode option can be mentionedenabling the compiler to include D in the 7th column for alllines as syntax.

    Syntax

    SOURCE COMPUTER. XYZ-2901

  • 8/7/2019 Eds Cobol Training

    21/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 21 EDS Internal

    OBJECT COMPUTEROBJECT COMPUTER

    Used to specify the name of the computer for executingthe program

    Syntax

    OBJECT-COMPUTER. Computer-name

    MEMORY SIZE integer-1 CHARACTERS/WORDS

    PROGRAM COLLATING SEQUENCE IS alphabet-name

    SEGMENT-LIMIT IS integer-2.

  • 8/7/2019 Eds Cobol Training

    22/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 22 EDS Internal

    OBJECT COMPUTEROBJECT COMPUTER

    Memory Size used to indicate the amount of storageavailable to Object computer.

    The Program Collating Sequence clause specifies thecollating sequence that is to be used to compare non-numeric data items. The alphabet-name is to be defined inSpecial names paragraph.

    The Segment-Limit clause is used to indicate that the

    section having segment number less than the specifiedshould be held in Permanent area of storage.

  • 8/7/2019 Eds Cobol Training

    23/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 23 EDS Internal

    SPECIAL NAMESSPECIAL NAMES

    Is used to relate some IBM specified environment names touser defined names.

    Regardless of number of entries in this paragraph thereshould be only one period in the end.

    Syntax

    SPECIAL-NAMES. CURRENCY SIGN IS literal-1

    DECIMAL-POINT IS COMMA

    CHANNEL integer IS mnemonic-names

    ALPHABET alphabet-name ISSTANDARD/NATIVE/implementer name

    Implementer-name IS mnemonic-name.

  • 8/7/2019 Eds Cobol Training

    24/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 24 EDS Internal

    SPECIAL NAMESSPECIAL NAMES

    CURRENCY SIGN literal-1

    used to change the currency sign other than $ with onecharacter symbol (literal-1).

    DECIMAL-POINT IS COMMA Used to interchange the roles of . and , as editcharacters.

    CHANNEL integer IS mnemonic-name

    Used to control the line spacing of line printers.

    The mnemonic-name can only be used in a WRITEstatement.

  • 8/7/2019 Eds Cobol Training

    25/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 25 EDS Internal

    SPECIAL NAMESSPECIAL NAMES

    ALPHABET alphabet-name ISSTANDARD/NATIVE/implementer name

    Implementer-name is mnemonic-name

    Used to indicate the collating sequence

    Standard stands for the ASCII collating sequence

    NATIVE stands for the computers own collatingsequence

  • 8/7/2019 Eds Cobol Training

    26/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 26 EDS Internal

    INPUTINPUT--OUTPUT SECTIONOUTPUT SECTION

    Contains information regarding files to be used in theprogram

    Consists FILE-CONTROL and I-O-CONTROL (INPUT-

    OUTPUT-CONTROL) paragraphs.

  • 8/7/2019 Eds Cobol Training

    27/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 27 EDS Internal

    FILEFILE--CONTROLCONTROL

    Associates each file used in program with an external DDname. The DD name is associated to a physical file in JCL.

    The simplified format of file association is done using

    SELECT clause.

    Coding rules

    SELECT clause must appear first

    Other clauses can appear in any order

    Each clause must start in Area B.

  • 8/7/2019 Eds Cobol Training

    28/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 28 EDS Internal

    II--OO--CONTROLCONTROL

    Optional paragraph.

    Must begin in Area A.

    Specifies when check points are to be taken

    Specifies the storage areas to be shared by different files

  • 8/7/2019 Eds Cobol Training

    29/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 29 EDS Internal

    DATA DIVISIONDATA DIVISION

    Used to define data needed to be accessed by program

    Describes input and output format of data files

    Defines any constants and work areas

    Consists of three sections namely

    FILE SECTION

    WORKING STORAGE SECTION

    LINKAGE SECTION

  • 8/7/2019 Eds Cobol Training

    30/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 30 EDS Internal

    FILE SECTIONFILE SECTION

    Includes the description of all the files.

    SYNTAX of file description

    FD file-name

    RECORD IS OMITTED

    LABEL

    RECORDS ARE STANDARD

    RECORD CONTAINS integer-1 CHARACTERS

    BLOCK CONTAINS integer-2 RECORDS

  • 8/7/2019 Eds Cobol Training

    31/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 31 EDS Internal

    FILE SECTIONFILE SECTION

    LABEL RECORDS clause used if labels stored in file

    BLOCK CONTAINS clause indicates blocking factor for diskfiles.

    RECORD CONTAINS clause indicates size of each record.

    Defining a Record

    Each FD followed by record description entries for the file.

    Record name is defined at 01 level considered highestlevel of data

    Fields within a record are defined at subordinate levelwith level numbers from 02 to 49.

  • 8/7/2019 Eds Cobol Training

    32/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 32 EDS Internal

    WORKINGWORKING--STORAGE SECTIONSTORAGE SECTION

    Must start in Area A and end with Period.

    All items must be defined at 01 level or at subordinate to01 level

    Rules for user-defined entry names apply

    Elementary items :

    Must include PICTURE (PIC) clause

    May be assigned initial value with VALUE clause

  • 8/7/2019 Eds Cobol Training

    33/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 33 EDS Internal

    LITERALS AND FIGURATIVE CONSTANTSLITERALS AND FIGURATIVE CONSTANTS

    Literal is a constant representing a number or non-number

    (Alpha numeric) like 33.3 or TEACHER

    Literals are storable in a memory location having a userdefined name called Data name or identifier or Variable orField

    Figurative constant is a COBOL reserved word representingfrequently used constants like ZEROS or SPACES

    Figurative constants are used in program for betterreadability.

    Ex: MOVE SPACES TO WS-RECORD.

    Literals are classified into Numeric and Non-numeric literals

  • 8/7/2019 Eds Cobol Training

    34/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 34 EDS Internal

    NUMERIC LITERALNUMERIC LITERAL

    Must contain at least one digit.

    + or sign, if used must be the left most character

    Not more than one decimal point

    Decimal may not be the right most character

    Maximum of 18 digits

    TOTAL-COUNT PIC 9(3) VALUE 100.

  • 8/7/2019 Eds Cobol Training

    35/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 35 EDS Internal

    NONNON--NUMERIC LITERALNUMERIC LITERAL

    May consist of any character in the character set

    Must be enclosed in quotes

    A numeric literal in quotes is non-numeric literal

    Maximum length of 120 characters

    COMPANY-NAME PIC X(3) VALUE EDS.

  • 8/7/2019 Eds Cobol Training

    36/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 36 EDS Internal

    FIGURATIVE CONSTANTSFIGURATIVE CONSTANTS

    List of Figurative constants

    ZERO/ZEROS/ZEROES

    Quote/Quotes

    Space/Spaces

    HIGH VALUE/HIGH VALUES

    LOW VALUE/LOW VALUES

    ALL

    One or more zeros

    One or more

    One or more spaces

    Value in collating sequence

    Value in collating sequence

    One or more string vlaues

  • 8/7/2019 Eds Cobol Training

    37/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 37 EDS Internal

    DATA DESCRIPTIONDATA DESCRIPTION

    The general format of data description is Level Number

    Data name

    Filler clause

  • 8/7/2019 Eds Cobol Training

    38/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 38 EDS Internal

    LEVEL NUMBERSLEVEL NUMBERS

    Specifies the hierarchical structure of data item

    Is a two digit number starting from 01.

    Single digit numbers must be written in a two-digit formwith a 0 or space preceding them.

    Are values taken from set of integers between 1 and 40, orone from 66, 77 and 88 which are called Special levelnumbers

  • 8/7/2019 Eds Cobol Training

    39/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 39 EDS Internal

    LEVEL NUMBERSLEVEL NUMBERS

    01 level Specifies a group of data items called record or anelementary data item

    Must begin in Area A

    02 49 levels

    Specifies group items or elementary item within a record.

    Group level data items will not have Picture Clause

  • 8/7/2019 Eds Cobol Training

    40/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 40 EDS Internal

    SPECIAL LEVEL NUMBERSSPECIAL LEVEL NUMBERS

    66 identifies items that contain RENAME clause

    77 identifies independent elementary data item

    77 has to appear only as elementary data item

    88 identifies any condition name that is associated with aparticular value of conditional variable

  • 8/7/2019 Eds Cobol Training

    41/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 41 EDS Internal

    DATA NAMESDATA NAMES

    Identifier name or Data name should not exceed 30characters

    There should be at least one alphabet anywhere in thename.

    Only special character allowed is (Hyphen) but shouldnot be at the beginning or at the End.

    Should be unique within a record

    If Data name is duplicated across records then it should bequalified as identifier-name of Record name

  • 8/7/2019 Eds Cobol Training

    42/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 42 EDS Internal

    DATA NAMESDATA NAMES

    Examples CURRENT-DATE

    EMPLOYEE

    11RAIL

    99-DETAIL-LINE

    MOVE BALANCE OF BILLING-RECORD TO TOTAL-AMOUNT

  • 8/7/2019 Eds Cobol Training

    43/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 43 EDS Internal

    FILLERFILLER

    Used whenever there is no specific reference to fields in arecord.

    Used wherever there is fixed information like SPACES orHeadings are stored.

    Example

    01 DETAIL-RECORD

    05 FILLER PIC X(05) VALUE SPACES.

    05 NAME PIC X(20).05 PIC X(02) VALUE SPACES.

    05 FILLER PIC X(05) VALUE BASIC.

    05 AMT PIC 9(9)V99.

  • 8/7/2019 Eds Cobol Training

    44/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 44 EDS Internal

    PICTURE CLAUSEPICTURE CLAUSE

    Describes the class (numeric, alphabetic, alphanumeric),sign(signed/unsigned), decimal point location and size of adata item.

    Specified for every elementary data item

    Type Character String Remark

    Numeric 9 Used for arithmeticoperations

    V Assumed decimal point

    S Signed data item

    P Position of assumeddecimal point when thepoint lies outside dataitem

  • 8/7/2019 Eds Cobol Training

    45/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 45 EDS Internal

    PICTURE CLAUSEPICTURE CLAUSE

    Type Character String RemarkAlphabetic A Data item contains only a

    letter or space

    B Blank insertion character

    Alpha numeric X Data item contains only

    allowable character fromthe COBOL character set

    Examples

    01 COMPANY PIC X(10). - Defines 10characters of Alphanumeric.

    01 BASIC-AMOUNT PIC 9(9)V99. Defines9 digits before decimaland two digits afterdecimal. The decimalwill not be displayed.

  • 8/7/2019 Eds Cobol Training

    46/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 46 EDS Internal

    EDITED PICTURE CLAUSEEDITED PICTURE CLAUSE

    Edited Picture Clause

    Used to display Numeric and other data in the userreadable format

    Edited types

    Numeric data

    Alphabetic

    Alphanumeric

  • 8/7/2019 Eds Cobol Training

    47/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 47 EDS Internal

    EDITED PICTURE CLAUSEEDITED PICTURE CLAUSE

    PIC OF THE FIELD NUMERIC VALUE EDITED VALUE

    ZZZV99

    * * 999

    $ * *999

    -ZZZV99

    +999

    +999

    9999+

    ZZ,Z99

    ZZZZ.ZZ

    $$$$9.99

    99B99B99

    09990

    999/999/99

    38^4

    00052

    985

    -46^52

    -382

    382

    -382

    2456

    5

    342

    46

    456

    3254

    b3840

    * * 052

    $**985

    -b4652

    -382

    +382

    0382-

    b2,456

    bbbb.05

    b$342.00

    00b00b46

    04560

    000/032/54

    ZZZ.99 BLANK WHEN ZERO

    999.99 BLANK WHEN ZERO

    2 5

    0

    bb2.50

    bbbbbb

  • 8/7/2019 Eds Cobol Training

    48/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 48 EDS Internal

    VALUE CLAUSEVALUE CLAUSE

    Assigns initial value to a data item.

    Should not exceed the picture clause

    Should be consistent with the picture clause

    Not used for for items whose size is variable

    Example 01 WS-RECORD

    05 WS-COMPANY PIC X(03) VLAUE EDS.

    05 FILLER PIC X(15) VALUE ALL -.

  • 8/7/2019 Eds Cobol Training

    49/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 49 EDS Internal

    USAGE CLAUSEUSAGE CLAUSE

    Specifies how data item is represented internally

    Types

    DISPLAY number of bytes required is equal to the size ofdata item. This is default type.

    COMPUTATIONAL Maintained in Binary and only forintegers. Stored either in half or full word.

    Syntax

    USAGE IS DISPLAY

    COMPUTATIONAL OR COMP , COMP -1, COMP-2, COMP-3

  • 8/7/2019 Eds Cobol Training

    50/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 50 EDS Internal

    SIGN CLAUSESIGN CLAUSE

    Indicates the data item is Signed.

    Only for numeric fields

    Picture clause should contain S

    Usage should be display

    To represent the position either LEDING or TRAILING can beused.

  • 8/7/2019 Eds Cobol Training

    51/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 51 EDS Internal

    OCCURS CLAUSEOCCURS CLAUSE

    Used to represent and store table of values When used allocates physically contiguous memory

    locations to store table values

    Values are accessed either by using index or subscript

    Example

    01 WS-TABLE.

    05 WS-NAME OCCURS 10 TIMES PIC X(20).

    01 WS-TABLE.

    05 WS-RECORD OCCURS 15 TIMES.

    10 WS-DEPT PIC X(10).

    10 WS-DIV PIC 9(05).

  • 8/7/2019 Eds Cobol Training

    52/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 52 EDS Internal

    REDEFINES CLAUSEREDEFINES CLAUSE

    Allows to reference same memory area for more than onedata-name with different formats and sizes.

    Syntax

    Level-number data-name-1 REDEFINES data-name-2

    Rules

    Level-number of data-name-1 and data-name-2 must beidentical and not 66 or 88

    Redefines clause must follow immediately after data-name-2

    data-name-1 cannot have value clause

    data-name-1 size should not exceed data-name-2 size

  • 8/7/2019 Eds Cobol Training

    53/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 53 EDS Internal

    REDEFINES CLAUSEREDEFINES CLAUSE

    Rules Multiple Redefinitions are allowed provided no newstorage areas defined in between

    At 01 level, OCCURS and REDEFINES cannot becombined

  • 8/7/2019 Eds Cobol Training

    54/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 54 EDS Internal

    RENAMES CLAUSERENAMES CLAUSE

    Regrouping of elementary data items in a Record.

    Example

    01 WS-RESPONSE.

    05 W-CHAR-123 PIC XXX.05 W-CHAR-4 PIC X.

    05 W-CHAR-56 PIC XX.

    66 ADD-RESPONSE RENAMES W-CHAR-123.

    66 VIEW-RESPONSE RENAMES W-CHAR-123 THRUW-CHAR-4.

    66 DELETE-RESPONSE RENAMES W-CHAR-123 THRUW-CHAR-56.

  • 8/7/2019 Eds Cobol Training

    55/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 55 EDS Internal

    JUSTIFIED CLAUSEJUSTIFIED CLAUSE

    Overrides standard positioning rules for a receiving stemof the alphabetic or alphanumeric categories

    Default is Left Justified

    Does not alter initial settings as determined by the valueclause

    May not be specified at 66 and 88 level.

    Example

    01 WS-CHAR PIC X(05) JUSTIFIED RIGHT.

  • 8/7/2019 Eds Cobol Training

    56/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 56 EDS Internal

    PROCEDURE DIVISIONPROCEDURE DIVISION

    Contains statements which specify the operations to beperformed

    Last division in a COBOL program

    Contains following structure

  • 8/7/2019 Eds Cobol Training

    57/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 57 EDS Internal

    PROCEDURE DIVISIONPROCEDURE DIVISION

    DIVISION Is a block of code, usually containing one or moresections

    Starts with a Division name and ends where a newDivision starts or program text ends

    SECTION

    Is a block code usually containing one or moreparagraphs.

    Starts with a Section name and ends where next sectionstarts or program text ends

  • 8/7/2019 Eds Cobol Training

    58/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 58 EDS Internal

    PROCEDURE DIVISIONPROCEDURE DIVISION

    PARAGRAPH A block of code made up of one or more sentences

    Starts with a paragraph name and ends where nextparagraph or next section starts or program text ends

    Sentences and Statements

    Sentence consists of one or more statements and isterminated by a period

    Example

    MOVE 0.12 TO TAX-RATECOMPUTE PRICEA = PROD-COST * TAX-RATE

  • 8/7/2019 Eds Cobol Training

    59/120

    Presentation Title Here,

    Place on Slide Master, Trebuchet Font, 9

    Pt., Normal 30 Sept 2005 page 59 EDS Internal

    PROCEDURE DIVISIONPROCEDURE DIVISION

    Statement consists of a COBOL verb and an operand oroperands

    Example

    SUBTRACT TAX FROM GROSS-PAY GIVING NETPAY.

  • 8/7/2019 Eds Cobol Training

    60/120

    P

    resentation Title Here,P

    lace on Slide Master, Trebuchet Font, 9P

    t., Normal 30 Sept 2005 page 60 EDS Internal

    PROCEDURE DIVISIONPROCEDURE DIVISION

    Guidelines

    Paragraph names section names should start in Area A

    Statements and Sentences should start in Area B

    Section names and Paragraph names are user defined

    Section names must be unique and must be different fromparagraph names

    Paragraph names must be unique in a section

    If paragraph name is duplicated across sections then it shouldbe qualified as paragraph-name of/in section name

  • 8/7/2019 Eds Cobol Training

    61/120

    P

    resentation Title Here,P

    lace on Slide Master, Trebuchet Font, 9P

    t., Normal 30 Sept 2005page 61 EDS Internal

    PROCEDURE DIVISIONPROCEDURE DIVISION

    Statements in Procedure division

    Can be broadly classified as

    Imperative statements which directs the program to take aspecific action during execution

    Examples: MOVE , ADD, GOTO , EXIT

    Conditional statements - Specified that the truth of acondition is to be determined and that the subsequent action ofthe object program is dependent on this truth value

    Examples: IF, EVALUATE, ADDON SIZE ERROR

    Compiler Directive statement is beginning with a compilerverb, that causes compiler to take specific action duringcompilation

    Examples: USE, COPY

    PROCEDURE DIVISIONPROCEDURE DIVISION

  • 8/7/2019 Eds Cobol Training

    62/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 62 EDS Internal

    PROCEDURE DIVISIONPROCEDURE DIVISION

    Explicit Scope Terminator Terminates the scope of theconditional statements

    Examples : END-IF, END-READ, END-EVALUATE,

    END-CALL, END-SORT

    Implicit Scope Terminator is a period that terminates thescope of all previous statements not yet terminated

    DATA MOVEMENTDATA MOVEMENT

  • 8/7/2019 Eds Cobol Training

    63/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 63 EDS Internal

    DATA MOVEMENTDATA MOVEMENT

    MOVE

    To move data into a place in a memory

    Format

    MOVE {IDENTIFIER-1/LITERAL-1} TO IDENTIFIER-2,[,IDENTIFIER-3],

    RULES

    Only one sending field, one or more receiving fields

    Value of the sending field remains unaltered after the

    statement execution

    DATA MOVEMENTDATA MOVEMENT

  • 8/7/2019 Eds Cobol Training

    64/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 64 EDS Internal

    DATA MOVEMENTDATA MOVEMENT

    Numeric Data Transfer Rules When sending field is numeric or numeric-edited, thedata movement is called Numeric data transfer

    Dominant factor is the decimal points alignment in two

    the fields

    If the receiving field is not large enough then truncationoccurs either ends or both the ends

    If the receiving field is large then the unused positionswill be filled with spaces.

    DATA MOVEMENTDATA MOVEMENT

  • 8/7/2019 Eds Cobol Training

    65/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 65 EDS Internal

    DATA MOVEMENTDATA MOVEMENT

    Alphanumeric Data Transfer Rules

    When both the sending and receiving fields arealphabetic, alphanumeric or alphanumeric edited the datamovement is called Alphanumeric

    Receiving field is filled from left to right

    When receiving field is smaller then truncation occursfrom the right, compiler will give warning

    DATA MOVEMENTDATA MOVEMENT

  • 8/7/2019 Eds Cobol Training

    66/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 66 EDS Internal

    DATA MOVEMENTDATA MOVEMENT

    Group Moves

    When at least one of the fields is a group item, it iscalled Group Move

    Example

    01 RECORD-1.

    05 A1 PIC 9(3).

    05 A2 PIC A(2).

    05 A3 PIC XXXX.

    01 RECORD-2.

    05 A1 PIC 9(3).05 A2 PIC A(2).05 A3 PIC XXXX.

    MOVE RECORD-1 TO RECORD-2.

    DATA MOVEMENTDATA MOVEMENT

  • 8/7/2019 Eds Cobol Training

    67/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 67 EDS Internal

    DATA MOVEMENTDATA MOVEMENT

    Move Corresponding

    When the names of the corresponding data item of twogroups are same, this statement can be used forsubstitute for a set of move statements

    Example

    01 PAY-REC.

    05 EMP-NO PIC 9(05).

    05 EMP-NAME PIC X(20).

    01 PRINT-REC.

    05 FILLER PIC X(05).

    05 EMP-NO PIC 9(05).05 FILLER PIC X(05).

    05 EMP-NAME PIC X(20).

    MOVE CORRESPONDING PAY-REC TO PRINT-REC.

    ARITHMETIC VERBSARITHMETIC VERBS

  • 8/7/2019 Eds Cobol Training

    68/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 68 EDS Internal

    ARITHMETIC VERBSARITHMETIC VERBS

    ADD

    To sum two or more numbers and store the result

    ADD [CORRESPONDING] [Identifier-1/Literal-1] [Identfier-2/Literal-2] [TO /GIVING] Identifier-3, Identifier-4..

    ExampleADD A TO B.

    ADD A , B GIVING C.

    ADD CORR OLD-REC TO NEW-REC.

    ARITHMETIC VERBSARITHMETIC VERBS

  • 8/7/2019 Eds Cobol Training

    69/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 69 EDS Internal

    ARITHMETIC VERBSARITHMETIC VERBS

    SUBTRACT

    Used to subtract one or the sum of two or more fromone or more numbers

    SUBTRACT [CORR] [Identifier-1/Literal-1] [Identifier-2/Literal-2] [FROM/GIVING] Identifier-3 Identifier-4.

    Example

    SUBTRACT A FROM B.

    SUBTRACT A B FROM C.

    ARITHMETIC VERBSARITHMETIC VERBS

  • 8/7/2019 Eds Cobol Training

    70/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 70 EDS Internal

    ARITHMETIC VERBSARITHMETIC VERBS

    MULTIPLY

    Used to multiply one or more multiplicands by multiplier

    MULTIPLY {IDENTIFIER-1 BY IDENTIFIER-2[ ,IDENTIFIER-3]...LITERAL - 1}[GIVING IDENTIFIER-4 [ , IDENTIFIER-5]...]

    Example

    MULTIPLY A BY B.

    MUYLTIPLY A BY B GIVING C.

    MULTIPLY 2 BY A.

    ARITHMETIC VERBSARITHMETIC VERBS

  • 8/7/2019 Eds Cobol Training

    71/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 71 EDS Internal

    ARITHMETIC VERBSARITHMETIC VERBS

    DIVIDE

    Used to divide one number by another

    DIVIDE {Identifier-1 / Literal-1}INTO[BY] identifier-2 { ,identifier-3}....[GIVING identifier-4 [ ,identifier-5]...][REMAINDER identifier-6.

    ExampleDIVIDE 5 INTO A.

    DIVIDE A INTO B GIVING C.

    DIVIDE A BY B GIVING C REMINDERD.

    ARITHMETIC VERBSARITHMETIC VERBS

  • 8/7/2019 Eds Cobol Training

    72/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 72 EDS Internal

    ARITHMETIC VERBSARITHMETIC VERBS

    COMPUTE

    Used as a substitute for any other arithmetic verbs likeADD, SUBTRACT, MULTIPLY and DIVIDE.

    COMPUTE IDENTIFIER-1 [ROUNDED][ , IDENTIFIER-2 [ ROUNDED ] ]= ARITHMETIC-EXPRESSION[ : ON SIZE ERROR]IMPERATIVE STATEMENT.

    ARITHMETIC OPERATORSARITHMETIC OPERATORS

  • 8/7/2019 Eds Cobol Training

    73/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 73 EDS Internal

    ARITHMETIC OPERATORSARITHMETIC OPERATORS

    Permitted operators

    ** Exponentiation

    / Division

    * Multiplication

    - Subtraction

    + Addition

    ARITHMETIC OPERATIONARITHMETIC OPERATION

  • 8/7/2019 Eds Cobol Training

    74/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 74 EDS Internal

    ARITHMETIC OPERATIONARITHMETIC OPERATION

    ROUNDED OPERATION

    It will round the number to the picture clause duringarithmetic operations.

    Cant be specified for the identifier that receives theremainder in a Divide operation

    ADD WS-A WS-B GIVING WS-C ROUNDED

    ON SIZE ERROR

    If the result after an arithmetic operation exceeds thelargest value that can be accommodated in the result field

    the error occurs is called ON SIZE ERROR Used to continue the process instead of terminatingbecause of error.

    ADD A TO B ON SIZE ERROR PERFORM ERROR-PARA.

    COBOL DEFINED VERBSCOBOL DEFINED VERBS

  • 8/7/2019 Eds Cobol Training

    75/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 75 EDS Internal

    COBOL DEFINED VERBSCOBOL DEFINED VERBS

    ACCEPT

    To transfer data from an input/output device, or systeminformation contained in the specified data items likeDATE, TIME etc.

    ACCEPT Identifier [FROM mnemonic name

    DATE / DAY/ TIME / DAY-OF-WEEK]

    DISPLAY

    Used to display data on to a terminal

    DISPLAY {identifier-1 identifier-2 literal-1} ,literal-2

    UPON [mnemonic name]

    Example: DISPLAY TOTAL STRENGTH = TOTAL-ST

    COBOL DEFINED VERBSCOBOL DEFINED VERBS

  • 8/7/2019 Eds Cobol Training

    76/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 76 EDS Internal

    COBOL DEFINED VERBSCOBOL DEFINED VERBS

    INITIALIZE

    Used to initialize value of either a group item or anelementary item

    INITIALIZE {identifier-1 } . . .REPLACING { ALPHABETIC

    ALPHANUMERICNUMERICALPHA-NUMERIC-EDITED.NUMERIC-EDITED }

    DATA BY { identifier-2literal-2 }

    CONDITIONAL AND UNCONDITIONAL TRANSFERCONDITIONAL AND UNCONDITIONAL TRANSFER

  • 8/7/2019 Eds Cobol Training

    77/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 77 EDS Internal

    CONDITIONAL AND UNCONDITIONAL TRANSFERCONDITIONAL AND UNCONDITIONAL TRANSFER

    Simple IF statement

    IF condition

    statement-1

    statement-2

    ELSE

    statement-3

    statement-4

    END-IF.

    CONDITIONAL AND UNCONDITIONAL TRANSFERCONDITIONAL AND UNCONDITIONAL TRANSFER

  • 8/7/2019 Eds Cobol Training

    78/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 78 EDS Internal

    CONDITIONAL AND UNCONDITIONAL TRANSFERCONDITIONAL AND UNCONDITIONAL TRANSFER

    Nested IF statement

    IF condition-1

    IF condition-2

    statement-1

    ELSE

    IF condition-3

    statement-3

    END-IF

    END-IF

    END-IF.

    CONDITIONAL AND UNCONDITIONAL TRANSFERCONDITIONAL AND UNCONDITIONAL TRANSFER

  • 8/7/2019 Eds Cobol Training

    79/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 79 EDS Internal

    CONDITIONAL AND UNCONDITIONAL TRANSFERCONDITIONAL AND UNCONDITIONAL TRANSFER

    EVALUATE Statement

    EVALUATE SUBJECT-1 [ALSO SUBJECT-2]...

    {WHEN OBJECT-1 [ALSO OBJECT-2}...}

    [WHEN OTHER {IMPERATIVE-STATEMENT-2}...]

    [END-EVALUATE].

    Can be used instead of nested IF statements

    CONDITIONAL AND UNCONDITIONAL TRANSFERCONDITIONAL AND UNCONDITIONAL TRANSFER

  • 8/7/2019 Eds Cobol Training

    80/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 80 EDS Internal

    CONDITIONAL AND UNCONDITIONAL TRANSFERCONDITIONAL AND UNCONDITIONAL TRANSFER

    GO TO statement

    Is an unconditional transferring of control to thespecified paragraph

    Advised to avoid GO TO as the structured programmingtechnique doesnt support unconditional transferstatements

    Example : GO TO REPORT-PARA.

    ALTER

    Used to modify the targets of GO TO statements written

    elsewhere in the procedure division.ALTER PROCEDURE-NAME-1 TO

    [PROCEED TO ] PROCEDURE-NAME-2[PROCEDURE-NAME-3 TO {PROCEED TO }

    PROCEDURE-NAME-4 ]....

    PERFORM STATEMENTPERFORM STATEMENT

  • 8/7/2019 Eds Cobol Training

    81/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 81 EDS Internal

    PERFORM STATEMENTPERFORM STATEMENT

    A PERFORM statement is used to execute a group of

    consecutive statements elsewhere in the program, under aparagraph

    Types of PERFORM

    PERFORM Para-name-1.

    Para-name-1 specifies the range, which containsstatements to be executed

    PERFORM para-name-1 thru para-name-2.

    This statement executes all the statements

    beginning in para-name-1 till the last statement inpara-name-2 including the paragraphs in betweenboth the paragraphs

    PERFORM STATEMENTPERFORM STATEMENT

  • 8/7/2019 Eds Cobol Training

    82/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 82 EDS Internal

    PERFORM STATEMENTPERFORM STATEMENT

    Types of PERFORM

    PERFORM para-name-1 [THRU para-name-2] {identifier-1/ integer} TIMES

    This is a looping statement which executes thespecified range of statements a fixed number of times.

    PERFORM para-name-1 [THRU para-name-2] UNTILcondition.

    This statement executes the specified range ofstatements repeatedly until the condition becomesTRUE.

    The condition is to be made TRUE within theparagraph performed

    PERFORM STATEMENTPERFORM STATEMENT

  • 8/7/2019 Eds Cobol Training

    83/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 83 EDS Internal

    PERFORM STATEMENTPERFORM STATEMENT

    Types of PERFORM

    PERFORM VARYING {identifier-1 FROM {identifier-2 /integer-1} BY {identifier-3 / integer-2}UNTIL Condition-1 AFTER identifier-1FROM {identifier-2/integer-1}BY {identifier-3/integer-2} UNTIL Condition-2

    [imperative statement]END-PERFORM.

    Example

    PERFORM VARYING I FROM 1 BY 1 UNTIL I > 3AFTER J FROM 1 BY 1 UNTIL J > 4Display SALE ( I , J )

    END-PERFORM.

    PERFORM STATEMENTPERFORM STATEMENT

  • 8/7/2019 Eds Cobol Training

    84/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 84 EDS Internal

    PERFORM STATEMENTPERFORM STATEMENT

    RELATIONAL CONDITION

    Compares two operands either of which can beidentifier literal, arithmetic expression or index-name

    A non-numeric literal can be enclosed in parentheseswithin a relational condition

    Relational operators are: < , , >=

    NOT GREATER THAN / LESS THAN/ EQUAL TO

    SIGN CONDITION

    Determines whether or not the algebraic value of a

    numeric operand is greater than or less than or equal toZero

    Possible conditions are

    POSITIVE, NEGATIVE OR ZERO

    CONDITIONAL EXPRESSIONSCONDITIONAL EXPRESSIONS

  • 8/7/2019 Eds Cobol Training

    85/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 85 EDS Internal

    CONDITIONAL EXPRESSIONSCONDITIONAL EXPRESSIONS

    CLASS CONDITION

    Determines whether the content of data item isalphabetic, numeric or contains only characters in theset of characters specified by the CLASS clause in theSPECIAL NAMES paragraph

    CONDITION-NAME CONDITION Tests a conditional variable to determine its value isequal to any value(s) associated with the conditionname

    Are declared at 88 level

    NEGATED CONDITION

    A condition is negated by using use of operator NOT

    CONDITIONAL EXPRESSIONSCONDITIONAL EXPRESSIONS

  • 8/7/2019 Eds Cobol Training

    86/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 86 EDS Internal

    CONDITIONAL EXPRESSIONSCONDITIONAL EXPRESSIONS

    COMPOUND CONDITION Two or more conditions can be logically connectedto form a compound condition

    Possible values are: AND, OR

    FILE HANDLINGFILE HANDLING

  • 8/7/2019 Eds Cobol Training

    87/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 87 EDS Internal

    N NGN NG

    RECORD : is a collection of relevant fields pertaining to an

    item/case/account/transaction FILE

    Is a collection of relevant records of an application

    Is organized in storage media either in SEQUENTIALor INDEXED or RELATIVE way.

    SEQUENTIAL FILES

    Records can be accessed in the order in which theyappear in the file

    Records can be appended at the end of the file butcannot be inserted

    Records cannot be deleted

    FILE HANDLINGFILE HANDLING

  • 8/7/2019 Eds Cobol Training

    88/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 88 EDS Internal

    INDEXED FILES

    Records can be accessed Randomly or Sequentiallyusing key called Primary-key

    There can be more than one key called Alternatekeys to access records

    Records can be inserted and deleted

    FILE HANDLING STEPSFILE HANDLING STEPS

  • 8/7/2019 Eds Cobol Training

    89/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 89 EDS Internal

    STEP 1:

    All files handled in a program should be assigned tological name

    The DDNAME assigned, Organization of the file, itsprimary key and alternate keys to be specified in File-control paragraph.

    STEP-2:

    Describe the details like record-name, record structurein File section including number of records grouped asBLOCK for input output operation

    STEP-3

    Open the files to do read/write operations in Proceduredivision.

    FILE HANDLING STEPSFILE HANDLING STEPS

  • 8/7/2019 Eds Cobol Training

    90/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 90 EDS Internal

    STEP 4:

    If we have to read records then READ statement shouldbe used

    Syntax: READ file-name

    STEP 5:

    If we have to write record then WRITE statement shouldbe used

    Syntax: WRITE record-name

    STEP 6:

    After all operations are completed the file has to beCLOSED to disconnect file from COBOL program

    Syntax: CLOSE file-name

    SELECT STATEMENTSELECT STATEMENT

  • 8/7/2019 Eds Cobol Training

    91/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 91 EDS Internal

    Syntax:

    SELECT file-name ASSIGN TO DD NameORGANIZATION IS[SEQUENTIAL/INDEXED/RELATIVE]

    ACESS MODE IS[SEQUENTIAL/DYNAMIC/RANDOM]

    [RECORD KEY data-name-1 ]

    [ALTERNATE KEY IS data-name-2. WITHDUPLICATE]

    FILE-STATUS IS data-name-2.

    SELECT STATEMENTSELECT STATEMENT

  • 8/7/2019 Eds Cobol Training

    92/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 92 EDS Internal

    ORGANIZATION CLAUSE

    Following file organizations can be chosen

    o SEQUENTIAL

    This option is used for PS data set or VSAM ESDS.

    The records are places in first come first servedbasis

    o INDEXED

    This option is used to handle a VSAM KSDS

    Key field called Primary key should be defined

    o RELATIVE

    This option is used to handle a VSAM RRDS

    Record number is used to access records

    SELECT STATEMENTSELECT STATEMENT

  • 8/7/2019 Eds Cobol Training

    93/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 93 EDS Internal

    ACCESS MODE CLAUSE

    Based on Organization file can be accessed in differentmodes

    o SEQUENTIAL Access mode To access records insequential order

    o RANDOM Access mode To access particular recordof an indexed / relative file provided key value is setprior to read / write operation

    o DYNAMIC Access mode To access a particular

    record or in sequential order from an indexed / relativefile

    SELECT STATEMENTSELECT STATEMENT

  • 8/7/2019 Eds Cobol Training

    94/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 94 EDS Internal

    RECORD KEY PHRASE

    To be defined for indexed files

    To be unique and is to be part of indexed record

    ALTERNATE KEY PHRASE

    To be defined if records are to be read by using keyother than Primary key

    Need not be unique but need to be part of the record

    FD ENTRYFD ENTRY

  • 8/7/2019 Eds Cobol Training

    95/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 95 EDS Internal

    Syntax

    FD file-name.

    [BLOCK CONTAINS [int-1 TO] int-2RECORDS[CHARACTERS]

    [RECORDS CONTAINS{int-3 to} int-4 CHARACTERS

    [LABEL RECORD/RECORDS IS/ARE STANDARD/OMITTED

    RECORDING MODE [F/V]

    [DATA RECORD/RECORDS IS/ARE data-name-2

    01 record-name

    05 field-1 PIC X(10).

    .

    FD ENTRYFD ENTRY

  • 8/7/2019 Eds Cobol Training

    96/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 96 EDS Internal

    BLOCK CONTAINS / RECORD CONTAINS PHRASE

    Length of the record can be specified in terms ofcharacters

    Number of characters / records for a Block can bespecified

    RECORDING MODE CLAUSE

    Specifies as that all the records in a file are of samelength (FIXED) or different (Variable )

    FD ENTRYFD ENTRY

  • 8/7/2019 Eds Cobol Training

    97/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 97 EDS Internal

    BLOCK CONTAINS / RECORD CONTAINS PHRASE

    Length of the record can be specified in terms ofcharacters

    Number of characters / records for a Block canbe specified

    RECORDING MODE CLAUSE

    Specifies as that all the records in a file are ofsame length (FIXED) or different (Variable )

    INPUT AND OUTPUT STATEMENTSINPUT AND OUTPUT STATEMENTS

  • 8/7/2019 Eds Cobol Training

    98/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 98 EDS Internal

    OPEN Statement

    OPEN INPUT file-name - Connects data set to programto records from the first enabling to read records

    OPEN OUTPUT file-name Connects data set toprogram though file is empty enabling to write records

    OPEN I-O file-name Connects data set to program to

    Read/ Write / Rewrite the records to file OPEN EXTEND file-name Connects the existing data setto program to append new records at the end of theexisting records in the file

    WRITE

    Adds records to the file

    Key to be used for indexed file

    INPUT AND OUTPUT STATEMENTSINPUT AND OUTPUT STATEMENTS

  • 8/7/2019 Eds Cobol Training

    99/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 99 EDS Internal

    START

    Establishes the current location in the cluster for aREAD NEXT statement

    This doesnt retrieve record

    It only sorts the current record pointer described underFile position indicator

    READ

    Used to read record from the file

    Reads next record for sequential file

    Reads the corresponding key specified

    INPUT AND OUTPUT STATEMENTSINPUT AND OUTPUT STATEMENTS

  • 8/7/2019 Eds Cobol Training

    100/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 100 EDS Internal

    REWRITE

    Updates record

    DELETE

    Logically removes the records from the

    Indexed/relative files

    CLOSE

    Disconnects file from the program

    SUBPROGRAMSSUBPROGRAMS

  • 8/7/2019 Eds Cobol Training

    101/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 101 EDS Internal

    Programs compiled and stored in library to be called

    when needed

    The program that calls another program is referred ascalling program, and the program it calls is referred ascalled program

    Called program itself can call another program

    During execution, called program can either transfer

    control back to the calling program or end the run unit

    SUBPROGRAMSSUBPROGRAMS

  • 8/7/2019 Eds Cobol Training

    102/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 102 EDS Internal

    ADVANTAGES

    Avoids duplication effort

    Improves programmer productivity

    Provides greater flexibility

    Changes to the called program can be made withoutchanging the calling program

    Results in greater standardization

    SUBPROGRAMSSUBPROGRAMS

  • 8/7/2019 Eds Cobol Training

    103/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 103 EDS Internal

    SUBPROGRAMSSUBPROGRAMS

  • 8/7/2019 Eds Cobol Training

    104/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 104 EDS Internal

    LINKAGE SECTION

    Describes data made available for anotherprogram

    Storage for data items within the program is notreserved because the area exists elsewhere

    Value clause may not be specified for items otherthan 88 level items

    STATIC CALL

    The compiler treats the CALL literal statementwhere the literal is program name, as a static call

    when NODYNUM compiler option is in effect

    DYNAMIC CALL

    Loads the subprogram at the run time

    SUBPROGRAMSSUBPROGRAMS

  • 8/7/2019 Eds Cobol Training

    105/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 105 EDS Internal

    CALL by Reference or by Content To pass an identifiers value only then use CALLBY REFERENCE

    To pass literals value then use CALL BY CONTENT

    STRING, UNSTRING AND INSPECT STATEMENTSSTRING, UNSTRING AND INSPECT STATEMENTS

  • 8/7/2019 Eds Cobol Training

    106/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 106 EDS Internal

    STRING Statement Strings together the partial or complete contents oftwo or more DATA ITESM or LITERALS into single dataitem

    STRING IDEN

    TIFIE

    R1DELIMI

    TED BYIDENTIFIER2

    LITERAL1 LITERALSSIZEINTO IDENTIFIER3 WITH POINTERIDENTIFIER4ON OVERFLOW IMPERATIVE STATEMENT1NOTON OVERFLOW IMPERATIVESTATEMENT2

    END-STRING

    STRING, UNSTRING AND INSPECT STATEMENTSSTRING, UNSTRING AND INSPECT STATEMENTS

  • 8/7/2019 Eds Cobol Training

    107/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 107 EDS Internal

    UNSTRING Statement Causes contiguous data in a sending field to beseparated and placed into multiple receiving fields

    UNSTRING IDENTIFIER1 DELIMITED BYALL IDENTIFIER2 LITERAL1

    ORALL IDENTIFIER-3 LITERAL2INTO IDENTIFIER4 DELIMITERIN

    IDENTIFIER5COUNT INIDENTIFIER6

    WITH POINTER IDENTIFIER7TALLYING IN IDENTIFIER8

    ON OVERFLOW IMPERATIVESTATEMENT1

    NOTON OVERFLOW IMPERATIVESTATEMENT2

    END-UNSTRING

    STRING, UNSTRING AND INSPECT STATEMENTSSTRING, UNSTRING AND INSPECT STATEMENTS

  • 8/7/2019 Eds Cobol Training

    108/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 108 EDS Internal

    INSPECT Specifies that characters or group of characters in adata item are to be countered or (tallied) or replacesor both

    Counts all the occurrences of a specific character

    Will fill all portions of data item with specifiedcharacters such as spaces or zeros

    Will convert all occurrences of specific characters ina data item to user supplied replacement character

    INSPECT IDENTIFIER1TALLYINGIDENTIFIER2

    FOR[ALL/LEADING][IDENTIFIER3/LITERAL1] [PHRASE]

    [PHRASE] here is AFTER/ BEFORE[INITIAL] IDENTIFIER4/LITERAL2.

    STRING, UNSTRING AND INSPECT STATEMENTSSTRING, UNSTRING AND INSPECT STATEMENTS

  • 8/7/2019 Eds Cobol Training

    109/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 109 EDS Internal

    INSPECT

    INSPECT IDENTIFIER1REPLACINGCHARACTERS

    BY [IDENTIFIER2/LITERAL1]BEFORE/AFTERINITIAL [IDENTIFIER3 /

    LITERA

    L 2]A

    FTER

    / LEA

    DING/FIRST

    [IDENTIFIER/LITERAL.]By IDENTIFIER/LITERAL [PHRASE]PHRASE] here is AFTER/ BEFORE

    [INITIAL] IDENTIFIER4/LITERAL2.

    DECLARATIVESDECLARATIVES

  • 8/7/2019 Eds Cobol Training

    110/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 110 EDS Internal

    Used for tracing the paragraph or procedure executedby the program as per the instruction given by theprogrammer

    WITH DEBUGGING MODE option has to be specifiedin the OBJECT-C0MPUTER paragraph

    Has to be first section in PROCEDURE DIVISION

    PROCEDURE DIVISION.

    DECLARATIVES.DEBUG -DECLARATIVES SECTION.USE FOR DEBUGGING ALL PROCEDURE .DEBUG -DECLARATIVES -PARA.DISPLAY TRACING DEBUG-NAME

    END DECLARATIVES.

    SORT STATEMENTSORT STATEMENT

  • 8/7/2019 Eds Cobol Training

    111/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 111 EDS Internal

    Accepts records from on or more files and arranges the records

    in the ascending/descending order and makes sorted recordsavailable either through an OUTPUT-PROCEDURE or in anoutput file.

    Can be appeared anywhere in PROCEDURE DIVISION

    SORT file-name-1ON[ASCENDING/DESCENDING KEY]data-name-1[WITH DUPLICATES ] [IN ORDERCOLLATING SEQUENCE ISAlphabet- name-1]

    INPUT PROCEDURE IS procedure-name-1THRU procedure-name-2OUTPUT-PROCEDURE IS procedure-name- 3THRU procedure-name-4

    END-SORT.

    SORT STATEMENTSORT STATEMENT

  • 8/7/2019 Eds Cobol Training

    112/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 112 EDS Internal

    File-name -1 is the name given in the SD entry that describes

    the records to be sorted

    data-name-1 specifies a KEY data item on which the SORTstatement will be based

    Each data name must identify a data item in a recordassociated with file-name -1

    Alphabet-name1 must be specified in the alphabet clause ofSPECIAL-NAMES para

    USING and INPUT-PROCEDURE are mutually exclusive

    Input-Procedure is specified to Select or Modify the InputRecord before Sort

    This Procedure can do any modifications in the record and copyUsing RELEASE Statement

    GIVING and OUTPUT-PROCEDURE are mutually exclusive

    SORT STATEMENTSORT STATEMENT

  • 8/7/2019 Eds Cobol Training

    113/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 113 EDS Internal

    Output-Procedure is specified to Select or Modify the output

    Record After Sort

    This Procedure can do any modifications in the record and copyUsing RETURN Statement

    MERGE STATEMENTMERGE STATEMENT

  • 8/7/2019 Eds Cobol Training

    114/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 114 EDS Internal

    Merges two or more input files based on common key.

    The merged records are made available to an output file or toan output procedure

    MERGE file-name-1ON [ASCENDING/DESCENDING KEY]data-name-1 USING file-name-2 file-name-3

    [COLLATING SEQUENCE ISAlphabet-name-1]GIVING file-name-4 /OUTPUT-PROCEDURE IS procedure-name-3THRUprocedure-name-4

    File-name -1 is the name given in the SD entry that describes

    the records to be merged

    GIVING and OUTPUT-PROCEDURE are mutually exclusive

    INTRINSIC FUNTIONSINTRINSIC FUNTIONS

  • 8/7/2019 Eds Cobol Training

    115/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 115 EDS Internal

    NUMBER HANDLING

    LENGTH Returns the length of the Picture clause

    FUNCTION LENGTH(NAME)

    MAX Returns the content of the argument that containsthe maximum value

    FUNCTION MAX(MARKS) MIN Returns the content of the argument that contains

    the minimum value

    FUNCTION MIN(MARKS)

    NUMVAL Returns the numeric value represented by the

    alphanumeric character string specified in the argument

    DATEDATE -- TIMETIME

  • 8/7/2019 Eds Cobol Training

    116/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 116 EDS Internal

    CURRENT DATE

    Returns 21 characters alphanumeric value

    1..4 Year in the Gregorian calendar

    5,6 Month of the year

    7,8 Day of the Month

    9..14 HHMMSS and so on

    DATE-OF-INTERGER

    Converts a date in the Gregorian calendar from integerdate form to standard date form yyyymmdd

    DAY-OF-INTEGER Converts a date in the Gregorian calendar from integerdate form to Julian date form yyyymmdd

    COMPILER OPTIONSCOMPILER OPTIONS

  • 8/7/2019 Eds Cobol Training

    117/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 117 EDS Internal

    NOC

    Specified to do only Syntax check

    NOC (W), NOC (E), NOC (S)

    W is warning, E is for error and S for severe. When anerror level of specified or of a more severe level occurs,compilation stops.

    Default is S

    DYNAM

    Causes subprograms that are invoked through the CALLliteral statement to load dynamically

    NODYNAM

    Causes the text files of subprograms called with a CALLliteral statement to be included with the calling program intoa single module file

    ERROR CODESERROR CODES

  • 8/7/2019 Eds Cobol Training

    118/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 118 EDS Internal

    File Status will have Picture clause of length 2 digits

    The first digit denotes general category under which theerror code falls

    The second digit will denote the particular type of errorunder that category

    The first digit categories are:0 Returned When Successful Open / Read / Write /

    Operation.1 Returned When At End Condition Fails2 Returned When Index Key Fails3 Returned When Permanent Open Error Occurs.4 Returned When Logic Error in

    opening/closing/deleting etc9 Implementer Defined

    ERROR CODESERROR CODES

  • 8/7/2019 Eds Cobol Training

    119/120

    Presentation Title Here, Place on Slide Master, Trebuchet Font, 9 Pt., Normal 30 Sept 2005 page 119 EDS Internal

    00 - Successful completion

    02 - Duplicate key detected

    10 - Sequential READ was attempted on an optional file thatwas not present or after end of file is reached

    21 A sequence error exists for a sequentially accessedindexed file

    39 - An OPEN statement was unsuccessful because of aconflict between the fixed file attributes and theattributes specified for the file in the program

  • 8/7/2019 Eds Cobol Training

    120/120

    03-23-0530 Sept 2005

    EDS

    RMZ Millenia Business Park

    Chennai 600113

    91 44 6612 2358

    harinath munupalle@eds com

    Presentation by Harinath M.