P. 1
Cobol Tutorials-Mainframe230.Blogspot.com Full

Cobol Tutorials-Mainframe230.Blogspot.com Full

|Views: 7|Likes:
Published by Jaideep Dhiman

More info:

Published by: Jaideep Dhiman on Apr 20, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

04/28/2013

pdf

text

original

Sections

  • 1. OBJECTIVES
  • 2. INTRODUCTION TO COBOL
  • 2.1. LANGUAGE CONSTRUCTION
  • 2.2. COBOL CHARACTER SET
  • 2.3. COBOL WORDS
  • 2.4. COBOL CODING FORM
  • 2.5. DIVISIONS OF COBOL
  • 3. IDENTIFICATION DIVISION
  • 3.1. SYNTAX OF IDENTIFICATION DIVISION
  • 4. ENVIRONMENT DIVISION
  • 4.1. CONFIGURATION SECTION
  • 4.1.1. SOURCE-COMPUTER
  • 4.1.2. OBJECT COMPUTER
  • 4.1.3. SPECIAL-NAMES
  • 4.2. INPUT-OUTPUT SECTION
  • 4.2.1. FILE-CONTROL
  • 4.2.2. I-O CONTROL
  • 5. DATA DIVISION
  • 5.1. LITERALS AND FIGURATIVE CONSTANTS
  • 5.1.1. NUMERIC LITERAL
  • 5.1.2. NON-NUMERIC LITERAL
  • 5.1.3. LIST OF FIGURATIVE CONSTANTS
  • 5.2. DATA DESCRIPTION
  • 5.2.1. LEVEL NUMBERS
  • 5.2.2. DATA NAMES
  • 5.2.3. CLAUSE
  • 5.2.4. CONDITION NAMES
  • 6. PROCEDURE DIVISION
  • 6.1. STATEMENTS IN PROCEDURE DIVISION
  • 6.2. DATA MOVEMENT
  • 6.2.1. MOVE
  • 6.3. ARITHMETIC VERBS
  • 6.3.1. ADD
  • 6.3.2. SUBTRACT
  • 6.3.3. MULTIPLY
  • 6.3.4. DIVIDE
  • 6.3.5. ROUNDED OPTION
  • 6.3.6. ON SIZE ERROR
  • 6.3.7. COMPUTE
  • 6.3.8. ARITHMETIC OPERATORS
  • 6.4. MISCELLANEOUS
  • 6.4.1. ACCEPT
  • 6.4.2. DISPLAY
  • 6.4.3. CONTINUE
  • 6.4.4. STOP RUN
  • 6.4.5. EXIT
  • 6.4.6. INITIALIZE
  • 6.5. CONDITIONAL AND UNCONDITIONAL TRANSFER
  • 6.5.1. SIMPLE IF STATEMENT
  • 6.5.2. NESTED IF
  • 6.5.3. EVALUATE STATEMENT
  • 6.5.4. GO TO STATEMENT
  • 6.5.5. GO TO WITH DEPENDING
  • 6.5.6. ALTER
  • 6.6. PERFORM STATEMENTS
  • 6.6.1. BASIC PERFORM
  • 6.6.2. PERFORM WITH TIMES PHRASE
  • 6.6.3. PERFORM WITH UNTIL PHRASE
  • 6.6.4. PERFORM WITH VARYING PHRASE
  • 6.7. CONDITIONAL EXPRESSIONS
  • 6.7.1. RELATIONAL CONDITION
  • 6.7.2. SIGN CONDITION
  • 6.7.3. CLASS CONDITION
  • 6.7.4. CONDITION-NAME CONDITION
  • 6.7.5. NEGATED SIMPLE CONDITION
  • 6.7.6. COMPOUND CONDITION
  • 7. FILE HANDLING
  • 7.1. SEQUENTIAL FILES
  • 7.2. INDEXED FILES
  • 7.3. DIRECT ACCESS FILES
  • 7.4.STEPS INVOLVED IN FILE HANDLING
  • 7.4.1. EXAMPLE
  • 7.5. SELECT STATEMENT
  • 7.5.1. ORGANIZATION CLAUSE
  • 7.5.2. ACCESS MODE CLAUSE
  • 7.5.3. RECORD KEY PHRASE
  • 7.5.4. ALTERNATE KEY PHRASE
  • 7.6. FD ENTRY
  • 7.6.1. BLOCK CONTAINS / RECORD CONTAINS PHRASE
  • 7.6.2. RECORDING MODE CLAUSE
  • 7.7. INPUT / OUTPUT STATEMENTS
  • 7.8. VSAM DATA SET
  • 7.8.1. VSAM DATASETS AND ACCESS MODES
  • 7.8.2. ENVIRONMENT DIVISION ENTRIES FOR VSAM FILES
  • 7.8.3. COBOL STATEMENTS USABLE WITH SEQUENTIAL FILES
  • 7.8.4. COBOL STATEMENTS WITH INDEXED FILES (KSDS) AND RELATIVE (RRDS)
  • 7.8.5. PROCEDURE DIVISION STATEMENTS TO UPDATE VSAM FILES
  • 7.8.6. ERROR PROCESSING FOR VSAM
  • 7.8.7. APPLICATIONS BEST SUITED TO VSAM DATASETS
  • 8. SUBPROGRAMS
  • 8.1. LINKAGE SECTION
  • 8.1.1. STATIC / DYNAMIC CALLS
  • 8.1.2. PASSING RETURN CODE INFORMATION
  • 9. STRING, UNSTRING AND INSPECT STATEMENTS
  • 9.1. STRING STATEMENT
  • 9.2. UNSTRING STATEMENT
  • 9.3. INSPECT STATEMENT
  • 9.4. DECLARATIVES
  • 10. SORT AND MERGE STATEMENTS
  • 11. INTRINSIC FUNCTIONS
  • 11.1. NUMBER HANDLING
  • 11.2. DATE / TIME
  • 11.3. FINANCE
  • 11.4. MATHEMATICS & STATISTICS
  • 12. COMPILER OPTIONS
  • 13. APPENDIX
  • 13.1. ERROR CODES
  • 13.2. EXERCISES
  • 13.2.1. BASIC PROBLEM SOLVING
  • 13.2.2. REPORT PREPARATION
  • 13.2.3. ARRAY HANDLING
  • 13.2.4. FILE HANDLING
  • 13.3. JCL

COBOL

Training Material

www.mainframe230.blogspot.com

COBOL Training

Table of Contents

1. OBJECTIVES 2. INTRODUCTION TO COBOL
2.1. LANGUAGE CONSTRUCTION 2.2. COBOL CHARACTER SET 2.3. COBOL WORDS 2.4. COBOL CODING FORM 2.5. DIVISIONS OF COBOL

5 6
6 7 7 7 8

3. IDENTIFICATION DIVISION
3.1. SYNTAX OF IDENTIFICATION DIVISION

9
9

4. ENVIRONMENT DIVISION
4.1. CONFIGURATION SECTION 4.1.1. SOURCE-COMPUTER 4.1.2. OBJECT COMPUTER 4.1.3. SPECIAL-NAMES 4.2. INPUT-OUTPUT SECTION 4.2.1. FILE-CONTROL 4.2.2. I-O CONTROL

10
10 10 10 10 11 11 11

5. DATA DIVISION
5.1. LITERALS AND FIGURATIVE CONSTANTS 5.1.1. NUMERIC LITERAL 5.1.2. NON-NUMERIC LITERAL 5.1.3. LIST OF FIGURATIVE CONSTANTS 5.2. Data Description 5.2.1. LEVEL NUMBERS 5.2.2. Data Names 5.2.3. CLAUSE 5.2.4. CONDITION NAMES

13
14 14 15 15 15 15 16 18 23

6. PROCEDURE DIVISION
6.1. STATEMENTS IN PROCEDURE DIVISION 6.2. Data Movement 6.2.1. MOVE 6.3. ARITHMETIC VERBS 6.3.1. ADD 6.3.2. SUBTRACT 6.3.3. MULTIPLY 6.3.4. DIVIDE 6.3.5. ROUNDED OPTION 6.3.6. ON SIZE ERROR 6.3.7. COMPUTE 6.3.8. ARITHMETIC OPERATORS 6.4. Miscellaneous 6.4.1. ACCEPT

24
25 26 26 27 27 28 30 31 33 33 33 33 34 34

www.mainframe230.blogspot.com

Page 2

date:16.05.2010

COBOL Training 6.4.2. DISPLAY 6.4.3. CONTINUE 6.4.4. STOP RUN 6.4.5. EXIT 6.4.6. INITIALIZE 6.5. CONDITIONAL AND UNCONDITIONAL TRANSFER 6.5.1. SIMPLE IF STATEMENT 6.5.2. NESTED IF 6.5.3. EVALUATE STATEMENT 6.5.4. GO TO STATEMENT 6.5.5. GO TO WITH DEPENDING 6.5.6. ALTER 6.6. PERFORM STATEMENTS 6.6.1. Basic Perform 6.6.2. PERFORM with TIMES phrase 6.6.3. PERFORM with UNTIL phrase 6.6.4. PERFORM with VARYING phrase 6.7. Conditional expressions 6.7.1. RELATIONAL CONDITION 6.7.2. SIGN CONDITION 6.7.3. CLASS CONDITION 6.7.4. CONDITION-NAME CONDITION 6.7.5. NEGATED SIMPLE CONDITION 6.7.6. COMPOUND CONDITION 34 34 35 35 35 35 35 36 36 37 37 38 38 38 39 39 40 40 41 41 41 41 42 42

7. FILE HANDLING
7.1. Sequential Files 7.2. Indexed Files 7.3. Direct Access Files 7.4.STEPS INVOLVED IN FILE HANDLING 7.4.1. EXAMPLE 7.5. SELECT Statement 7.5.1. ORGANIZATION CLAUSE 7.5.2. ACCESS MODE CLAUSE 7.5.3. RECORD KEY PHRASE 7.5.4. ALTERNATE KEY PHRASE 7.6. FD entry 7.6.1. BLOCK CONTAINS / RECORD CONTAINS PHRASE 7.6.2. RECORDING MODE CLAUSE 7.7. INPUT / OUTPUT STATEMENTS 7.8. VSAM DATA SET 7.8.1. VSAM DATASETS AND ACCESS MODES 7.8.2. ENVIRONMENT DIVISION ENTRIES FOR VSAM FILES 7.8.3. COBOL STATEMENTS USABLE WITH SEQUENTIAL FILES 7.8.4. COBOL STATEMENTS WITH INDEXED FILES (KSDS) AND RELATIVE (RRDS) 7.8.5. PROCEDURE DIVISION STATEMENTS TO UPDATE VSAM FILES 7.8.6. ERROR PROCESSING FOR VSAM 7.8.7. APPLICATIONS BEST SUITED TO VSAM DATASETS

43
43 43 43 43 44 46 47 47 48 48 48 49 50 50 54 55 55 56 56 59 60 60

8. SUBPROGRAMS
8.1. LINKAGE SECTION 8.1.1. STATIC / DYNAMIC CALLS 8.1.2. PASSING RETURN CODE INFORMATION

61
62 63 63

www.mainframe230.blogspot.com

Page 3

date:16.05.2010

COBOL Training

9. STRING, UNSTRING AND INSPECT STATEMENTS
9.1. STRING STATEMENT 9.2. UNSTRING STATEMENT 9.3. INSPECT STATEMENT 9.4. DECLARATIVES

65
65 66 68 70

10. SORT AND MERGE STATEMENTS 11. INTRINSIC FUNCTIONS
11.1. Number Handling 11.2. Date / Time 11.3. Finance 11.4. Mathematics & Statistics

71 77
77 77 77 78

12. COMPILER OPTIONS 13. APPENDIX
13.1. ERROR CODES 13.2. EXERCISES 13.2.1. BASIC PROBLEM SOLVING 13.2.2. REPORT PREPARATION 13.2.3. ARRAY HANDLING 13.2.4. FILE HANDLING 13.3. JCL

79 81
81 82 82 83 83 83 84

www.mainframe230.blogspot.com

Page 4

date:16.05.2010

is that the students should be able to:  Understand the standard format of the COBOL program.  Write COBOL programs which uses VSAM or Non VSAM files. OBJECTIVES The main objective after the completion of this course. www.05.mainframe230.2010 .COBOL Training 1.  Write programs using modular design techniques.blogspot.com Page 5 date:16.  Submit jobs to Compile and Link-edit COBOL source codes.

blogspot. It specifies an attribute for an entry  Statement is syntactically valid combination of words and clauses www. INTRODUCTION TO COBOL COBOL => COMMON BUSINESS ORIENTED LANGUAGE Cobol can be referred to as:  High-Level Programming language oriented towards business applications. computer manufacturers Standard Versions of COBOL  1960s . standardized  1985 .  Character is the lowest component.  A procedure oriented language.COBOL Training 2.1.first COBOL standard set by American National Standards Institute (ANSI)  1974 . A Problem may be segmented into multiple sub-functionalities.com Page 6 date:16.2010 .Some Characteristics  COBOL is self-documenting  COBOL is simple  COBOL is non-proprietary (portable)  COBOL is Maintainable 2.wide variations in COBOL compilers  1968 .  Clause consists of word and characters.mainframe230.second ANSI standard to make COBOL more efficient. Each sub-functionality is written as a Paragraph in Procedure Division and executed in a logical sequence as mentioned. A Procedure is a module having its own functionality.this ANSI standard incorporated structured programming techniques COBOL . business. LANGUAGE CONSTRUCTION  COBOL is like an English language.05.  Problem Oriented and Machine independent History of COBOL  Developed in 1959 as standard language to meet needs of business  Committee to develop language convened by Department of Defense  Included representatives from academia.  Word is made up of one or more characters.

.6 7 8 .>.. COBOL CODING FORM Columns 1.(.2..blogspot. 2. COBOL WORDS User defined words  Words declared by programmer to coin identifiers.mainframe230.Z b +.*.4.= $. section and paragraph-names must all begin in Area A and end with a period. comment or starting of a new page COBOL program statements Remarks / (slash) forces page break when printing source listing .com Page 7 date:16.(dash) to indicate continuation of nonnumeric literal  Columns 8-72 divided into two areas Area A . COBOL CHARACTER SET Set of 51 characters 0.72 73-80  Sequence numbers identifying pages or lines of a program Continuation..../. Column 7 * (asterisk) designates entire line as comment www.-.. DIGITS LETTERS SPACE/BLANK CHARACTER SPECIAL SYMBOLS 2.<.2010 .COBOL Training  Sentence is a sequence of one or more statements terminated by period  Paragraph consists of one or more sentences  Section consists of one or more paragraphs  Division consists of one or more paragraphs or sections  Program is made up of divisions 2.3.columns 8 to 11 Area B .). Reserved words  Words that are having specific meaning to the compiler.05. file names and section names.columns 12 to 72 Division. paragraph names.“.9 A.

DIVISIONS OF COBOL Every COBOL program contains up to four separate divisions in the following order:     IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION www.COBOL Training 2.mainframe230.5.com Page 8 date:16.05.blogspot.2010 .

www. in the case of IBM COBOL. PROGRAM-ID. Identifies program name to operating system.COMMENT ENTRY.COMMENT ENTRY. Security here does not pertain to the operating system security.COMMENT ENTRY.1. DATE-COMPILED. Other paragraphs are optional but essential for documentation. AUTHOR. First division of a Cobol program.COBOL Training 3. 3. INSTALLATION. PROGRAM NAME.2010 . IDENTIFICATION DIVISION The Identification Division is:        Paragraph ‘PROGRAM-ID’ followed by a user-defined name is compulsory. For example.blogspot. Length of PROGRAM-ID differs from compiler to compiler. SYNTAX OF IDENTIFICATION DIVISION IDENTIFICATION DIVISION.COMMENT ENTRY. Should begin in Area A.COMMENT ENTRY. but the information that is passed to the user of the program about the Security features of the program. it is 8 characters. SECURITY.com Page 9 date:16. Provides documentation about program.05. DATE-WRITTEN.mainframe230.

Describes the computer used. Regardless of the number of entries in this paragraph.1. ‘ are to be interchanged in the PIC clause. Substitutes character for currency sign. Maps IBM specified environment names to user defined mnemonic names. Indicates that ‘ .1. SOURCE-COMPUTER   Used to specify the name of the Source Computer compiling the COBOL program.COBOL Training 4.1. By default. Division is terminated by a period. 4. object-computer. symbolic-names and classes defined by programmer. The Division itself is optional but for file handling it is essential.blogspot.2010 . there should be only one period at the end. peripheral devices.com Page 10 date:16. Should begin in Area A. CONFIGURATION SECTION   Mentions the name of the source-computer. The “With Debugging Mode” option can be mentioned to enable the Compiler to include all the lines with ‘D’ in the 7th column as syntax (Otherwise it is taken as comment). We can change it to ASCII.05. such as. Contains two sections namely.1. OBJECT COMPUTER   Used to specify the target system. etc. We can also specify symbolic characters. OBJECT-COMPUTER. or any other order if we define SPECIAL-NAMES. PERCENTAGE-SIGN IS 38. ‘ and ‘ . SPECIAL-NAMES       Specifies collating sequence. CONFIGURATION and INPUT-OUTPUT. It can also include the debug Declaratives in PROCEDURE DIVISION. 4.mainframe230. 4.2. special-names. 4. ENVIRONMENT DIVISION       It is a machine dependent division.3.1. www. The paragraphs of configuration section are SOURCE-COMPUTER. EBCDIC code is followed in MVS. The program collating sequence can also be specified in this paragraph for SORTING and STRING COMPARISON. and SPECIAL-NAMES.

ALPHABET A01 IS "A" ALSO "a" "B" ALSO "b" ALPHABET A IS STANDARD-1 SYSIN IS PROGIN CURRENCY IS "@" DECIMAL-POINT IS COMMA. AUTHOR. ENVIRONMENT DIVISION. Example: IDENTIFICATION DIVISION. INPUT-OUTPUT SECTION   Contains information regarding files to be used in the program. OBJECT-COMPUTER.2. Three formats for the FILE-CONTROL paragraph are:    Sequential file entries Indexed file entries Relative file entries Coding rules for FILE-CONTROL paragraph. I-O CONTROL     Optional Paragraph. EDS001. Specifies when check points are to be taken.mainframe230. FILE-CONTROL Associates each file used in a COBOL program with an external ddname.1. The key word I-O control must begin in Area A. Specifies the storage areas to be shared by different files.    SELECT clause must appear first Other clauses may appear in any order Each clause must start in Area B 4.2.2010 . CONFIGURATION SECTION.blogspot.2. PROGRAM-ID.05. Consists of two paragraphs FILE-CONTROL and I-O CONTROL. 4. A343. IBM-390 PROGRAM COLLATING SEQUENCE IS A01.COBOL Training 4. FILE-CONTROL SELECT OUTFILE ASSIGN TO DD1 ORGANIZATION IS SEQUENTIAL ACCESS MODE SEQUENTIAL www. INPUT-OUTPUT SECTION. Physical dataset is assigned in DD statement of JCL at execution time.2. SPECIAL-NAMES.com Page 11 date:16. IBM-390 WITH DEBUGGING MODE. SOURCE-COMPUTER.

www.mainframe230.blogspot.05.2010 .COBOL Training FILE STATUS IS WS-FST.com Page 12 date:16.

Describes data made available from another program.com Page 13 date:16.blogspot.Used if labels stored in file www. File Description clauses LABEL RECORDS clause .2010 .  Describes input and output format of data in files. WORKING-STORAGE SECTION    LINKAGE SECTION  FILE SECTION File Description Entries   Each file described with an FD (File Descriptor) sentence One FD for each SELECT statement in ENVIRONMENT DIVISION Syntax: FD file-name RECORD IS LABEL RECORDS ARE STANDARD OMITTED RECORD CONTAINS integer-1 CHARACTERS BLOCK CONTAINS integer-2 RECORDS.COBOL Training 5. DATA DIVISION Data division is used to define data needed to be accessed by the program.  The three sections of this division are: FILE SECTION  Describes Record Structure of Files Succeeds file section Used for intermediate storage Common practice to group related items together. Defines any constants and work areas.05.mainframe230.

1.COBOL Training BLOCKS CONTAINS clause .blogspot. LITERALS AND FIGURATIVE CONSTANTS     Literal is a constant representing a number or Non number (Alpha numeric) like 45.com Page 14 date:16. NUMERIC LITERAL  Must contain at least one digit www. ends with period All items must be defined at 01 level or in entries subordinate to 01 level entry Rules for user-defined data-names apply Elementary items: • • Must include PICTURE clause May be assigned initial value with VALUE clause 5. Literals are storable in a memory Location having a user defined name called Data Name or Identifier or Variable or Field Figurative Constant is a COBOL RESERVED WORD representing frequently used constants like ZEROS / SPACES.mainframe230.1. Figurative constants are used in the program as such for better readability as. MOVE SPACES TO WS-REC. 05 Name-In … 05 Annual-Salary-In … 05 Job-Description-In … WORKING-STORAGE SECTION      Follows FILE SECTION Starts in Area A.1.  Literals are classified in to NUMERIC and NON-NUMERIC literals.Indicates blocking factor for disk files Both labels and blocking usually handled by operating systems so clauses will be omitted RECORD CONTAINS clause . 5.Indicates size of each record (Optional but recommended since it provides check on record size) Defining a Record Each FD followed by record description entries for the file Record-name defined at the 01 level -Considered highest level of data Fields within a record defined at subordinate level with level numbers from 02 to 49    Example: 01 Employee-Rec-In.2010 .05.3 / ‘MANAGER’.

2. A level-number has a value taken from the set of integers between 1 and 49.2. a renamed or redefined item. NON-NUMERIC LITERAL     May consist of any character in the character set Must be enclosed in quotes A numeric literal in quotes is non-numeric Maximum length of 120 chars 05 COMPANY-NAME PIC X(3) VALUE ‘EDS’. LIST OF FIGURATIVE CONSTANTS ZERO / ZEROES / ZEROS QUOTE / QUOTES SPACE / SPACES ONE OR MORE ZEROS ONE OR MORE “ ONE OR MORE SPACE X’FF’ FOR EBCDIC LOW-VALUE / LOW-VALUES LOWEST VALUE IN COLLATING SEQUENCE ALL literal ONE or MORE OCCURENCES OF literal HIGH-VALUE / HIGH-VALUES HIGHEST VALUE IN COLLATING SEQUENCE 5.05. and identifies special-purpose data entries. 5.COBOL Training     + or .blogspot. A record structure is a structure of all the fields of a record.mainframe230. 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.2. 66. Here ‘EDS’ is an alphanumeric constant assigned in identifier COMPANY-NAME. or 88. Here 100 is a numeric constant assigned in identifier TOTAL-MARK. LEVEL NUMBERS    A Record is a Collection of all the fields pertaining to an Item/person/Transaction.1. or a condition-name entry. or from one of the special level-numbers. DATA DESCRIPTION The general format of the data description is  Level-number data-name / FILLER clauses 5. 5.2010 .3. The level-number specifies the hierarchy of data within a record.1.1.Sign. 05 TOTAL-MARK PIC 9(3) VALUE 100. A level-number begins a data description entry. It may be available in the FILE SECTION/ WORKING-STORAGE SECTION/ LINKAGE SECTION. 77.  www.com Page 15 date:16.

1.com Page 16 date:16. Example 01 77 01 TOTAL WS-FLAG PIC PIC 9(5). Only special Character allowed is – ( Hyphen) but should not be at the Beginning or End Examples of data names EMPLOYEE-NAME . 77 Identifies independent elementary data item.2. 05 DN─3.   01 EMPLOYEE-REC. PIC A. 03 FIRST-NAME 03 INITIAL-1 03 INITIAL-2 03 INITIAL-3 5..mainframe230.2010 . .. . 5. PIC A.1..2. 999-EMPLOYEE-RECORD Data name must be unique within a Record www. 88 Identifies any condition name that is associated with a particular value of conditional variable Level Number 01 can appear as a Group Level Number as well as Elementary data item level number. There should be at least one Alphabet anywhere in the name. DN─6 RENAMES DN─1 THROUGH DN─3. VALUE "Y". │<───────────────RECORD─I───────────────>│ ┌──────┬──────────┬───────────┬──────────┐ │ DN─1 │ DN─2 │ DN─3 │ DN─4 │ └──────┴──────────┴───────────┴──────────┘ │<───────────DN─6────────────>│ 66 RECORD─I.blogspot. It must begin in Area A. 01 SWITCHES. 02 LOADDATA-EOF-SWITCH 88 LOADDATA-EOF PIC X(1) VALUE "N". They may begin in Area A or B Group Level Data Names Will not have Picture Clause. 05 DN─4.. COMPANY.05. 02-49 These level numbers specify group and elementary items within a record..01 entry may be either a group item or an elementary item.. 0001AB. .. PIC A.2. A(30). SPECIAL LEVEL NUMBERS 66 Identifies items that contain the RENAMES clause..COBOL Training 01 This level . WORKING-STORAGE SECTION.number specifies the record itself. . XX. DATA NAMES       Identifier name/ Data name should not exceed 30 Characters.   A level . 05 DN─2. PIC PIC XXXX. 05 DN─1. It can appear only as an elementary Data Item Level Number. 02 EMP-NO 02 EMP-NAME.

COBOL Training  If ‘Name’ is duplicated across Records.05. Time out www. it has to be qualified as Identifier-name of Record Name. My-Section 5.com Page 17 date:16. Identify the valid data-names 1. Last--Name 7.Date-Of-Birth 2. -First-Name 6.mainframe230.2010 . Amount$Out 3. 98-6 8. • DISPLAY BALANCE OF STOCK-RECORD  Here balance is an identifier declared in Stock-record.blogspot. Section 4.

1. FILLER Whenever there is no need for specific reference to fields in a record structure. alphanumeric.05.mainframe230. X(10) 9(6). alphabetic.blogspot. www. VALUE SPACES. 5. Example 01 Detail-record. sign(signed/unsigned).2.2. VALUE SPACES.2010 .com Page 18 date:16.1. X(10) VALUE SPACES.2. decimal point location and size characteristics of a data item. 05 05 05 05 05 05 05 05 FILLER NAME FILLER BASIC FILLER DA FILLER GROSS PIC PIC PIC PIC PIC PIC PIC PIC X(10) X(30) .) (Defines 4 Numeric digits) X REMARK Used for arithmetic operations Assumed Decimal Point Data item is Signed Position of Assumed decimal point when the point lies outside the data item Data Item contains only a Letter Or Space Blank insertion character Data item contains any allowable character from the COBOL character set. edited numeric). TYPE Numeric CHARACTER STRING 9 V S P Alphabetic A B Alpha Numeric Examples VAR1 PIC A(04) VAR2 PIC 9(4) (Defines 4 alphabetic characters. we name it as FILLER or F. 9(05) . 9(04) . 5.2. This Data name is used wherever there is fixed information like SPACES Or Headings Are stored. CLAUSE A Clause specifies certain characteristics of the data item being described.3.COBOL Training 5. X(10) VALUE SPACES.3. Specified for every elementary item Format of Picture Clause. The detail of each Clause is explained below. PICTURE CLAUSE Describes the class (numeric.

EDIT TYPES .3. Example: 10 VAR1 PIC A(2)BBBA(3). Displaying the number as 77.1.00 00b00b46 04560 000/032/54 www. ZERO and SLASH INSERTION PIC OF THE FIELD ZZZV99 * * 999 $ * *999 -ZZZV99 +999 +999 9999+ ZZ.2.05.456 bbbb.2010 .99 99B99B99 09990 999/999/99 NUMERIC VALUE 38^4 00052 985 -46^52 -382 382 -382 2456 5 342 46 456 3254 BLANK WHEN ZERO ZZZ.Z99 ZZZZ.1.3 EDIT TYPES .3.2.ALPHANUMERIC BLANK.1.NUMERIC DATA Z * $ + CR DB ZERO SUPPRESSION ASTERISK CURRENCY SIGN MINUS SIGN PLUS SIGN CREDIT DEBIT SIGN PERIOD( .blogspot. 5.50 EDITED VALUE b3840 * * 052 $**985 -b4652 -382 +382 0382b2.1.ZZ $$$$9.mainframe230.419.com Page 19 date:16.3.2.3. ) COMMA( . /* displays xy abc */ MOVE “xyabc” TO VAR1 DISPLAY VAR1 5. ) BLANK( ‘B‘ ) ZERO( 0 ) SLASH( / ) BLANK WHEN ZERO (Inserts blanks when data value is zero) 5.2.ALPHABETIC Used To Insert Blank within Alphabetic Characters. EDITED PICTURE CLAUSES Used to display Numeric and other data in the human readable form. EDIT TYPES .99 BLANK WHEN ZERO 25 bb2.4.1.56 is easier to read instead of 7741958.COBOL Training 5.2.05 b$342.

VALUE ALL ‘ . -.COBOL Training 999.3. VALUE ZERO.3.99 BLANK WHEN ZERO 0 bbbbbb 5.3. COMPUTATIONAL(COMP) USAGE   Maintained in binary Only integral numbers www.1. USAGE CLAUSE Specifies how a data item is represented internally. +.2.05.3. * Are Mutually Exclusive.2.2010 . $ can appear at first place and * as Floating($****. DISPLAY is the default usage 5. -.3. Are Mutually Exclusive 5. VALUE CLAUSE Assigns initial value to a data item VALUE IS literal Literal can be Numeric.1. CR.3.‘.   DISPLAY COMPUTATIONAL SYNTAX USAGE IS [DISPLAY ] [COMPUTATIONAL] [COMP-1] [COMP-2] [COMP-3] 5. 05 WS-NAME 05 FILLER 01 01 WS-NUM1 WS-CHAR2 PIC X(30) PIC X(20) PIC 9(5) PIC X(5) VALUE ‘ABC VALUE ZERO.2.3.blogspot. The number of bytes required is equal to the size of the item. DISPLAY USAGE.2. EDIT COMBINATION +. Non-Numeric(in Quotes) or Figurative Constant Not for items whose size is variable Value of item should not exceed picture size Consistent with class of PIC clause Examples 01 WS-REC.2.2.2. Z. COMPANY ‘. 5.5.3.**) V and .mainframe230. DB Are Mutually Exclusive $.com Page 20 date:16. Each character of the data is represented in one byte .

Internally stored as 00010010 1 10 2 A is stored as 00000000 (Extra Byte) 5.com Page 21 date:16.COBOL Training   Depending on the size of the data item. COMP-2 USAGE. 0010 0011 1111 VALUE 123. COMP-1 USAGE .mainframe230.blogspot.2. it can be stored either in half word or full word Should be numeric only NUMBER OF digits IN PIC 1 TO 4 5 TO 9 10 TO 18 LENGTH OF ITEM IN BYTES 2 4 8 01 WS .2010 .3.      EXAMPLE FOR USAGE COMP .     One word in floating point form The number is represented in hexadecimal The picture clause cannot be specified Suitable for arithmetic operations WS-NUM USAGE COMP-1.NUM PIC S9(004) USAGE COMP. SIGN CLAUSE   [SIGN IS] [LEADING] [SEPARATE CHAR ] [TRAILING] Specifies the position and mode of representation of sign www.4.05.   Same as COMP 1 except that data is represented internally in two words Increases the precision of the data Internal Representation In Packed Decimal Form Each digit and sign occupy 1/2 a byte The Hexadecimal number C or F denotes a positive sign The Hexadecimal number D denotes a negative sign Maximum precision is 18 COMP-3 USAGE.3 10 A PIC 0011 3 PIC 0001 S9(3) USAGE COMP-3 1111 F S9(04) USAGE COMP-3 VALUE 123.

5. X(40). Example 01 01 WS-TABLE. REDEFINES CLAUSE This clause allows the same area of memory to be referenced by more than one data-name with different formats and sizes.3.2. 10 such group items (WS-REC) are allocated memory space contiguously.3.2010 . 5. NAME-ADD.3. We use OCCURS clause to allocate physically contiguous memory locations to store the table values and access them with subscripts. Y(1) = 8 bytes) Hence.1.mainframe230.5. 10 WS-REC 15 15 X Y OCCURS 10 PIC PIC TIMES. X(1) = 5 bytes. 10 WS-NAME WS-TABLE. 10 NAME PIC 10 ADD-LN-1 PIC 05 NAME-DD REDEFINES X(20).2.no > <Data-item-1> REDEFINES <Data-item-2>. X(8). OCCURS 10 TIMES PIC X(20).2. D-TYPE-1 05 CARD-CODE PIC 9. SYNTAX AND RULES < Lvl. 05 NAME-ADD.6.6. Example: FD 01 CARDIN.COBOL Training     Only for numeric elementary items Picture string should contain ‘S’ Usage should be DISPLAY Default is TRAILING without separate character EXAMPLE PIC S9(3) S9(3) VALUE -243 -243 SIGN LEADING TRAILING REPRESENTATION K 4 3 2 4 L 5. or within the FILESECTION if a part of a record is to be remapped. OCCURS CLAUSE There may be a need to keep a table of values in the memory for calculations.05.e.Explicit Use OF REDEFINES REDEFINES must be used for re-mapping record areas outside the FILE-SECTION.REC (1) = 13 BYTES (i.blogspot. www. Redefines clause must immediately follow <data-item-1> Level nos of <data-item-1> and <data-item-2> must be identical and not 66 or 88.com Page 22 date:16. WS . X(5).

W-CHAR-123 THRU W-CHAR-56.COBOL Training 10 ADD-LN-2 PIC X(60).7. 01 W-RESPONSE 05 W-CHAR-123 05 W-CHAR-4 05 W-CHAR-56 ADD-RESPONSE VIEW-RESPONSES DELETE-RESPONSE PIC XXX. RENAMES RENAMES RENAMES 66 66 66 W-CHAR-123.2.05. The question of justification comes only when you move a smaller data item to a larger data item.3.mainframe230. Justified clause does not alter initial settings as determined by the value clause Justified clause must not be specified with level 66(RENAMES) and level 88(condition-names) clauses. 5.3.2. RENAMES Regrouping of elementary data items in a Record.2. PIC XX. 5. PIC X. 5. At 01 level.1 > and <data-item-2> Value clauses are allowed only in condition names in a redefined data-item.8.2. Example would be a PIC X(5) field to a PIC X(20) 5. W-CHAR-123 THRU W-CHAR-4. RESTRICTIONS ON USE OF REDEFINES Redefinition ceases whenever a level number is less than or equal to that of <data-item-1> or <data-item2> Multiple redefinition’s of the same area is possible provided there are no new storage areas defined in between < data-item .blogspot. CONDITION NAMES   Allow users to assign acceptable values for data names Are used as an abbreviation for condition checking PIC VALUE VALUE 9(02). JUSTIFIED CLAUSE Overrides standard positioning rules for a receiving stem of the alphabetic or alphanumeric categories. <data-name-2> may not have an OCCURS clause.com Page 23 date:16.3.4. OCCURS and REDEFINES cannot be combined. O THRU 20 21 THRU 99 88 C-PERSON-MINOR 88 C-PERSON-ADULT 01 W-PERSON-AGE www.6. 01 WS-CHAR PIC Default is left justified X(05) JUSTIFIED RIGHT.2010 .2.

Section: A section is a block of code usually containing one or more paragraphs. A section begins with the section name and ends where the next section name is encountered or where the program text ends. that starts where the division name is encountered and ends with the beginning of the next division or with the end of the program text. Example: SUBTRACT Tax FROM GrossPay GIVING NetPay www. Example: SelectUnpaidBills SECTION. PROGRAM-ID. Example: PrintFinalTotals.21 TO VatRate MOVE 1235.2010 . Sentences and statements: A sentence consists of one or more statements and is terminated by a period.blogspot.COBOL Training 6.05.mainframe230. FILE SECTION. A paragraph begins with the paragraph name and ends with the next paragraph or section name or the end of the program text. PROCEDURE DIVISION    Last division in a COBOL program Contains statements which specify the operations to be performed Contains the following structure Division: A division is a block of code. usually containing one or more sections. Example: MOVE .com Page 24 date:16. Paragraphs: A paragraph is a block of code made up of one or more sentences. A statement consists of a COBOL verb and an operand or operands.76 TO ProductCost COMPUTE VatAmount = ProductCost * VatRate.

mainframe230. END-EVALUATE. IF . Example : Use. and that the subsequent action of the object program is dependent on this truth value. END-MULTIPLY .blogspot.. END-CALL. ADD. STATEMENTS IN PROCEDURE DIVISION Procedure division statements can be broadly classified as   Imperative Statements Statement which directs the program to take a specific action during execution Examples MOVE. beginning with a compiler directing verb. GOTO. COMPUTE.com Page 25 date:16. This includes statements which contain conditional expression (like IF statement) and imperative statements (like ADD) Examples END-ADD. that causes the compiler to take a specific action during compilation.NOT ON SIZE ERROR COMPUTE.. END-COMPUTE. Copy Explicit Scope Terminator An EXPLICIT SCOPE TERMINATOR terminates the scope of conditional statements. ADD.2010 .COBOL Training PROCEDURE DIVISION GUIDELINES:        Paragraph names and 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 from paragraph names Section names should be followed by a space and the word SECTION with a period at the end Paragraph names must be unique within a section If paragraph name is duplicated across sections.ON SIZE ERROR.   Examples: Conditional Statements A conditional statement specifies that the truth value of a condition is to be determined.ON SIZE ERROR.NOT ON SIZE ERROR Compiler Directives A Compiler-Directing Statement is a statement. EVALUATE . www. EXIT.. an IMPLICIT SCOPE TERMINATOR is a separator period that terminates the scope of all previous statements not yet terminated.05. ADD. Example with ADD ADD 1 TO TWODIGITYEAR ON SIZE ERROR PERFORM CENTURYWINDOWOVERFLOW END-ADD Implicit Scope Terminator At the end of any sentence. END-READ... END-SUBTRACT. it has to be qualified as paragraph-name { of / in } section name 6..1.. END-IF.. END-DELETE.

it is called A Group Move www. The dominant factor in the numeric data transfer is the alignment of decimal points of the two fields. If the significant integral positions are likely to be lost. DATA MOVEMENT RULES   Only one sending field. MOVE A TO B Examples: After execution A will contain 0015 and B will contain bb15. the Data Movement is called Numeric. When the receiving field is smaller.1. If the receiving field is not large enough to hold the data received.4.05.1. one or more receiving fields.IDENTIFIER-3].1. 6. MOVE To move data into a place in memory. the decimal point is assumed to be at the right of the rightmost digit. truncation can take place at either ends or at both ends.2.2.. the Data Movement is called as Alphanumeric.2010 .COBOL Training 6. 6. truncation occurs from the right and the compiler gives a warning to that effect If the receiving field is larger than the field.. Value of the sending field remains unaltered after the statement execution. which is called as ‘ space fill ‘ A defined as PIC 9999 B defined as PIC ZZZ9 MOVE 15 TO A. the unused positions will be filled with zeros.mainframe230. ALPHANUMERIC DATA TRANSFER     When both the sending and receiving fields are alphabetic. which is known as ‘ zero fill ‘. alphanumeric or alphanumeric edited.1. GROUP MOVES When at Least One Of The Fields is a Group item.1.2.2. receiving area is filled from left to right. a warning to that effect is issued by the compiler. Format. 6. DATA MOVEMENT 6.2.com Page 26 date:16.3. If the receiving field is larger than the sending field.2. 6. In the case of alphanumeric data transfer. the unused positions will be filled with spaces.blogspot. MOVE {IDENTIFIER-1/LITERAL-1} TO IDENTIFIER-2[.1. NUMERIC DATA TRANSFER RULES       When sending field is numeric or numeric-edited. If the decimal point is not explicitly indicated.2.

mainframe230.3.blogspot. in the left-toright order in which identifier-2 is specified.COBOL Training Example: 01 REC-1. XXXX. AA. 05 05 05 REC-2 05 05 05 A1 A2 A3 B1 B2 B3 PIC PIC PIC PIC PIC PIC 9999.2010 .5. ADD This verb is used to find the sum of two or more numbers and to store the resultant sum <──────────────────┐ <───────────────────────────┐ >>──ADD────┬─identifier-1─┬─┴──TO────identifier-2──┬─────────┬─┴─────> └─literal-1────┘ └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬─────────┬──────────────────────────────────────────────────────>< └─END-ADD─┘ All identifiers or literals preceding the key word TO are added together. 6. 01 PRINT-REC. 9999.3.2. AA. 05 EMP-NAME PIC X(30). 05 FILLER PIC X(5). 05 EMP-BASIC PIC 9(5)V99. PIC 9(5) 05 EMP-NAME PIC X(30). 05 EMP-NO PIC 9(5). This process is repeated for each successive occurrence of identifier-2. 05 FILLER PIC X(5). www.com Page 27 date:16.1.1. MOVE CORRESPONDING PAY-REC TO PRINT-REC. 05 FILLER PIC X(5).99. and this sum is added to and stored in identifier-2. Source and destination groups can include data names that are not common Only the fields having identical names in the two records will take part in the data movements The remaining data items in the destination group will remain unchanged Example: 01 PAY-REC. this statement can be used to substitute for a set of move statements MOVE CORRESPONDING IDENTIFIER-1 TO IDENTIFIER-2.05. ARITHMETIC VERBS 6. 05 EMP-NO. XXXX. 05 EMP-SAL PIC 9(6). 01 MOVE REC-1 TO REC-2 6. MOVE CORRESPONDING When the names of the corresponding data item of two groups are the same.

com Page 28 date:16. numeric elementary items in the group referred to by first identifier are added to and stored in the corresponding elementary items of the second group.mainframe230.      In the case of TO option. only if they have the Same data name and same qualifiers Corresponding items can have different locations within the group and the field sizes Can also be different.COBOL Training <──────────────────┐ >>──ADD────┬─identifier-1─┬─┴──┬────┬──┬─identifier-2─┬──────────────> └─literal-1────┘ └─TO─┘ └─literal-2────┘ <───────────────────────────┐ >──GIVING────identifier-3──┬─────────┬─┴─────────────────────────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬─────────┬──────────────────────────────────────────────────────>< └─END-ADD─┘ The values of the operands preceding the word GIVING are added together. ADD CORR OLD-REC TO NEW-REC.3. Data items in identifier-1 and identifier-2 take part in the summation.2.blogspot.05. the previous value of the last named operand takes part in the summation and then this value is replaced by the result. In the group add. SUBTRACT <──────────────────┐ www. the value of the last named operand does not take part in the summation and only the result is stored there. 6. Whereas in the case of GIVING option. >>──ADD──┬─CORRESPONDING─┬──identifier-1──TO──identifier-2───────────> └─CORR──────────┘ >──┬─────────┬──┬────────────────────────────────────────────┬───────> └─ROUNDED─┘ └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬─────────┬──────────────────────────────────────────────────────>< └─END-ADD─┘ Elementary data items within identifier-1 are added to and stored in the corresponding elementary items within identifier-2. Example: ADD A TO B ADD A B GIVING C.2010 . and the sum is stored as the new value of each data item referenced by identifier-3.

com Page 29 date:16. This process is repeated for each successive occurrence of identifier-2. <──────────────────┐ >>──SUBTRACT────┬─identifier-1─┬─┴──FROM──┬─identifier-2─┬───────────> └─literal-1────┘ └─literal-2────┘ <───────────────────────────┐ >──GIVING────identifier-3──┬─────────┬─┴─────────────────────────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬──────────────┬─────────────────────────────────────────────────>< └─END-SUBTRACT─┘ All identifiers or literals preceding the key word FROM are added together and this sum is subtracted from identifier-2 or literal-2. in the left-to-right order in which identifier-2 is specified.2010 .blogspot. The result of the subtraction is stored as the new value of each data item referenced by identifier-3.05.COBOL Training >>──SUBTRACT────┬─identifier-1─┬─┴──FROM─────────────────────────────> └─literal-1────┘ <───────────────────────────┐ >────identifier-2──┬─────────┬─┴─────────────────────────────────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬──────────────┬─────────────────────────────────────────────────>< └─END-SUBTRACT─┘ All identifiers or literals preceding the key word FROM are added together and this sum is subtracted from and stored immediately in identifier-2. >>──SUBTRACT──┬─CORRESPONDING─┬──identifier-1──FROM──────────────────> └─CORR──────────┘ >──identifier-2──┬─────────┬─────────────────────────────────────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬──────────────┬─────────────────────────────────────────────────>< www.mainframe230.

05. The product is then stored in the data item(s) referenced by identifier-3. SUBTRACT A B FROM C. Example: www.2010 . 6.mainframe230. SUBTRACT A B FROM C D. For each successive occurrence of identifier-2. SUBTRACT 10 FROM A. the product is then placed in identifier-2. the corresponding elementary data items within identifier-2.blogspot. MULTIPLY <───────────────────────────┐ >>──MULTIPLY──┬─identifier-1─┬──BY────identifier-2──┬─────────┬─┴────> └─literal-1────┘ └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬──────────────┬─────────────────────────────────────────────────>< └─END-MULTIPLY─┘ The value of identifier-1 or literal-1 is multiplied by the value of identifier-2. >>──MULTIPLY──┬─identifier-1─┬──BY──┬─identifier-2─┬─────────────────> └─literal-1────┘ └─literal-2────┘ <───────────────────────────┐ >──GIVING────identifier-3──┬─────────┬─┴─────────────────────────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬──────────────┬─────────────────────────────────────────────────>< └─END-MULTIPLY─┘ The value of identifier-1 or literal-1 is multiplied by the value of identifier-2 or literal-2. Example: SUBTRACT A FROM B.COBOL Training └─END-SUBTRACT─┘ Elementary data items within identifier-1 are subtracted from.com Page 30 date:16.3. and the results are stored in. the multiplication takes place in the left-to-right order in which identifier-2 is specified.3.

5 BY B.mainframe230.com Page 31 date:16. The value of the quotient is stored in each data item referenced by identifier-3. >>──DIVIDE──┬─identifier-1─┬──INTO──┬─identifier-2─┬─────────────────> └─literal-1────┘ └─literal-2────┘ <───────────────────────────┐ >──GIVING────identifier-3──┬─────────┬─┴─────────────────────────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬────────────┬───────────────────────────────────────────────────>< └─END-DIVIDE─┘ In Format 2.4.blogspot.3. the value of identifier-1 or literal-1 is divided into the value of identifier-2. and the quotient is then stored in identifier-2.05. the division takes place in the left-to-right order in which identifier-2 is specified. DIVIDE <───────────────────────────┐ >>──DIVIDE──┬─identifier-1─┬──INTO────identifier-2──┬─────────┬─┴────> └─literal-1────┘ └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬────────────┬───────────────────────────────────────────────────>< └─END-DIVIDE─┘ In Format 1.COBOL Training MULTIPLY A MULTIPLY A MULTIPLY A MULTIPLY 0. BY B C D. BY B GIVING C. >>──DIVIDE──┬─identifier-1─┬──BY──┬─identifier-2─┬───────────────────> └─literal-1────┘ └─literal-2────┘ <───────────────────────────┐ >──GIVING────identifier-3──┬─────────┬─┴─────────────────────────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> www. BY B. 6. For each successive occurrence of identifier-2.2010 . the value of identifier-1 or literal-1 is divided into the value of identifier-2 or literal-2.

05.COBOL Training └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬────────────┬───────────────────────────────────────────────────>< └─END-DIVIDE─┘ In Format 3. Example: DIVIDE DIVIDE DIVIDE 5 A A INTO INTO BY A . >>──DIVIDE──┬─identifier-1─┬──INTO──┬─identifier-2─┬─────────────────> └─literal-1────┘ └─literal-2────┘ >──GIVING──identifier-3──┬─────────┬──REMAINDER──identifier-4────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬────────────┬───────────────────────────────────────────────────>< └─END-DIVIDE─┘ In Format 4. the value of identifier-1 or literal-1 is divided into identifier-2 or literal-2. B GIVING C D.2010 . the value of identifier-1 or literal-1 is divided by identifier-2 or literal-2.mainframe230. The value of the quotient is stored in identifier-3. The value of the quotient is stored in identifier-3. and the value of the remainder is stored in identifier-4..com Page 32 date:16. and the value of the remainder is stored in identifier-4. the value of identifier-1 or literal-1 is divided by the value of identifier-2 or literal-2. B GIVING C. >>──DIVIDE──┬─identifier-1─┬──BY──┬─identifier-2─┬───────────────────> └─literal-1────┘ └─literal-2────┘ >──GIVING──identifier-3──┬─────────┬──REMAINDER──identifier-4────────> └─ROUNDED─┘ >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬────────────┬───────────────────────────────────────────────────>< └─END-DIVIDE─┘ In Format 5.blogspot. www. The value of the quotient is stored in each data item referenced by identifier-3.

the statement becomes a conditional statement. the result exceeds the largest value that can be accommodated in the result field.3. COMPUTE <───────────────────────────┐ >>──COMPUTE────identifier-1──┬─────────┬─┴──┬─=───────┬──────────────> └─ROUNDED─┘ └─ EQUAL ─┘ >──arithmetic-expression─────────────────────────────────────────────> >──┬────────────────────────────────────────────┬────────────────────> └─┬────┬──SIZE ERROR──imperative-statement-1─┘ └─ON─┘ >──┬─────────────────────────────────────────────────┬───────────────> └─NOT──┬────┬──SIZE ERROR──imperative-statement-2─┘ └─ON─┘ >──┬─────────────┬──────────────────────────────────────────────────>< └─END-COMPUTE─┘ This verb is very powerful and is used as a substitute for any of the other arithmetic verbs like add. 6. numeric LITERALS and numeric operators. When a size error occurs. Arithmetic operators permitted in COBOL are: www.5. 6.7. When this phrase is used. ON SIZE ERROR If after an arithmetic operation. divide.6.2010 . 6.05. the contents of the resultant field after the operation is unpredictable. It will round the number to the picture clause.com Page 33 date:16.3. Example: ADD A TO B ON SIZE ERROR GO TO ERROR-PARA.3. The imperative statements can be delimited by END-ADD 6.3.. ARITHMETIC OPERATORS Arithmetic expression is formed with numeric operands.COBOL Training DIVIDE A BY B GIVING C REMAINDER D. ROUNDED OPTION This can be used with any arithmetic verb.mainframe230. subtract. the processing is not terminated and the next statement will be taken up for further execution. Arithmetic expression always assumes a numeric value.blogspot. multiply.8. the error is called a “size error”. This phrase cannot be specified for the identifier that receives the remainder in a divide operation. ADD A B GIVING C ROUNDED. Can be used with any arithmetic verb When a size error occurs.

6. 2 . Mnemonic name option is implementation dependent and has to be defined in SPECIAL-NAMES paragraph. DAY. DISPLAY Display statement is used to display data on the terminal. ADDITION. ACCEPT Accept statement can transfer data from an input/output device. CONTINUE The CONTINUE statement allows you to specify a no operation statement. program is suspended until the operator enters the data. the data is read from the operator’s terminal. At the time of execution. SUBTRACTION. 3 .blogspot. MISCELLANEOUS 6.05. DIVISION.4.2.com Page 34 date:16. literal . 6.Monday. DAY-OF-WEEK.2 [upon mnemonic-name] 6.3. or system information contained in the specified conceptual data items DATE. www.4.1. The time option returns eight digit [9(8)] time in HHMMSSTT format The day-of-week option returns a single digit [9(1)] value as follows: 1 .2010 . or TIME Format: ACCEPT IDENTIFIER [ FROM mnemonic name DATE DAY TIME DAY-OF-WEEK}] When ‘FROM’ is omitted.4.THE-RESULT identifier-2 .mainframe230.4. Format DISPLAY {identifier-1 literal-1} Example DISPLAY “RESULT IS :“.Wednesday and so on. The day option returns five digit [9(5)] current date in YYDDD format. The date option returns six digit [9(6)] current date in YYMMDD format. MULTIPLICATION. ACCEPT THIS-DATE FROM DATE..COBOL Training ** / * + => => => => => EXPONENTIATION.Tuesday.

5. SIMPLE IF STATEMENT IF condition [THEN] statement-1 ELSE statement-2 END-IF.5. INITIALIZE This statement is used to initialize value of either an elementary or group item. STOP RUN This verb is used to terminate the execution of the program. <──────────────┐ >>──INITIALIZE────identifier-1─┴─────────────────────────────────────────────────────> >──┬────────────────────────────────────────────────────────────────────────┬───────>< │ <─────────────────────────────────────────────────────────┐ │ └─REPLACING────┬─ALPHABETIC──────────┬──┬──────┬──BY──┬─identifier-2─┬─┴─┘ ├─ALPHANUMERIC────────┤ └─DATA─┘ └─literal-1────┘ ├─NUMERIC─────────────┤ ├─ALPHANUMERIC-EDITED─┤ └─NUMERIC-EDITED──────┘ Example: INITIALIZE WS .5. CONDITIONAL AND UNCONDITIONAL TRANSFER 6. 6. www.blogspot.COBOL Training CONTINUE indicates that no executable instruction is present. 05 B PIC A(4).2010 . 05 C PIC X(4).05.4.mainframe230. EXIT The EXIT statement provides a common end point for a series of paragraphs.com Page 35 date:16. DATAITEM PIC BEFORE AFTER EXECUTION EXECUTION A 9(4) 1000 0000 B A(4) LIFE bbbb C X(4) A2BC bbbb INITIALIZE B REPLACING NUMERIC DATA BY 105 REPLACING ALPHANUMERIC DATA BY “ LOVE “ REPLACING NUMERIC-EDITED DATA BY 1500. 01 WS . 6. no action takes place 6. 05 A PIC 9(4).4.23.4.REC. This statement indicates a no operation and when executed.6.1. 6.4.REC.

) is placed only at the end of the IF structure. Example: IF ELSE ADD AMOUNT TO TOTAL-2 END-IF. Indent nested ‘if‘ s properly to improve readability and maintainability.blogspot.2...5. If the condition is found to be FALSE. Period (.. after the connective END-IF.. NESTED IF Inclusion of one or more IF statements within its scope is called as Nesting.05. www. i.e.COBOL Training The condition can be any one of the conditions mentioned before. AMOUNT > 5000 THEN ADD AMOUNT TO TOTAL-1 NEXT SENTENCE will be used to make either the THEN or ELSE part dummy.5. Statement-1 represents one or more COBOL statements If the condition is found to be true. the statements represented in the ELSE part will be executed After execution of this statement control will be implicitly transferred to the next sentence following the IF statement.2010 .} [WHEN OTHER {IMPERATIVE-STATEMENT-2}. A list of subjects is specified between the word EVALUATE and the first appearance of WHEN Subject can be an Identifier / Literal /Expression or key words True / False Each WHEN specifies a list of objects Number of subjects and number of objects should tally Subjects and their corresponding objects should be comparable WHEN phrases are taken up for a “ match “ in the order they appear. Statement-1 and Statement-2 represents one or more COBOL statements. IF condition-1 [THEN] IF condition-2 [THEN ] statement-1 ELSE statement-2 END-IF END-IF. The most inclusive IF statement must have terminating period. {WHEN OBJECT-1 [ALSO OBJECT-2}. 6. Imperative statements corresponding to the matching WHEN will be executed. 6..mainframe230.com Page 36 date:16.] [END-EVALUATE] A list of subjects and several lists of objects are associated with an Evaluate. the statements represented in the THEN part will be executed.3.. EVALUATE STATEMENT Used for decisions and can be used when many branches are there Can be used as a substitute for nested if“s EVALUATE SUBJECT-1 [ALSO SUBJECT-2]. WHEN OTHER phrase is selected only if none of the previous WHEN phrases are selected.

procedure-name-2. OR 6 OR 9 OR 11 TO NO . 2 .DAYS TO NO .mainframe230. PROCEDURE-NAME-N DEPENDING ON identifier The statement transfers control to one of the procedures named in the statement depending on the value of the identifier The identifier specified in the statement must be a numeric.5.05. the control is transferred to procedurename-1. n. Note: It is advised to avoid GO TO Statements as the structured programming technique does not support unconditional transfer statements. Non-numeric value. PROCEDURE-NAME-2 ]. GO TO STATEMENT >>──GO──┬────┬──procedure-name-1────────────────────────────────────>< └─TO─┘ It is an unconditional transferring control to the specified paragraph .DAYS TO NO . GO TO WITH DEPENDING This verb is used to conditionally transfer the control to elsewhere in the program.COBOL Training Objects can be Numeric value .4. If the value of the identifier is anything other than the specified range of 1.. . Depending on whether the value of the identifier is 1. . There is no any comparison being made by the system before branching off .5. non-numeric values. elementary item. 6. .com Page 37 date:16.2010 . .OF .DAYS Range of Numeric values.blogspot. 6. GO TO PROCEDURE-NAME-1 [ . www.OF . the said go to is ineffective and the control is transferred to the next statement. Range of Example: EVALUATE PRODUCT-TYPE ALSO CUSTOMER-TYPE WHEN 1 ALSO ANY MOVE 0 TO COMMISSION WHEN 2 ALSO 1 THRU 5 MOVE 10 TO COMMISSION WHEN OTHER MOVE 20 TO COMMISSION END-EVALUATE. Conditional Values.OF . .5.2 . n . integral. Example GO TO DISPLAY-PARA. procedure-name-n respectively. keywords Example1: EVALUATE TRUE WHEN MONTH = 4 MOVE 30 WHEN MONTH = 2 MOVE 28 WHEN OTHER MOVE 31 END-EVALUATE..

mainframe230. 6.6. the control is implicitly. 6. BASIC PERFORM PERFORM PARA-name-1. the GO TO statement transfers control to the paragraph specified in procedure-name-2.6. Before the ALTER statement is executed. The ALTER statement encourages the use of unstructured programming practices.com Page 38 date:16. when control reaches the paragraph specified in procedure-name-1.2010 . procedure-name-1 Must name a Procedure Division paragraph that contains only one sentence: a GO TO statement without the DEPENDING ON phrase. Para-name-1 specifies the range. the EVALUATE statement provides the same function as the ALTER statement and helps to ensure that your program will be well-structured. which contains statements to be executed Upon execution of this statement the control is transferred to the beginning of the paragraph and executes all the statements in that paragraph till the last statement. PERFORM STATEMENTS A PERFORM statement is used to execute a group of consecutive statements specified elsewhere in the program.COBOL Training Example:GO TO RECEIPT-PARA. however. The ALTER statement acts as a program switch. for example. ALTER The ALTER statement changes the transfer point specified in a GO TO statement. After execution of the ALTER statement.blogspot. After executing the said range. >>──ALTER────────────────────────────────────────────────────────────> <────────────────────────────────────────────────────────┐ >────procedure-name-1──TO──┬────────────┬──procedure-name-2─┴───────>< └─PROCEED TO─┘ The ALTER statement modifies the GO TO statement in the paragraph named by procedurename-1. the next time control reaches the paragraph specified in procedure-name-1. under a paragraph.6. 6. transferred to the next line after the PERFORM statement Example: www. Subsequent executions of the modified GO TO statement(s) transfer control to procedure-name-2.1. allowing. the GO TO statement transfers control to the paragraph specified in the GO TO statement.5. ADJUSTMENT-PARA DEPENDING ON TRANSACTION-TYPE. one sequence of execution during initialization and another sequence during the bulk of file processing. procedure-name-2 Must name a Procedure Division section or paragraph.05. ISSUE-PARA.

Initially the condition is expected to be false. PERFORM WITH TIMES PHRASE PERFORM para-name-1 [THRU para-name-2] {identifier-1/ integer} TIMES. within the paragraph being performed. those are also executed After executing the said range.6. The condition should be made true. This statement executes a series of instructions in para-name-1 repeatedly till the condition becomes TRUE. the range is not executed at all Example: MOVE 1 TO I. 6. This is a looping statement that executes the specified range of statements a fixed no.3. www. Here 000-CALC-PARA is performed 10 TIMES.2010 .com Page 39 date:16. of times. This statement executes all the stmts. PERFORM 1000-ACCEPT-PARA. PERFORM para-name-1 thru para-name-2. PERFORM WITH UNTIL PHRASE PERFORM para-name-1 [THRU para-name-2] UNTIL condition.6. 6.COBOL Training 100-MAIN-PARA. transferred to the next line after the PERFORM statement Example: PERFORM BEGIN-PARA THRU END-PARA. Example: PERFORM READ-RTN 10 TIMES.blogspot.mainframe230. the control is implicitly. If the condition is true initially.2. PERFORM 000-CALC-PARA UNTIL I>10 000-CALC-PARA. in READ-RTN 10 times without testing any condition. PERFORM 2000-COMPUTE-PARA.05. -ADD 1 TO I. This statement executes all the statements beginning in the para-name-1 till the last statement in the para-name-2 If there are any other paragraphs placed in between these two paragraphs.

3 1.1 2.blogspot.2 2.4 3.1 1.6.1 3. PERFORM WITH VARYING PHRASE ┌─── Format 4 ─────────────────────────────────────────────────────────────────────────────────────┐ │ │ │ >>──PERFORM────────────────────────────────────────────────────────────────────────────────────> │ │ │ │ >──┬─procedure-name-1──┬───────────────────────────────┬──┤ phrase 1 ├──┬──────────────┬─┬────>< │ │ │ └─┬─THROUGH─┬──procedure-name-2─┘ └─┤ phrase 2 ├─┘ │ │ │ │ └─THRU────┘ │ │ │ │ (1) │ │ │ └─┤ phrase 1 ├──imperative-statement-1─────END-PERFORM────────────────────────────────┘ │ │ │ │ phrase 1: │ │ ├──┬────────────────────────────┬──VARYING──┬─identifier-2─┬──FROM──┬─identifier-3─┬──BY───────> │ │ └─┬──────┬──TEST──┬─BEFORE─┬─┘ └─index-name-1─┘ ├─index-name-2─┤ │ │ └─WITH─┘ └─AFTER──┘ └─literal-1────┘ │ │ │ │ >──┬─identifier-4─┬──UNTIL──condition-1────────────────────────────────────────────────────────┤ │ │ └─literal-2────┘ │ │ │ │ phrase 2: │ │ <───────────────────────────────────────────────────────────────┐ │ │ ├────AFTER──┬─identifier-5─┬──FROM──┬─identifier-6─┬──┤ phrase 3 ├─┴───────────────────────────┤ │ │ └─index-name-3─┘ ├─index-name-4─┤ │ │ └─literal-3────┘ │ │ │ │ phrase 3: │ │ ├──BY──┬─identifier-7─┬──UNTIL──condition-2────────────────────────────────────────────────────┤ │ │ └─literal-4────┘ │ │ │ │ Note: │ │ (1) Imperative-statement-1 is optional as an IBM extension.2010 .4.com Page 40 date:16.7. Example: PERFORM VARYING I FROM 1 BY 1 UNTIL I > 3 AFTER J FROM 1 BY 1 UNTIL J > 4 Display SALE ( I . J ) END-PERFORM.4 2. The above example will take I and j vales as 1. CONDITIONAL EXPRESSIONS In COBOL there are various types of conditions as follows: RELATIONAL CONDITION SIGN CONDITION CLASS CONDITION CONDITION .4 6.3 3.3 2.2 3.2 1.mainframe230.COBOL Training 6. │ │ │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘ This is also a looping statement which executes imperative statement for all possible values of identifier-1 and identifier-3 until Condition-1 and Condition-2 are TRUE.NAME CONDITION NEGATED SIMPLE CONDITION COMPOUND CONDITION www.05.

or equal to zero. CONDITION-NAME CONDITION A condition-name condition tests a conditional variable to determine whether its value is equal to any value(s) associated with the condition-name.1. A non-numeric literal can be enclosed in parentheses within a relation condition.7.2. Example: IF CURR-STOCK-ISS-QTY IS NEGATIVE DISPLAY “ ISSUE CANNOT BE MADE” GO TO NO-STOCK-PARA END-IF. Comparisons can be simplified. less than. numeric.7. www. Example: 01 WS-MARITAL-STATUS 88 SINGLE PIC 9. Alphabetic-lower. Condition names are not memory locations but names assigned to data ranges . SIGN CONDITION The sign condition determines whether or not the algebraic value of a numeric operand is greater than.3.blogspot. VALUE IS 0. arithmetic expression. The Possible SIGN conditions are POSITIVE / NEGATIVE / ZERO. The relational operators are < <= > >= NOT GREATER THAN / LESSER THAN / EQUAL TO IF A > B DISPLAY “ A IS GREATER THAN B “ ELSE DISPLAY “ A IS LESS THAN OR EQUAL TO B “ END-IF.mainframe230. or index-name. RELATIONAL CONDITION A relation condition compares two operands.4.COBOL Training 6.7. or contains only the characters in the set of characters specified by the CLASS clause as defined in the SPECIAL-NAMES paragraph of the Environment Division. CLASS CONDITION The class condition determines whether the content of a data item is alphabetic.7.2010 . alphabetic-upper. either of which can be an identifier. The possible CLASS Conditions are ALPHABETIC / NUMERIC / ALPHANUMERIC Example: IF A IS NUMERIC ADD 1 TO A ELSE DISPLAY “ NON . 6.05. 6.NUMERIC DATA FOR A “ GO TO ERROR-PARA END-IF.com Page 41 date:16. literal. 6.

6. IF SINGLE ADD 1 TO SINGLE-COUNT. 6.COBOL Training 88 MARRIED VALUE IS 1.2010 . Example: IF NOT MARRIED DISPLAY “ELIGIBLE FOR RS 1000 ONLY “ END-IF. OR NOT .mainframe230.blogspot.7. www.7.6.com Page 42 date:16. NEGATED SIMPLE CONDITION A simple condition is negated through the use of the logical operator NOT. COMPOUND CONDITION Two or more conditions can be logically connected to form a compound condition.5. The possible Compound Conditions are AND Example: IF AGE IS LESS THAN 18 AND MARRIED DISPLAY “EARLY MARRIAGE “ END-IF.05.

7.1. FILE HANDLING A data file is a collection of relevant records of an application. This is specified using SELECT statement of File-Control para.DDNAME assigned for the dataset and its primary and alternate key.mainframe230.4. In this Organization  Record can be accessed in any order by key called Primary Key.3.2010 . www.2. INDEXED FILES Indexed File Organization is to do random Processing or sequential processing. if any. SEQUENTIAL FILES If a file organization is Sequential then  Records can be accessed in the order in which they appear in the file  Records can be appended at the end of the file but cannot be inserted.blogspot.COBOL Training 7. A record is a collection of relevant fields pertaining to an item/case/ account/transaction . The organization of the file .STEPS INVOLVED IN FILE HANDLING To handle a file the following operations are to done.  Records cannot be deleted  Records can be updated 7.  All files handled in a program should be assigned a logical name chosen by the programmer as per the syntax similar to Cobol identifier. deleted and updated. 7.com Page 43 date:16. Step 1.  There can be more than one key called Alternate Keys to access records  Records can be inserted added. DIRECT ACCESS FILES This record is best suited if there are records which can be accessed on record number basis rather than based on a field of the record. have to be specified in the File-Control para of Environment Division. Each record has a unique address and is identified by a relative record number (8 digits numeric character).05. File is organized in storage media in one of the following ways    SEQUENTIAL INDEXED RELATIVE 7.

05 CUST-DEPT PIC X(5). SYNTAX : CLOSE File-name. WRITE Record -name.mainframe230. appending.COBOL Training Step2. INPUT-OUTPUT SECTION.4. SYNTAX : Step5. Read File -name. 05 CUST-DTLS PIC X(70). These statements are coded in procedure division. 7. FILE-CONTROL. writing.05. 100-WRITE-PARA. DATA DIVISION. PROGRAM-ID. OPEN OUTPUT CUSTOMER-FILE PERFORM 100-WRITE-PARA PERFORM 200-CLOSE-PARA. 05 CUST-NO PIC X(5). PROCEDURE DIVISION. FILE SECTION. ENVIRONMENT DIVISION. Open statement is used to connect dataset to the Cobol program.  After read / write operations are over the file must be closed to disconnect the file from the Cobol program. Step4. SELECT CUSTOMER-FILE ASSIGN TO ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL RECORD KEY IS CUST-NO FILE STATUS IS WS-FST1. If we have to read a file READ statement is used in procedure Division.blogspot. 01 CUSTOMER-RECORD.1. 000-MAIN-PARA.Also specify as how many records are grouped as a BLOCK for Input Output Operation. Step3. Files can be opened for reading.2010 .  All files described as explained above should be first opened to do read/write operations. 01 WS-FST1 PIC X(2). The record attached to the concerned file alone can be used to write into the file.com Page 44 date:16. ACCEPT CUST-NO ACCEPT CUST-DEPT DD1 www. F1. FD CUSTOMER-FILE RECORD CONTAINS 80 CHARACTERS DATA RECORD IS CUSTOMER-RECORD.  Describe the File with detail like record name . WORKING-STORAGE SECTION. EXAMPLE IDENTIFICATION DIVISION.  SYNTAX : If we have to write in to a file WRITE command is used in procedure Division.record structure in the File Section of DATA DIVISION .

mainframe230. 200-CLOSE-PARA.blogspot.05. www.2010 . CLOSE CUSTOMER-FILE DISPLAY 'CLOSE FILE STATUS:-' WS-FST1 STOP RUN.com Page 45 date:16.COBOL Training ACCEPT CUST-DTLS WRITE CUSTOMER-RECORD DISPLAY 'WRITE FILE STATUS:-' WS-FST1.

COBOL Training 7.blogspot.com Page 46 date:16.2010 .05.5. SELECT STATEMENT Sequential files: >>──SELECT──┬──────────┬──file-name-1──ASSIGN───┬────┬────assignment-name-1────────> └─OPTIONAL─┘ └─TO─┘ >──┬──────────────────────────────────────┬───────────────────> └─┬──────────────────────┬──SEQUENTIAL─┘ └─ORGANIZATION──┬────┬─┘ └─IS─┘ >──┬──────────────────────────────────────┬────────────────────────────────────────> └─ACCESS──┬──────┬──┬────┬──SEQUENTIAL─┘ └─MODE─┘ └─IS─┘ >──┬────────────────────────────────────────────────────────┬─────────────────────>< └─┬──────┬──STATUS──┬────┬──data-name-1──────────────────┘ └─FILE─┘ └─IS─┘ Indexed File >>──SELECT──┬──────────┬──file-name-1──ASSIGN───┬────┬────assignment-name-1─────────────> └─OPTIONAL─┘ └─TO─┘ >──┬──────────────────────┬──INDEXED──────────────────────────> └─ORGANIZATION──┬────┬─┘ └─IS─┘ >──┬──────────────────────────────────────────┬─────────────────────────────────────────> └─ACCESS──┬──────┬──┬────┬──┬─SEQUENTIAL─┬─┘ └─MODE─┘ └─IS─┘ ├─RANDOM─────┤ └─DYNAMIC────┘ >──RECORD──┬─────┬──┬────┬──data-name-2──┬─────────────────────────────────────┬────────> └─KEY─┘ └─IS─┘ └─ PASSWORD ──┬──────┬── data-name-6 ─┘ └─ IS ─┘ <─────────────────┐ >────┬─────────────┬─┴──┬────────────────────────────────────────────────────────┬──────>< └─┤ entry 1 ├─┘ └─┬──────┬──STATUS──┬────┬──data-name-1──────────────────┘ └─FILE─┘ └─IS─┘ entry 1: (3) ├──ALTERNATE RECORD─────┬─────┬──┬────┬──data-name-3──┬──────────────────────┬───────────> └─KEY─┘ └─IS─┘ └─┬──────┬──DUPLICATES─┘ └─WITH─┘ www.mainframe230.

COBOL Training

Relative files
>>──SELECT──┬──────────┬──file-name-1──ASSIGN───┬────┬────assignment-name-1─────────────> └─OPTIONAL─┘ └─TO─┘ >───┬──────────────────────┬──RELATIVE─────────────────────────> └─ORGANIZATION──┬────┬─┘ └─IS─┘ >─┬──────────────────────────────────────────────────────────────────────────────────┬─> └─ACCESS─┬──────┬─┬────┬─┬─SEQUENTIAL──┬───────────────────────────────────────┬─┬─┘ └─MODE─┘ └─IS─┘ │ └─RELATIVE──┬─────┬─┬────┬──data-name-4─┘ │ │ └─KEY─┘ └─IS─┘ │ └─┬─RANDOM──┬──RELATIVE──┬─────┬─┬────┬──data-name-4────┘ └─DYNAMIC─┘ └─KEY─┘ └─IS─┘ >──┬───────────────────────────────────────────────────────┬──────────────────────────>< └─┬──────┬──STATUS──┬────┬──data-name-1─────────────────┘ └─FILE─┘ └─IS─┘

Assignment Name ties the select statement to the DDNAME in the JCL QSAM file >>────┬─────┬──name──────────────────────────────────────>< └─S- ─┘ VSAM Sequential File >>────AS- ──name─────────────────────────────────────────>< VSAM Indexed or Relative File >>────name───────────────────────────────────────────────><

7.5.1. ORGANIZATION CLAUSE
This clause should appear in Environment division. We can choose File Organization SEQUENTIAL -This Option is to handle a PS data set or VSAM ESDS . Once the file is organized as Sequential records can be placed as first come first served basis. INDEXED - This Option is to handle a VSAM KSDS . There should be a key field to choose this operating mode. This is called primary key and is to be unique like ROLLNO, EMPLYEENO. RELATIVE - This Option is to handle a VSAM RRDS . Record Numbers are identifying the records to access.

7.5.2. ACCESS MODE CLAUSE
This clause should appear in the access mode statement of Environment division. Files can be accessed in different modes based on the type of Organization.

www.mainframe230.blogspot.com

Page 47

date:16.05.2010

COBOL Training We can choose access mode depending on the order in which we like it to be accessed. Sequential Access Mode will facilitate to access any file records in sequential order. Random Access Mode will facilitate to access a particular record of an Indexed File / Relative File by supplying the Record key before read / write operation. Dynamic Access Mode will facilitate to access a particular record or in sequential order from an Indexed File / Relative File We give below all possible access modes on organization. Seq. access Organization Sequential Relative Indexed Order of write Ascending rel rec. no Ascending key value Invalid Value of rel key Value of rel key Invalid Seq. or random Seq. or random Random access Dynamic access

7.5.3. RECORD KEY PHRASE
This Phrase is to be defined in the Environment Division and essential when the file is an Indexed File. This key is to be Unique and is to be a part of the Indexed record.

7.5.4. ALTERNATE KEY PHRASE
This Phrase is to be defined in the Environment Division when we want to access record in the order of some other Key apart from primary key. This key need not be unique but to be a part of the record.

7.6. FD ENTRY
Syntax Sequential Files
>>──FD──file-name-1─────────────────────────────────────────────────────────> >──┬───────────────────────────────────────────────────────────────────┬────> └─BLOCK──┬──────────┬──┬───────────────┬──integer-2──┬─CHARACTERS─┬─┘ └─CONTAINS─┘ └─integer-1──TO─┘ └─RECORDS────┘ >──┬────────────────────────────────────────────────────────────────────┬───> └─RECORD──┬─┬──────────┬──integer-3──┬────────────┬────────────────┬─┘ │ └─CONTAINS─┘ └─CHARACTERS─┘ │ ├─┬──────────┬──integer-4──TO──integer-5──┬────────────┬─┤ │ └─CONTAINS─┘ └─CHARACTERS─┘ │ └─┤ clause 1 ├──┬────────────────────────────────┬───────┘ └─DEPENDING──┬────┬──data-name-1─┘ └─ON─┘ >──┬──────────────────────────────────────────────────────┬────────────────> └─LABEL───RECORD──┬────┬─────┬─STANDARD──────────────┬─┘ └─IS─┘ └─OMITTED───────────────┘ >──┬─────────────────────────────────────────────┬───────────────────────────> │ <─────────────┐ │ └─DATA──┬─RECORD──┬────┬───┬────data-name-4─┴─┘ │ └─IS─┘ │ └─RECORDS──┬─────┬─┘

www.mainframe230.blogspot.com

Page 48

date:16.05.2010

COBOL Training
└─ARE─┘ >──┬───────────────────────────────────────────┬─────────────────────────────> └─ RECORDING ──┬────────┬──┬──────┬── mode ─┘ └─ MODE ─┘ └─ IS ─┘ clause 1: ├──┬────┬──VARYING──┬────┬──┬──────┬──┬─────────────────────┬────────────────> └─IS─┘ └─IN─┘ └─SIZE─┘ └─┬──────┬──integer-6─┘ └─FROM─┘ >──┬───────────────┬──┬────────────┬───────────────────────────────────────── └─TO──integer-7─┘ └─CHARACTERS─┘

Indexed and Relative files
>>──FD──file-name-1─────────────────────────────────────────────────────────> >──┬───────────────────────────────────────────────────────────────────┬────> └─BLOCK──┬──────────┬──┬───────────────┬──integer-2──┬─CHARACTERS─┬─┘ └─CONTAINS─┘ └─integer-1──TO─┘ └─RECORDS────┘ >──┬────────────────────────────────────────────────────────────────────┬───> └─RECORD──┬─┬──────────┬──integer-3──┬────────────┬────────────────┬─┘ │ └─CONTAINS─┘ └─CHARACTERS─┘ │ ├─┬──────────┬──integer-4──TO──integer-5──┬────────────┬─┤ │ └─CONTAINS─┘ └─CHARACTERS─┘ │ └─┤ clause 1 ├──┬────────────────────────────────┬───────┘ └─DEPENDING──┬────┬──data-name-1─┘ └─ON─┘ >──┬───────────────────────────────────────────┬────────────────────────────> └─LABEL──┬─RECORD──┬────┬───┬──┬─STANDARD─┬─┘ │ └─IS─┘ │ └─OMITTED──┘ └─RECORDS──┬─────┬─┘ └─ARE─┘ >──┬─────────────────────────────────────────────┬──.──────────────────────>< │ <─────────────┐ │ └─DATA──┬─RECORD──┬────┬───┬────data-name-4─┴─┘ │ └─IS─┘ │ └─RECORDS──┬─────┬─┘ └─ARE─┘ clause 1: ├──┬────┬──VARYING──┬────┬──┬──────┬──┬─────────────────────┬───────────────> └─IS─┘ └─IN─┘ └─SIZE─┘ └─┬──────┬──integer-6─┘ └─FROM─┘ >──┬───────────────┬──┬────────────┬────────────────────────────────────────┤ └─TO──integer-7─┘ └─CHARACTERS─┘

7.6.1. BLOCK CONTAINS / RECORD CONTAINS PHRASE
We can specify the length of the file record in this Clause in terms of Characters this is to be specified in Data Division. We can specify the number of characters / records contains in a Block.

www.mainframe230.blogspot.com

Page 49

date:16.05.2010

COBOL Training

7.6.2. RECORDING MODE CLAUSE
This Phrase is to be defined in the File section Data division. When the file is with Fixed length record is chosen as F. This key represents s only the record Number. RECORDING MODE [F] [V].

F => Fixed which Indicates that every record of same length Example:
FD file-name BLOCK CONTAINS 500 CHARACTERS. RECORD CONTAINS 50 CHARACTERS. DATA-RECORD IS EMP-RECORD. EMP-RECORD 01 EMPNO PIC X(6). 02 EMP-NAME PIC X(30). 02 BASIC PIC 9(5). 02 HRA PIC 9(5). 02 DA PIC 9(4).

The above record is of length 50 characters. V => Variable which Indicates that record length may vary from I1 to I2. Example:
FD BLOCK CONTAINS 320 THRU 640 CHARACTERS. RECORD CONTAINS 32 THRU 64 CHARACTERS. DATA RECORD IS MARK-RECORD. 01 MARK-RECORD 02 P1 PIC 99. 02 MARKS OCCURS 10 THRU 20 Depending P1 03 SCORE PIC 999.

The above record length is based on P1.

7.7. INPUT / OUTPUT STATEMENTS
Open statement can be used for opening the file with different mode. OPEN OUTPUT file-name connects data set to your COBOL program to write records when the file is even with out a single record.. OPEN INPUT file-name connects data set to your COBOL program to records from the first . OPEN EXTEND file-name connects data set to your COBOL program for writing new records in an existing non empty file. OPEN I-O file-name connects data set to your COBOL program for processing to do read/write /Rewrite.

www.mainframe230.blogspot.com

Page 50

date:16.05.2010

05. it positions the current record pointer.blogspot.2010 .COBOL Training WRITE >>──WRITE──record-name-1──┬────────────────────┬────────────────> │ │ └─FROM──identifier-1─┘ ├──┬────────────────────────────────────────────────┬───────────────┤ └─ INVALID ──┬───────┬── imperative-statement-1 ─┘ └─ KEY ─┘ ├──┬────────────────────────────────────────────────────┬───────────┤ └─ NOT INVALID ──┬───────┬── imperative-statement-2 ─┘ └─ KEY ─┘ Add records to a file or load a file .com Page 51 date:16. When this command is used in an Indexed file key must be newer one always. START .mainframe230. READ Sequential Retreival >>──READ──file-name-1──┬───────────────┬──┬────────┬─────────────────> └─NEXT──────────┘ └─RECORD─┘ >──┬────────────────────┬────────────────────────────────────────────> www.Establish the current location in the cluster for a READ NEXT statement >>──START──file-name-1───────────────────────────────────────────────────────────> >──┬────────────────────────────────────────────────────────────────────────┬────> └─KEY──┬────┬──┬─EQUAL──┬────┬────────────────────────────┬──data-name-1─┘ └─IS─┘ │ └─TO─┘ │ ├─=────────────────────────────────────────┤ ├─ LESS ──┬────────┬───────────────────────┤ │ └─ THAN ─┘ │ ├─ < ──────────────────────────────────────┤ ├─GREATER──┬──────┬────────────────────────┤ │ └─THAN─┘ │ ├─>────────────────────────────────────────┤ ├─NOT LESS──┬──────┬───────────────────────┤ │ └─THAN─┘ │ ├─NOT <────────────────────────────────────┤ ├─ NOT GREATER ──┬────────┬────────────────┤ │ └─ THAN ─┘ │ ├─ NOT > ──────────────────────────────────┤ ├─ LESS ──┬────────┬── OR EQUAL ──┬──────┬─┤ │ └─ THAN ─┘ └─ TO ─┘ │ ├─ <= ─────────────────────────────────────┤ ├─GREATER──┬──────┬──OR EQUAL──┬────┬──────┤ │ └─THAN─┘ └─TO─┘ │ └─>=───────────────────────────────────────┘ >──┬──────────────────────────────────────────┬──────────────────────────────────> └─INVALID──┬─────┬──imperative-statement-1─┘ └─KEY─┘ >──┬──────────────────────────────────────────────┬──┬───────────┬───────────────>< └─NOT INVALID──┬─────┬──imperative-statement-2─┘ └─END-START─┘ └─KEY─┘ START does not retrieve a record.

DELETE >>──DELETE──file-name-1──┬────────┬──────────────────────────────────> └─RECORD─┘ >──┬──────────────────────────────────────────┬──────────────────────> www. If it used to read from an Indexed/Relative file it would read the corresponding key record. the key field must have a value before read.mainframe230.2010 .COBOL Training └─INTO──identifier-1─┘ >──┬─────────────────────────────────────┬───────────────────────────> └─┬────┬──END──imperative-statement-1─┘ └─AT─┘ >──┬──────────────────────────────────────────┬──┬──────────┬───────>< └─NOT──┬────┬──END──imperative-statement-2─┘ └─END-READ─┘ └─AT─┘ Random Retreival >>──READ──file-name-1──┬────────┬──┬────────────────────┬────────────> └─RECORD─┘ └─INTO──identifier-1─┘ >──┬──────────────────────────┬──────────────────────────────────────> └─KEY──┬────┬──data-name-1─┘ └─IS─┘ >──┬──────────────────────────────────────────┬──────────────────────> └─INVALID──┬─────┬──imperative-statement-3─┘ └─KEY─┘ >──┬──────────────────────────────────────────────┬──┬──────────┬───>< └─NOT INVALID──┬─────┬──imperative-statement-4─┘ └─END-READ─┘ └─KEY─┘ The READ statement is used to read a record from a file.05.blogspot. Files must be opened in I-O mode.com Page 52 date:16. If it is used to read a sequential file it will read the next record always. If we have read sequentially from an Indexed file READ NEXT RECORD will retrieve records from a file in sequence REWRITE >>──REWRITE──record-name-1──┬────────────────────┬───────────────────> └─FROM──identifier-1─┘ >──┬──────────────────────────────────────────┬──────────────────────> └─INVALID──┬─────┬──imperative-statement-1─┘ └─KEY─┘ >──┬──────────────────────────────────────────────┬──────────────────> └─NOT INVALID──┬─────┬──imperative-statement-2─┘ └─KEY─┘ >──┬─────────────┬──────────────────────────────────────────────────>< └─END-REWRITE─┘ Used for Updating records.

Not permitted for ESDS and PS files. File must be opened in I-O mode.COBOL Training └─INVALID──┬─────┬──imperative-statement-1─┘ └─KEY─┘ >──┬──────────────────────────────────────────────┬──────────────────> └─NOT INVALID──┬─────┬──imperative-statement-2─┘ └─KEY─┘ >──┬────────────┬───────────────────────────────────────────────────>< └─END-DELETE─┘ Remove records from indexed and relative files only.mainframe230.2010 .com Page 53 date:16. CLOSE Disconnect the VSAM data set from your program >>──CLOSE────file-name-1────────>< www.blogspot.05.

com Page 54 date:16. changing their lengths in place For variable .blogspot.05.2010 . retrieve and delete datasets.sequenced Key . distributed free space is used for adding records and changing their lengths in place A record cannot be deleted but Space given up by a deleted or Space given up by a deleted record can you can reuse its space for a shortened record is be reused record of the same length automatically reclaimed within a control interval Can have spanned records Can be reused as a work file unless it has an alternate index associated with key ranges or exceeds 123 extents per volume can have spanned records can be reused unless it has an associated with exceeds 123 volume Can be reused as a work file as a work file can be reused as work file alternate index key ranges or extents per www.mainframe230. VSAM DATA SET VSAM – Virtual Storage Access Method VSAM is high performance access method used to organize. or more May not have alternate indexes A record relative record number cannot change A record’s RBA cannot change A record RBA can change Space at the end of the data Distributed free space is used for fixed length RRDS empty slots in the set is used for adding records for inserting record and data set are used for adding records. VSAM supports 5 dataset organizations.sequenced Relative .length RRDS. store. index which is treated like a key more May have one alternate indexes.Record Records are in order in which Records are in collating Records are in relative record number they are written sequence by key field order Access is sequential May have one alternate indexes or Access is by key through an Access is by relative record number. COMPARISON ON VSAM DATASETS Entry . catalog.COBOL Training 7.      Key-Sequenced Data Set (KSDS) Entry-Sequenced Data Set (ESDS) Fixed-Length Relative Record Data Set (RRDS) Variable-Length RRDS (VRRDS) Linear Data Set (LDS) The Primary difference of the above types is the way in which their records are stored and retrieved.8.

1.mainframe230.8.blogspot.1.8. Access Yes Yes Yes Ran.for VSAM sequential files (ESDS) ORGANIZATION IS INDEXED ORGANIZATION IS RELATIVE . VSAM DATASETS AND ACCESS MODES File Organization VSAM sequential (ESDS) VSAM indexed (KSDS) VSAM Relative (RRDS) Seq.for VSAM indexed files (KSDS) . Access Fixed Length Yes Yes Yes Variable Length Yes Yes NO 7. 7.2.com Page 55 date:16. Access No Yes Yes No Yes Yes Dyna.VSAM Relative File SELECT R-FILE ASSIGN TO INFILE ORGANIZATION IS RELATIVE ACCESS IS RANDOM RELATIVE KEY IS RFILE-RELATIVE-KEY FILE STATUS KEY IS FSTAT-CODE VSTAT-CODE www.05. ORGANIZATION CLAUSE ORGANIZATION IS SEQUENTIAL .2010 . ENVIRONMENT DIVISION ENTRIES FOR VSAM FILES Example :VSAM Sequential File SELECT S-FILE ASSIGN TO AS-INFILE ORGANIZATION IS SEQUENTIAL ACCESS IS SEQUENTIAL FILE STATUS KEY IS FSTAT-CODE VSTAT-CODE Note the prefix of AS.8.for VSAM relative files (RRDS).1.COBOL Training 7.for a VSAM ESDS file Example :VSAM Indexed File SELECT I-FILE ASSIGN TO INFILE ORGANIZATION IS INDEXED ACCESS IS DYNAMIC RECORD KEY IS IFILE-RECORD-KEY ALTERNATE RECORD KEY IS IFILE-ALTREC-KEY FILE STATUS KEY IS FSTAT-CODE VSTAT-CODE Example:.

3.8.mainframe230. COBOL STATEMENTS USABLE WITH SEQUENTIAL FILES Access Mode Sequential COBOL / 370 Statement OPEN WRITE START READ REWRITE DELETE CLOSE X X X X X X X OPEN INPUT X OPEN OUTPUT X X OPEN I-O X OPEN EXTEND X X 7.8.com Page 56 date:16.COBOL Training 7.2010 .4. COBOL STATEMENTS WITH INDEXED FILES (KSDS) AND RELATIVE (RRDS) www.05.blogspot.

com Page 57 date:16.mainframe230.05.2010 .blogspot.COBOL Training Access Mode Sequential COBOL/370St atement OPEN WRITE START READ REWRITE DELETE CLOSE OPEN INPUT X OPEN OUTPUT X X OPEN I-O X OPEN EXTEND X X x X x X X x X X X X Random OPEN WRITE START READ REWRITE DELETE CLOSE X X X X X X X X X X X X Dynamic OPEN WRITE START READ REWRITE DELETE CLOSE X X X X X X X X X X X X X X www.

COBOL Training www.mainframe230.05.com Page 58 date:16.blogspot.2010 .

05.2010 .O READ NEXT Not Applicable WRITE REWRITE DELETE CLOSE RRDS ACCESS IS SEQUENTIAL OPEN EXTEND WRITE CLOSE OPEN I-O READ REWRITE DELETE CLOSE ACCESS IS RANDOM OPEN I-O READ WRITE REWRITE DELETE CLOSE ACCESS IS DYNAMIC Sequential processing OPEN I-O READ NEXT WRITE REWRITE DELETE CLOSE ACCESS IS DYNAMIC Random processing OPEN I .COBOL Training 7.mainframe230.blogspot. PROCEDURE DIVISION STATEMENTS TO UPDATE VSAM FILES ESDS ACCESS IS SEQUENTIAL OPEN EXTEND WRITE CLOSE OPEN I-O READ REWRITE CLOSE ACCESS IS RANDOM KSDS ACCESS IS SEQUENTIAL OPEN EXTEND WRITE CLOSE OPEN I-O READ REWRITE DELETE CLOSE ACCESS IS RANDOM OPEN I-O READ Not Applicable WRITE REWRITE DELETE CLOSE ACCESS IS DYNAMIC Sequential processing ACCESS IS DYNAMIC Sequential processing OPEN I-O READ NEXT Not Applicable WRITE REWRITE DELETE CLOSE ACCESS IS DYNAMIC Random processing ACCESS IS DYNAMIC Random processing OPEN I .O READ NEXT WRITE REWRITE DELETE CLOSE www.5.com Page 59 date:16.8.

7. ESDS Applications that require sequential access only.6.COBOL Training 7.com Page 60 date:16.8.2.3.05.of . Example : BANK ACCOUNT TRANSACTIONS.7. www. 7.file . RRDS Applications that require only Direct Access. Applications that use High Level Languages which do not support RBA (Relative Byte Address) Applications that require ALTERNATE KEY to access any record .8. The FILE STATUS clause (file status key and VSAM return code) can be used in ENVIRONMENT DIVISION to trap standard errors in all FILE Handling The INVALID KEY phrase can be used to trap the errors while COBOL reads a record at random.mainframe230. While file is read sequentially AT END CLAUSE is to be used to know whether a record is read.7.8.phrase (AT END) available. Applications that require that each record have a key field.7. Example : Payroll Processing. ERROR PROCESSING FOR VSAM The end . APPLICATIONS BEST SUITED TO VSAM DATASETS 7. Applications that have one to one correspondence between records.8.7.8.blogspot. KSDS Applications that require that each record have a key field and require both direct and sequential access.2010 . The EXCEPTION / ERROR declarative statement can be used to trap the errors in any I/O handling. 7.1.

mainframe230. Edit routines Error control checks Standard calculations Summary. When the called program is completed. stored in library to be called when needed.05. debugged. Called program may itself call yet another program. SUBPROGRAMS      Compiled. The program that calls another program is referred to as the Calling program and the program it calls is referred to as the Called program (subprogram).com Page 61 date:16.COBOL Training 8. the program can either transfer control back to the calling program or end the run unit. No specific source code statements or options identify a COBOL program to be a main program or a subprogram.2010 .blogspot. total printing Typical subprograms include:     Advantages of Subprograms      Avoids duplication of effort Improves programmer productivity Provides greater flexibility Changes to called program can be made without modifying calling program Results in greater standardization Calling and Called Programs www.

2010 .blogspot.. You can use GOBACK instead of EXIT PROGRAM.mainframe230. Value clause may not be specified for items other than level ..88 items Example: IDENTIFICATION DIVISION PROGRAM-ID.1. LINKAGE SECTION Describes data made available from another program Storage for data items within the program is not reserved because the data area exists elsewhere... Control returns to calling program 3.. . PROCEDURE DIVISION . Subprogram Sub1 called and executed in its entirety 2. www. IDENTIFICATION DIVISION PROGRAM-ID. ABC.com Page 62 date:16. CALL XYZ USING A B STOP RUN. Subprogram Sub2 called and executed in its entirety 4. Control returns to calling program 5.. EXIT PROGRAM.COBOL Training 1..05. 8. XYZ LINKAGE SECTION 01 PARAM1 PIC X(05) 01 PARAM2 PIC 9(5) PROCEDURE DIVISION USING PARAM1 PARAM2 .

10 SALES PIC 9(5). CALL BY REFERENCE OR BY CONTENT.05. BY CONTENT identifier. When a COBOL / 370 program returns to its caller. . If you want to pass both item and its length to a subprogram.LIST In the calling program the code for parts (PARTCODE) and the number (PARTNO) are referred to separately In the called program.mainframe230. 01 PARAM-LIST. PROCEDURE DIVISION CALL CALLED–PROG USING PARAM. BY CONTENT LENGTH OF Identifier. .SALES PIC 9(5).1. PASSING RETURN CODE INFORMATION You can use the RETURN-CODE special register to pass and receive return codes between programs.1.1.2. the code for parts and the part number are combined into one data item (PART-ID ). 10 PART-ID PIC X(5). 05 U . the contents of the RETURN-CODE special register contains the return code of the called program. .com Page 63 date:16. STATIC / DYNAMIC CALLS To transfer control from one COBOL program to another COBOL program you can use one of these methods: STATIC CALL The Compiler treats the CALL Literal statement (Where literal is the name of a subprogram) as a static call when the NODYNAM compiler option is in effect.1. specify : CALL . DYNAMIC CALL A dynamic call loads the subprograms at run time.2010 . Note that the compiler option DYNAM can change a static call to a dynamic call.1. 8. specify a combination of BY REFERENCE and BY CONTENT Example:CALL ‘ ERRPROC’ USING BY REFERENCE A BY CONTENT LENGTH OF A Common Data Items in Subprogram Linkage Calling Program Description WORKING-STORAGE SECTION.1.COBOL Training 8. specify CALL .blogspot. www. . 05 PARTNO PIC X(4). If you want to pass a literal value to a called program. PROCEDURE DIVISION USING L-PARAM 8. In the called program a reference to PART-ID is the valid reference to them Called Program Description LINKAGE SECTION. 05 PARTCODE PIC A. If you want to pass an identifier’s value only to a called program. 01 L-PARAM.

When control is returned from a COBOL program to the operating system.mainframe230.com Page 64 date:16. the contents of register 15 are stored into the calling program ‘s RETURN .blogspot. the special register contents are returned as a user return code.CODE special register. www.COBOL Training When control is returned to a COBOL program from a call.2010 .05.

It should be an integer data item with enough picture clause to hold the count It should be initialized to 1. STRING STATEMENT String statement strings together the partial or complete contents of two or more DATA ITEMS or LITERALS into one single data item.mainframe230.com Page 65 date:16. www. INTO represents the receiving field POINTER represents pointer field which represents the last character position in the receiving field.05. UNSTRING AND INSPECT STATEMENTS 9.blogspot.2010 .COBOL Training 9. It will return the length of the received data plus 1. FORMAT : >>──STRING───────────────────────────────────────────────────────────> <───────────────────────────────────────────────────────────┐ <──────────────────┐ │ >──────┬─identifier-1─┬─┴──DELIMITED──┬────┬──┬─identifier-2─┬─┴─────> └─literal-1────┘ └─BY─┘ ├─literal-2────┤ └─SIZE─────────┘ >──INTO──identifier-3──┬─────────────────────────────────┬───────────> └─┬──────┬──POINTER──identifier-4─┘ └─WITH─┘ >──┬──────────────────────────────────────────┬──────────────────────> └─┬────┬──OVERFLOW──imperative-statement-1─┘ └─ON─┘ >──┬───────────────────────────────────────────────┬─────────────────> └─NOT──┬────┬──OVERFLOW──imperative-statement-2─┘ └─ON─┘ >──┬────────────┬───────────────────────────────────────────────────>< └─END-STRING─┘ Identifiers should be with USAGE clause DISPLAY should not be with picture clause LITERALS should be non numeric literals / figurative constant except ALL (considers a character non numeric for figurative constant) THRU (all) should not be with P picture Identifiers 1 are sending fields.1. identifier 2 is the delimiting field and Identifiers 3 is the receiving field DELIMITED BY phrase is used to delimit the pieces of data to be extracted from each input identifier and transferred SIZE sends the complete sending area. STRING.

ENVIRONMENT DIVISION. PROCESS-PARA. PERFORM PROCESS-PARA PERFORM END-PARA. 01 ID1 PIC X(5) VALUE "AB.05.CD".2010 . 01 ID5 PIC X(100). www. END-PARA. 01 STR-COUNT PIC 999 VALUE 1.2. DATA DIVISION. 01 ID3 PIC X(5) VALUE "IJK#L". 01 ID2 PIC X(5) VALUE "E. PROGRAM-ID. Output is AB/E/IJK/MN 012 9. UNSTRING STATEMENT >>──UNSTRING──identifier-1─────────────────────────────────────────────────────────────────────> >──┬─────────────────────────────────────────────────────────────────────────────────────┬─────> └─DELIMITED──┬────┬──┬─────┬──┬─identifier-2─┬──┬───────────────────────────────────┬─┘ └─BY─┘ └─ALL─┘ └─literal-1────┘ │ <───────────────────────────────┐ │ └───OR──┬─────┬──┬─identifier-3─┬─┴─┘ └─ALL─┘ └─literal-2────┘ >──INTO────────────────────────────────────────────────────────────────────────────────────────> <────────────────────────────────────────────────────────────────────────────────────┐ >────identifier-4──┬─────────────────────────────────┬──┬─────────────────────────────┬─┴──────> └─DELIMITER──┬────┬──identifier-5─┘ └─COUNT──┬────┬──identifier-6─┘ └─IN─┘ └─IN─┘ >──┬─────────────────────────────────┬──┬────────────────────────────────┬─────────────────────> └─┬──────┬──POINTER──identifier-7─┘ └─TALLYING──┬────┬──identifier-8─┘ └─WITH─┘ └─IN─┘ >──┬──────────────────────────────────────────┬────────────────────────────────────────────────> └─┬────┬──OVERFLOW──imperative-statement-1─┘ └─ON─┘ >──┬───────────────────────────────────────────────┬──┬──────────────┬────────────────────────>< └─NOT──┬────┬──OVERFLOW──imperative-statement-2─┘ └─END-UNSTRING─┘ └─ON─┘ Unstring statement causes contiguous data in a Sending Field to be separated and placed into multiple receiving fields.FGH". 01 ID4 PIC X(5) VALUE "MN#OP". STRPGM.com Page 66 date:16. STRING ID1 "/" ID2 DELIMITED BY ".mainframe230.COBOL Training OVERFLOW executed when pointer is < 1 or > the picture length of the receiving field IDENTIFICATION DIVISION.blogspot. WORKING-STORAGE SECTION. STOP RUN." "/" ID3 "/" ID4 DELIMITED BY "#" INTO ID5 WITH POINTER STR-COUNT DISPLAY ID5 DISPLAY STR-COUNT. PROCEDURE DIVISION.

SPACES. ". All data receiving fields have been acted upon and the sending still contain the unexamined character. INTO represents the receiving field POINTER contains a value that indicates a relative position in the sending field. STRPGM. WORKING-STORAGE SECTION. IDENTIFICATION DIVISION. 5)For each instance of identifier 4 you can have a identifier 6 that is set with the count of bytes in identifier 4 except the delimiter. 0. 01 ID1 PIC X(9) VALUE 01 ID1-D PIC X VALUE 01 ID1-C PIC 9 VALUE 01 ID2 PIC X(9) VALUE 01 ID2-D PIC X VALUE 01 ID2-C PIC 9 VALUE 01 ID3 PIC X(9) VALUE 01 ID3-D PIC X VALUE 01 ID3-C PIC 9 VALUE SPACES.COBOL Training How to interpret the above diagram:1)Identifier 1 is the sending field 2)Pieces of the identifier 1 delimited by either identifier 2 or 3 are extracted and sent to the receiving fields which are identifier 4 . 0.05. OVER FLOW executed when pointer is < 1 or > the picture length of the receiving field TALLYING in this count field is increased by the number of data receiving fields acted upon execution.mainframe230. PROGRAM-ID. Represents the sending field. "IJK#L".com Page 67 date:16. ENVIRONMENT DIVISION. DATA DIVISION.2010 . 3)Each instance of identifier 4 holds a piece 4)For each instance of identifier 4 you can have a identifier 5 that is set with the delimiter. 6)The pointer identifier 7 is set to the number of bytes examined in the sending field plus 1 7)Identifier 8 is set to the number of receiving data areas that were acted upon. SIZE sends the complete sending area. It should be initialized to 1 It will return the length of the received data plus 1. "@".". DELIMITED BY phrase is used to limit the data to be transferred .blogspot. "#". Restrictions Identifiers should be with USAGE clause DISPLAY should not be with P picture LITERALS should be non numeric literals/figurative constant except ALL (considers a character non numeric for figurative constant) Identifier1 must be an alphanumeric item May not be reference modified. www. 0.

". 02 PARM-D PIC X(100). www.ID2-C:-5 ID3-D:-*ID3-C:-4 ID4-C:-5 9. PROCESS-PARA.com Page 68 date:16. UNSTRING PARM-D DELIMITED BY DE-ID OR ALL "*" INTO ID1 DELIMITER IN ID1-D COUNT IN ID1-C ID2 DELIMITER IN ID2-D COUNT IN ID2-C ID3 DELIMITER IN ID3-D COUNT IN ID3-C ID4 COUNT IN ID4-C WITH POINTER ID-P TALLYING IN ID-T ON OVERFLOW PERFORM FLOW-EXIT-PARA END-UNSTRING DISPLAY "ID1:-" ID1 "ID1-D:-" ID1-D "ID1-C:-" ID1-C DISPLAY "ID2:-" ID2 "ID2-D:-" ID2-D "ID2-C:-" ID2-C DISPLAY "ID3:-" ID3 "ID3-D:-" ID3-D "ID3-C:-" ID3-C DISPLAY "ID4:-" ID4 "ID4-C:-" ID4-C DISPLAY "ID-P:-" ID-P DISPLAY "ID-T:-" ID-T. 01 JCL-PARM.3.2010 .mainframe230. DISPLAY "FLOW-EXIT-PARA EXECUTED". 01 ID-T PIC 999 VALUE 0. 02 PARM-L PIC S9(4) COMP. END-PARA. 01 ID-P PIC 999 VALUE 1. FLOW-EXIT-PARA. PERFORM PROCESS-PARA PERFORM END-PARA. 01 DE-ID PIC X VALUE ". 01 ID4-C PIC 9 VALUE 0. PROCEDURE DIVISION USING JCL-PARM. LINKAGE SECTION.ID1-C:-2 ID2-D:-.blogspot. INSPECT STATEMENT This statement specifies that characters or group of characters in a data item are to be counted or (tallied) or replaced or both. STOP RUN. OUTPUT ID1:-AB ID2:-EFGHI ID3:-PQRS ID4:-GH ID-P:-101 ID-T:-004 ID1-D:-.COBOL Training 01 ID4 PIC X(9) VALUE SPACES.05.

INSPECT ITEM-1 TALLYING C2 FOR ALL CHARACTERS. FORMAT1: >>──INSPECT──identifier-1──TALLYING─────────────────────────────────────────────────────> <───────────────────────────────────────────────────────────────────────────────────┐ <────────────────────────────────────────────────────────────┐ │ <──────────────────┐ │ │ >────identifier-2──FOR────┬─CHARACTERS────┬──────────────┬─┴───────────────────────┬─┴─┴>< │ └─┤ phrase 1 ├─┘ │ │ <───────────────────────────────────────┐ │ │ <──────────────────┐ │ │ └─┬─ALL─────┬────┬─identifier-3─┬───┬──────────────┬─┴─┴─┘ └─LEADING─┘ └─literal-1────┘ └─┤ phrase 1 ├─┘ phrase 1: ├──┬─BEFORE─┬──┬─────────┬──┬─identifier-4─┬─────────────────────────────────────────────┤ └─AFTER──┘ └─INITIAL─┘ └─literal-2────┘ Example: INSPECT ITEM-1 TALLYING C1 FOR ALL SPACES. It will convert all occurrences of specific characters in a data item to user supplied replacement characters.2010 . INSPECT ITEM-1 TALLYING C3 FOR LEADING SPACES. NUMERIC OR SPECIAL CHARACTER) It will fill all portions of data item with specified characters such as spaces or zeroes. FORMAT 2: >>--INSPECT--identifier-1--REPLACING------------------------------------------------> <-----------------------------------------------------------------------------+ <------------------+ ¦ >------CHARACTERS BY----identifier-5------------------------------------------------>< ¦ +-literal-3----+ +-¦ phrase 1 +-+ ¦ ¦ <----------------------------------------------------------+ ¦ ¦ <--------------+ ¦ ¦ +---ALL------------identifier-3----BY----identifier-5-----------------------+ +-LEADING-¦ +-literal-1----+ +-literal-3----+ +-¦ phrase 1 +-+ +-FIRST---+ phrase 1: +----BEFORE-------------------identifier-4-------------------------------------------¦ +-AFTER--+ +-INITIAL-+ +-literal-2----+ Example: INSPECT ITEM-4 REPLACING DATA ITEM1 10-07-97 OUTPUT 20/07/97 “-“ BY “/“.2.mainframe230.05.blogspot. www.1 respectively.com Page 69 date:16. DATA ITEM1 BB56BB will yield 4 .COBOL Training It will count the occurrences of a specific character (ALPHABETIC.

COBOL Training 9. DEBUG-DECLARATIVES-PARA.mainframe230. PROCEDURE DIVISION. PARA-3. SOURCE-COMPUTER. PARA-2. DECLARATIVES. DISPLAY "TRACING:-" DEBUG-NAME. IBM-390 WITH DEBUGGING MODE. WORKING-STORAGE SECTION. It is the first Section To Be Defined in Procedure Division. The rest of the paragraphs may be placed in User defined Section. DISPLAY "IN PARA-1".4. DECLARATIVES It is used for tracing the paragraph or procedures executed by the program as per the Instruction given by the programmer.blogspot. OBJECT-COMPUTER. IBM-390. PERFORM PARA-1 PERFORM PARA-2 PERFORM PARA-3 PERFORM END-PARA.com Page 70 date:16. www. DATA DIVISION.e. DEBUG-DECLARATIVES SECTION. DISPLAY "IN PARA-2". i. PROGRAM-ID. STOP RUN. MAIN-PARA.05. This declarative section of the program will be executed before the start of execution of each paragraph defined in the program.2010 . MAIN SECTION. DISPLAY "IN PARA-3". We have to specify the Option " WITH DEBUGGING MODE" option in the SOURCE-COMPUTER The following rules should be followed. END-PARA. DEBUG-NAME is a special register storing the name of the paragraph it is executing. Make SURE you code PARM=”/DEBUG” in the EXEC JCL card before you run your program!. The Debug Declarative-paragraph should immediately follow the "USE" instruction. ENVIRONMENT DIVISION. "TRACING paraname " will be displayed before the execution of each paragraph. PARA-1. USE FOR DEBUGGING ALL PROCEDURES. DECLRPGM. IDENTIFICATION DIVISION. END DECLARATIVES. CONFIGURATION SECTION.

USING and INPUT-PROCEDURE are mutually exclusive. Each data name must identify a data item in a record associated with file-name -1 There can be any number of data names in file-name–1 and each can be either sorted in ascending or descending order. This statement can appear anywhere in the PROCEDURE DIVISION except in declarative section. data-name-1 specifies a KEY data item on which the SORT statement will be based. You specify an INPUT PROCEDURE when you want to process input records before they are RELEASED to the sort feature for sorting. If USING is specified it means that the sort feature will automatically open file name 2 (s) and read the records as input.COBOL Training 10. Duplicates are specified to place the similar records in the order they are accessed. Alphabet-name1 must be specified in the alphabet clause of SPECIAL-NAMES paragraph. If you do specify INPUT PROCEDURE it is your responsibility to open input file(s) www. SORT AND MERGE STATEMENTS SORT statement accepts records from one or more files and arranges the records in the ascending /descending order and makes the sorted records available either through an OUTPUT PROCEDURE or in an output file.com Page 71 date:16.05.2010 . The first key referred is taken as major key and the next referred is taken as the next significant key and so on Sorting in ascending order will be done from lowest key value to highest key value. FORMAT 1: <──────────────────────────────────────────────────┐ <─────────────┐ │ >>──SORT──file-name-1────┬────┬──┬─ASCENDING──┬──┬─────┬────data-name-1─┴─┴─────────> └─ON─┘ └─DESCENDING─┘ └─KEY─┘ >──┬─────────────────────────────────────────┬──────────────────────────────────────> └─┬──────┬──DUPLICATES──┬────┬──┬───────┬─┘ └─WITH─┘ └─IN─┘ └─ORDER─┘ >──┬──────────────────────────────────────────────────┬─────────────────────────────> └─┬───────────┬──SEQUENCE──┬────┬──alphabet-name-1─┘ └─COLLATING─┘ └─IS─┘ <─────────────┐ >──┬─USING────file-name-2─┴───────────────────────────────────────────────────────┬─> └─INPUT PROCEDURE──┬────┬──procedure-name-1──┬───────────────────────────────┬─┘ └─IS─┘ └─┬─THROUGH─┬──procedure-name-2─┘ └─THRU────┘ <─────────────┐ >──┬─GIVING────file-name-3─┴───────────────────────────────────────────────────────┬>< └─OUTPUT PROCEDURE──┬────┬──procedure-name-3──┬───────────────────────────────┬─┘ └─IS─┘ └─┬─THROUGH─┬──procedure-name-4─┘ └─THRU────┘           File-name -1 is the name given in the SD entry that describes the records to be sorted. Sorting in descending order will be done from highest key value to lowest key value.mainframe230.blogspot.

If you specify OUTPUT PROCEDURE. WORKING-STORAGE SECTION. If you specify USING file name 3 then the file name 3 is automatically opened by the sort feature and used as the sort output file. PROCEDURE DIVISION. 05 SORT-KEY1 PIC X(5). This Procedure can do any modifications in the record and copy Using RELEASE Statement. SD SORT-WORK-ONE RECORD CONTAINS 80 CHARACTERS DATA RECORD SORT-RECORD. MAIN-PARA. You must then RELEASE the records via RELEASE to the SORT feature. Example 2 with INPUT and OUTPUT PROCEDURES Example with USING www. END-PARA. PERFORM MAIN-PARA DISPLAY "SORT RC " SORT-RETURN PERFORM END-PARA. You must define file name 3 in the usual way. SORT1. FD INFILE RECORD CONTAINS 80 CHARACTERS BLOCK 800 RECORDING MODE IS F DATA RECORD IS INFILE-RECORD. SELECT OUTFILE ASSIGN TO OUTFILE. You do this when the INPUT PROCEDURE is driven. 01 OUTFILE-RECORD PIC X(80).     File-name-2 is the actual file to be sorted. FILE-CONTROL. SORT SORT-WORK-ONE ON ASCENDING KEY SORT-KEY2 WITH DUPLICATES IN ORDER USING INFILE GIVING OUTFILE. STOP RUN. INPUT-OUTPUT SECTION. You must define this file(s) in the standard way. 01 INFILE-RECORD PIC X(80).2010 . DATA DIVISION. The OUTPUT PROCEDURE is mutually exclusive with USING. you must open the output file and write the sorted records when the OUTPUT PROCEDURE is driven. Input-Procedure is specified to Select or Modify the Input Record before Sort. FILE SECTION. ENVIRONMENT DIVISION.com Page 72 date:16. SELECT INFILE ASSIGN TO INFILE.mainframe230. 01 SORT-RECORD. IDENTIFICATION DIVISION.COBOL Training and read the input records.blogspot. 05 SORT-DATA PIC X(70). Multiple files can specified. FD OUTFILE RECORD CONTAINS 80 CHARACTERS BLOCK 80 RECORDING MODE IS F DATA RECORD IS OUTFILE-RECORD.05. SELECT SORT-WORK-ONE ASSIGN TO SORTFILE. PROGRAM-ID. 05 SORT-KEY2 PIC X(5).

WORKING-STORAGE SECTION. 01 OUTFILE-RECORD PIC X(80). 03 WS-OUTFILE-BUFFER PIC X(80). SOURCE-COMPUTER. 05 SORT-DATA PIC X(70).com Page 73 date:16. SORT2. SELECT INFILE ASSIGN TO INFILE FILE STATUS IS INFILE-STAT. SELECT OUTFILE ASSIGN TO OUTFILE FILE STATUS IS OUTFILE-STAT.05. INPUT-OUTPUT SECTION.COBOL Training IDENTIFICATION DIVISION. CONFIGURATION SECTION. 01 INFILE-RECORD PIC X(80). 03 WS-FLAG PIC X(1) VALUE "0". IBM-390 WITH DEBUGGING MODE. PROGRAM-ID. 01 WS-VARS. PROCEDURE DIVISION. 01 SORT-RECORD.mainframe230. SELECT SORTFILE ASSIGN TO SORTFILE. 03 OUTFILE-STAT PIC X(2). ENVIRONMENT DIVISION. 03 INFILE-EOF PIC X VALUE "N". PERFORM OPEN-PARA PERFORM MAIN-PARA DISPLAY "SORT RC " SORT-RETURN PERFORM CLOSE-PARA PERFORM END-PARA. 05 SORT-KEY1 PIC X(5). 03 INFILE-STAT PIC X(2). FD OUTFILE RECORD CONTAINS 80 CHARACTERS BLOCK 80 RECORDING MODE IS F DATA RECORD IS OUTFILE-RECORD. DATA DIVISION.2010 . 03 WS-FLAG PIC X(1) VALUE "0". SD SORTFILE RECORD CONTAINS 80 CHARACTERS DATA RECORD SORT-RECORD. 05 SORT-KEY2 PIC X(5). 88 INFILEEOF VALUE "Y". FILE SECTION. FD INFILE RECORD CONTAINS 80 CHARACTERS BLOCK 800 RECORDING MODE IS F DATA RECORD IS INFILE-RECORD. 03 WS-INFILE-BUFFER PIC X(80). 88 OUTFILEEND VALUE "Y". OPEN INPUT INFILE OUTPUT OUTFILE IF INFILE-STAT NOT = "00" DISPLAY "INFILE DID NOT OPEN :" INFILE-STAT STOP RUN END-IF IF OUTFILE-STAT NOT = "00" www.blogspot. 03 OUTFILE-END PIC X VALUE "N". OPEN-PARA. FILE-CONTROL.

The sort feature will store input records you supply in sort work files until your INPUT PROCEDURE returns. As each output record (sorted) is ready your OUTPUT PROCEDURE is driven. once for each output record. MAIN-PARA. SORT-READ. SORT-RETURN-PARA.mainframe230. D DISPLAY "IN READ" READ INFILE INTO WS-INFILE-BUFFER AT END MOVE "Y" TO INFILE-EOF.05. the OUTPUT PROCEDURE is driven many times. PERFORM SORT-READ UNTIL INFILEEOF. After your INPUT PROCEDURE returns. STOP RUN. SORT-WRITE. SORT-OUTPROC. SORT SORTFILE ON ASCENDING KEY SORT-KEY2 WITH DUPLICATES IN ORDER INPUT PROCEDURE SORT-INPROC OUTPUT PROCEDURE SORT-OUTPROC. SORT-INPROC. When you have no more input you return from the INPUT PROCEDURE SORTINPROC.blogspot. MERGE The MERGE statement is a PROCEDURE DIVISION statement which merges two or more input files on some common key. Notes: In the above program the sort feature drives the SORT-INPROC (INPUT PROCEDURE) only once. END-PARA. When it is thus driven you read input records one after the other and issue the RELEASE verb to make these records available to sort. the sort feature will sort the stored input records.2010 . The merged records are then written to an output file or made available to an output procedure. CLOSE INFILE CLOSE OUTFILE. Notice that while the INPUT PROCEDURE is driven only once. www. D DISPLAY "IN OUTPROC" PERFORM SORT-WRITE UNTIL OUTFILEEND. READ-INFILE. D DISPLAY "IN SORT-RETURN" RETURN SORTFILE INTO WS-OUTFILE-BUFFER AT END MOVE "Y" TO OUTFILE-END. PERFORM READ-INFILE IF NOT INFILEEOF RELEASE SORT-RECORD FROM WS-INFILE-BUFFER. CLOSE-PARA.COBOL Training DISPLAY "OUTFILE DID NOT OPEN :" OUTFILE-STAT STOP RUN END-IF. D DISPLAY "IN SORT-WRITE" PERFORM SORT-RETURN-PARA WRITE OUTFILE-RECORD FROM WS-OUTFILE-BUFFER.com Page 74 date:16.

SELECT OUTFILE ASSIGN TO OUTFILE. IDENTIFICATION DIVISION. FILE-CONTROL. FD INFILE1 RECORD CONTAINS 80 CHARACTERS BLOCK 800 RECORDING MODE IS F Example www. INPUT-OUTPUT SECTION.2010 . 05 MERGE-KEY2 PIC X(5). 01 MERGE-RECORD.COBOL Training <──────────────────────────────────────────────────┐ <─────────────┐ │ >>──MERGE──file-name-1────┬────┬──┬─ASCENDING──┬──┬─────┬────data-name-1─┴─┴──────> └─ON─┘ └─DESCENDING─┘ └─KEY─┘ >──┬──────────────────────────────────────────────────┬──USING──file-name-2───────> └─┬───────────┬──SEQUENCE──┬────┬──alphabet-name-1─┘ └─COLLATING─┘ <─────────────┐ >────file-name-3─┴────────────────────────────────────────────────────────────────> >──┬─OUTPUT PROCEDURE──┬────┬──procedure-name1──┬───────────────────────────────┬─┬──>< │ │ │ <─────────────┐ └─IS─┘ └─┬─THROUGH─┬──procedure-name-2─┘ │ └─THRU────┘ │ │ └─IS─┘ └─GIVING────file-name-4─┴───────────────────────────────────────────────────────┘      File-name -1 is the name given in the SD entry that describes the records to be merged. File-name-2 and file-name-3 are files to be merged. 05 MERGE-DATA PIC X(70).blogspot. SELECT MERGE-WORK-ONE ASSIGN TO MERGFILE.mainframe230. MERGE1. Multiple files can specified. SELECT INFILE2 ASSIGN TO INFILE2. SELECT INFILE1 ASSIGN TO INFILE1.com Page 75 date:16. GIVING and POUTPUT-PROCEDURE are mutually exclusive Other rules remain same as that of SORT statement. FILE SECTION. 05 MERGE-KEY1 PIC X(5). SD MERGE-WORK-ONE RECORD CONTAINS 80 CHARACTERS DATA RECORD MERGE-RECORD.05. PROGRAM-ID. ENVIRONMENT DIVISION. File-name-4 is the actual output merged file. DATA DIVISION.

mainframe230.2010 . STOP RUN. 01 FD www. 01 OUTFILE-RECORD PIC X(80). MAIN-PARA.com Page 76 date:16. PERFORM MAIN-PARA DISPLAY "MERGE RC " SORT-RETURN PERFORM END-PARA.COBOL Training DATA RECORD IS INFILE1-RECORD. 01 INFILE2-RECORD PIC X(80).blogspot. MERGE MERGE-WORK-ONE ON ASCENDING KEY MERGE-KEY1 USING INFILE1 INFILE2 GIVING OUTFILE.05. INFILE1-RECORD PIC X(80). END-PARA. INFILE2 RECORD CONTAINS 80 CHARACTERS BLOCK 80 RECORDING MODE IS F DATA RECORD IS INFILE2-RECORD. PROCEDURE DIVISION. WORKING-STORAGE SECTION. FD OUTFILE RECORD CONTAINS 80 CHARACTERS BLOCK 800 RECORDING MODE IS F DATA RECORD IS OUTFILE-RECORD.

4 Year in the Gregorian Calendar 5.3.14 HHMMSS and so on. 11.com Page 77 date:16..2010 . INTRINSIC FUNCTIONS Frequently Used functions are Listed here for reference.Any optional Currency sign mentioned in argument 2 and decimal point are missed on conversion. DATE / TIME CURRENT-DATE .671=31-12-9999 INTEGER-OF-DATE .of periods Formula is Argument1/(1-(1-Argument1)**Argument2 Or 1/argument2 if Argument1=0 PRESENT – VALUE .Reverse of DAY-OF-INTEGER 11.67.67. 8 Day of the Month 9.671=31-12-9999 DAY-OF-INTEGER .Returns the length of the Picture Clause FUNCTION LENGTH(NAME) Will return the Picture Clause value of NAME. 11.1.Returns the content of the argument that contains the maximum value FUNCTION MAX(MARK) . MAX Ex:MIN Ex:. Argument2) Argument1= Rate Of Interest Argument2 = No.blogspot.Returns the content of the argument that contains the minimum value FUNCTION MIN (MARK) NUMVAL . 01-01-1601 =1 and 30. DATE-OF-INTEGER .2.COBOL Training 11.mainframe230.Converts a Date in the Gregorian Calendar from integer date form to standard date form yyyymmdd.Converts a Date in the Gregorian Calendar from integer date form to standard date form yyyyddd 01-01-1601 =1 and 30.Returns the numeric value represented by the alphanumeric character string specified in the argument . NUMBER HANDLING LENGTH . 6 month of the year 7.Reverse of DATE-OF-INTEGER INTEGER-OF-DAY .05.Returns the numeric value represented by the alphanumeric character string specified in the argument NUMVAL-C .Returns a Value that approximate the present value of a series of future periodend amounts specified by argument1 at a discount rate argument2 www. FINANCE ANNUITY FUNCTION ANNUITY(Argument1.Returns 21 Chars alphanumeric Value 1.

blogspot.05.2010 .DEVIATION MEDIAN MIDRANGE RANDOMRANGE www.4.COBOL Training 11. MATHEMATICS & STATISTICS COS FACTORIAL INTEGER MEAN STANDARD .mainframe230.com Page 78 date:16.

The first character of the record does not have to be explicitly reserved by the programmer Instructs the compiler not to adjust the record length for WRITE. However individual applications may experience some performance degradation due to a longer path length but overall system performance may be slightly improved.mainframe230. The application programmer must ensure that the record description allows for this additional byte.05. ADV    Instructs the compiler to add one byte to the record length for the printer control character.com Page 79 date:16. The compiler uses the first character of the specified record area to place the printer control character. COMPILER OPTIONS A compiler directing Statement is a statement beginning with a compile directing verb (CBL Process) that causes the compiler to take specific action during compilation. compilation stops and only syntax checking is done for the balance of the compilation Default COMPILE(S) Default symbol is the dollar sign ($). E is error : S is severe.COBOL Training 12.blogspot. This listing also includes any statements embedded by COPY By default SOURCE = YES Indicates that you want full compilation including diagnostics and object code indicates that you want only a syntax check Specifies an error message level : W is warning . NOADV     LIB  SOURCE / NOSOURCE   COMPILE(n)  NOCOMPILE  NOC (W) NOC (E) NOC (S)   CURRENCY  DYNAM   www. Default Value is Yes.ADVANCING. When an error of the level specified or of a more severe level occurs.2010 . The option may be useful to programmers who use WRITE ADVANCING in their source files. It indicates that the source program contains COPY statements It Indicates the listing of source statements should be included in compiler generated o/p. This option allows you to define an alternate default currency symbol causes subprograms that are invoked through the CALL literal statement to be dynamically loaded Performance consideration : Using DYNAM = YES eases sub-programs maintenance since the application will not have to be relink-edited if the subprogram is changed. Compiler options can be coded in the Program itself but the action is controlled in the JCL as follows.

COBOL Training NODYNAM  Causes the text files of subprograms called with a CALL literal statement to be included with the calling program into a single module file. See also LIST.mainframe230. MAP and TEST Options www.05.2010 .com Page 80 date:16.blogspot.

www. 1 When At End Condition Fails 0 A sequential READ was attempted on an optional file that was not present or after end of file was reached. 3 An attempt was made to access a record that does not exist or an optional file that was not present. 5 The referenced optional file was not present when the OPEN statement was executed.com Page 81 date:16.1.mainframe230. (This does not apply to VSAM sequential files. 1 Returned When At End Condition Fails 2 Returned When Index Key Fails 3 Returned When Permanent Open Error Occurs.) 7 An OPEN or CLOSE statement was executed with a phrase that implies a tape file (i. the file is created. 4 An attempt was made to WRITE beyond the boundaries for a relative or indexed file. 4 Returned When Logic Error in opening/closing/deleting etc 9 Implementator Defined 0 Successful Open / Read / Write / Operation. ERROR CODES The File Status Code attached to a file will have Picture Clause of length 2 digits. The first digit category are as follows : 0 Returned When Successful Open / Read / Write / Operation. 2 An attempt was made to WRITE a record that would create a duplicate key.2010 . 3 Permanent Open Error Occurs. APPENDIX 13. 4 A sequential READ was attempted for a relative file and the relative record number is larger than the maximum number that can be stored in the relative key data item. 4 An attempt was made to WRITE beyond the boundaries of a sequential file. The second digit will denote the particular type of Error/Message under that category. or FOR REMOVAL but the referenced file is not a tape file. 2 This Error Will Occur When Index Key Fails 1 A sequence error exists for a sequentially accessed indexed file. 8 An OPEN statement was attempted on a file previously closed with lock. file status 0 is returned. REEL/UNIT. 0 Successful Completion 2 A duplicate key was detected. The first digit will denote the general category under which the return code falls. If the open mode is I-O or EXTEND. 5 An OPEN statement was attempted on a non-optional file that was not present.NO REWIND.blogspot.COBOL Training 13. 4 The length of the record just read did not conform to the fixed file attributes for the file.05. 7 An OPEN statement was attempted on a file that would not support the open mode specified in the OPEN statement.

4 Logic Error in opening/closing/deleting etc. EXERCISES The following problems are only models. 2 A CLOSE was attempted for a file not in the open mode. Write a program to ACCEPT the following details from the user and compute payslip. 8 A WRITE was attempted on a file not open in the I-O. No file position indicator for sequential request. 4 An attempt was made to REWRITE a record with an invalid length.mainframe230.COBOL Training 9 An OPEN statement was unsuccessful because of a conflict between the fixed file attributes and the attributes specified for the file in the program. You can select similar problems and write programs. Write a program to ACCEPT your name and display the same the number of times you specify.blogspot. EMPLOYEE-NUMBER EMPLOYEE-NAME EMPLOYEE-BASIC PERCENTAGE -OF. www. 2. ANY OTHER ALLOWANCE 9999. 7 A READ was attempted for a file not open in the input or I-O mode.2010 . File integrity verified for VSAM file. ANY OTHER DEDUCTION 9999. 99. VSAM password error. output. 13.CCA PERCENTAGE OF HRA PERCENTAGE-OF-PF XXXXX. 99999.1. VSAM resource not available. 3 The last I/O statement executed for the file prior to the execution of a REWRITE or DELETE statement was not a successfully executed READ statement.05. BASIC PROBLEM SOLVING 1. X(30). 1 An OPEN statement was attempted for a file in the open mode. 9 Implemention Defined 0 1 2 3 4 5 6 7 No further information. or extend mode. 13. showing the given details along with GROSS and NET. 6 A sequential READ was attempted but no valid next record had been established. 99. Logic error. Invalid or incomplete VSAM file information.2. 99.com Page 82 date:16.2. Follow the Program Coding standard strictly. 9 A DELETE or REWRITE was attempted on a file not open in the I-O mode. No DD statement specified for VSAM file.

13.2. ARRAY HANDLING 1.05. X(30). REPORT PREPARATION 1. Transfer the output of Problem 2 to a PS DATA SET. For the above programs give a proper report heading and column headings and print the report in the formatted form.2. UNIT OF MEASUREMENT XXX. Write a program to create a KSDS for the Stock Master File ITEM NUMBER ITEM NAME BALANCE QUANTITY XXXXX. Edit numeric data with comma for clarity.2. 13. Write a program to input the temperature for a week and display the temperature on any day of the week. 2. Write a COBOL Program to maintain the above Stock Master and do necessary update process on Issue/Receipt of the Item. Transaction entries may be saved in a PS Data Set.mainframe230. FILE HANDLING 1. Display the temperature detail on Input. Use necessary edited picture clauses.COBOL Training 3.Write a program to display the class obtained by the student based on the marks obtained in three subjects as per the following rules. Write a program to Input the data in a ESDS Dataset and display the Data.In no subject the boy should have got < 40 Condition For Class III Class : 40 or More but Less than 50 II Class : 50 or More but Less than 60 I Class : 60 or More but Less than 80 DISTINCTION : 80 or More 13.com Page 83 date:16.2. Expand the Table to two dimensional array to accept week as well as the temperature on any day of the week. 2.blogspot.3. 3. 2. 3. www.2010 . 99999. Basic Condition :.4. 4. Find the day on which there was the highest temperature.

SYSIN DD DSN=&SYSUID.45) //* ---------------------------------------------------------------//* ------------COMPILING & LINK EDITING---------------------------//* ---------------------------------------------------------------//* CHECK JOBNAME AND USERID BEFORE SUBMITTING //* THIS JCL COMPILES AD/CYCLE COBOL/370 PROGRAM SPECIFIED BY //* COB.45) //* ---------------------------------------------------------------//* ------------COMPILING .MSGLEVEL=(1.SYSIN DD NAME AND PRODUCES LOAD MODULE IN THE DATA SET //* MEMBER SPECIFIED BY LKED.mainframe230.COBOL Training 13. Linkedit and execute any COBOL Program.3.MSGCLASS=X.DISP=SHR //LKED.NOTIFY=&SYSUID. //* ---------------------------------------------------------------//CMPCOB EXEC IGYWCLG //COBOL.com Page 84 date:16.COBOL(MEMBER1).DISP=SHR //LKED.SYSLMOD DD DSN=&SYSUID.SYSLMOD DD NAME .SYSIN DD DSN=&SYSUID.1).TIME=(00.COBOL(VTOCLIST).TRG1. //* ---------------------------------------------------------------//CMPCOB EXEC IGYWCL or IGYWCLG //COBOL. // REGION=2M.TIME=(00.LOAD(VTOCLIST). JCL IGYWCL is a catalogued procedure to Compile and Linkedit any COBOL Program.MSGCLASS=X.LINK EDITING & EXECUTING---------------//* ---------------------------------------------------------------//* CHECK JOBNAME AND USERID BEFORE SUBMITTING //* THIS JCL COMPILES AD/CYCLE COBOL/370 PROGRAM SPECIFIED BY //* COB.1). JCL for IGYWCL //&SYSUIDZZ JOB CLASS=B.SYSIN DD * /* // ******** End of the Document ******** www. IGYWCLG is a catalogued procedure to Compile.blogspot.LOAD(MEMBER1).SYSIN DD NAME AND PRODUCES LOAD MODULE IN THE DATA SET //* MEMBER SPECIFIED BY LKED.2010 .DISP=SHR // JCL for IGYWCLG //&SYSUIDZZ JOB CLASS=B. // REGION=2M.TRG1.MSGLEVEL=(1.NOTIFY=&SYSUID.TRG1.05.SYSLMOD DD DSN=&SYSUID.TRG1.DISP=SHR //GO.SYSLMOD DD NAME AND EXECUTES THE /* MEMBER.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->