Your SlideShare is downloading. ×
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
User manual for cobol
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

User manual for cobol

1,905

Published on

User manual for cobol

User manual for cobol

Published in: Education, Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,905
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
8
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. User Manual for COBOL_______________________________________________________________________________ COBOL Training Material_______________________________________________________________________________ COBOL 1
  • 2. User Manual for COBOL_______________________________________________________________________________Table of Contents1. OBJECTIVES...........................................................................................................92. INTRODUCTION TO COBOL................................................................................102.1. LANGUAGE CONSTRUCTION..........................................................................102.2. COBOL CHARACTER SET................................................................................102.3. COBOL WORDS.................................................................................................102.4. COBOL CODING FORM.....................................................................................112.5. DIVISIONS OF COBOL......................................................................................113. IDENTIFICATION DIVISION..................................................................................123.1. SYNTAX OF IDENTIFICATION DIVISION.........................................................124. ENVIRONMENT DIVISION....................................................................................134.1. CONFIGURATION SECTION.............................................................................134.1.1. SOURCE-COMPUTER....................................................................................134.1.2. OBJECT COMPUTER.....................................................................................134.1.3. SPECIAL-NAMES............................................................................................134.2. INPUT-OUTPUT SECTION.................................................................................154.2.1. FILE-CONTROL...............................................................................................154.2.2. I-O CONTROL..................................................................................................155. DATA DIVISION.....................................................................................................175.1. LITERALS AND FIGURATIVE CONSTANTS....................................................175.1.1. NUMERIC LITERAL.........................................................................................18_______________________________________________________________________________ COBOL 2
  • 3. User Manual for COBOL_______________________________________________________________________________5.1.2. NON-NUMERIC LITERAL...............................................................................185.1.3. LIST OF FIGURATIVE CONSTANTS............................................................185.2. DATA DESCRIPTION.........................................................................................195.2.1. LEVEL NUMBERS...........................................................................................195.2.1.1. SPECIAL LEVEL NUMBERS.......................................................................205.2.2. DATA NAMES..................................................................................................205.2.2.1. FILLER..........................................................................................................215.2.3. CLAUSE...........................................................................................................215.2.3.1. PICTURE CLAUSE.......................................................................................225.2.3.1.1. EDITED PICTURE CLAUSES...................................................................225.2.3.1.2. EDIT TYPES - NUMERIC DATA...............................................................225.2.3.1.3. EDIT TYPES - ALPHABETIC....................................................................245.2.3.1.4. EDIT TYPES - ALPHANUMERIC..............................................................245.2.3.1.5. EDIT COMBINATION................................................................................245.2.3.2. VALUE CLAUSE...........................................................................................255.2.3.3. USAGE CLAUSE..........................................................................................255.2.3.3.1. DISPLAY USAGE......................................................................................255.2.3.3.2. COMPUTATIONAL(COMP) USAGE........................................................265.2.3.4. SIGN CLAUSE..............................................................................................275.2.3.5. OCCURS CLAUSE.......................................................................................285.2.3.6. REDEFINES CLAUSE..................................................................................285.2.3.6.1. EXPLICIT USE OF REDEFINES...............................................................28_______________________________________________________________________________ COBOL 3
  • 4. User Manual for COBOL_______________________________________________________________________________5.2.3.6.2. RESTRICTIONS ON USE OF REDEFINES..............................................295.2.3.7. RENAMES.....................................................................................................295.2.3.8. JUSTIFIED CLAUSE....................................................................................295.2.4. CONDITION NAMES.......................................................................................306. PROCEDURE DIVISION........................................................................................316.1. STATEMENTS IN PROCEDURE DIVISION.......................................................316.2. DATA MOVEMENT.............................................................................................336.2.1. MOVE...............................................................................................................336.2.1.1. DATA MOVEMENT RULES.........................................................................336.2.1.2. NUMERIC DATA TRANSFER RULES.........................................................336.2.1.3. ALPHANUMERIC DATA TRANSFER.........................................................346.2.1.4. GROUP MOVES............................................................................................346.2.1.5. MOVE CORRESPONDING...........................................................................356.3. ARITHMETIC VERBS ........................................................................................366.3.1. ADD..................................................................................................................366.3.2. SUBTRACT......................................................................................................376.3.3. MULTIPLY........................................................................................................376.3.4. DIVIDE..............................................................................................................376.3.5. ROUNDED OPTION.........................................................................................386.3.6. ON SIZE ERROR.............................................................................................396.3.7. COMPUTE........................................................................................................406.3.8. ARITHMETIC OPERATORS............................................................................40_______________________________________________________________________________ COBOL 4
  • 5. User Manual for COBOL_______________________________________________________________________________6.4. MISCELLANEOUS..............................................................................................416.4.1. ACCEPT...........................................................................................................416.4.2. DISPLAY..........................................................................................................426.4.3. CONTINUE.......................................................................................................426.4.4. STOP RUN.......................................................................................................426.4.5. EXIT..................................................................................................................426.4.6. INITIALIZE........................................................................................................426.5. CONDITIONAL AND UNCONDITIONAL TRANSFER.......................................446.5.1. SIMPLE IF STATEMENT.................................................................................446.5.2. NESTED IF.......................................................................................................456.5.3. EVALUATE STATEMENT...............................................................................456.5.4. GO TO STATEMENT.......................................................................................466.5.5. GO TO WITH DEPENDING.............................................................................466.5.6. ALTER..............................................................................................................476.6. PERFORM STATEMENTS.................................................................................476.6.1. BASIC PERFORM............................................................................................476.6.2. PERFORM WITH TIMES PHRASE.................................................................496.6.3. PERFORM WITH UNTIL PHRASE..................................................................496.6.4. PERFORM WITH VARYING PHRASE............................................................506.7. CONDITIONAL EXPRESSIONS.........................................................................516.7.1. RELATIONAL CONDITION.............................................................................516.7.2. SIGN CONDITION............................................................................................52_______________________________________________________________________________ COBOL 5
  • 6. User Manual for COBOL_______________________________________________________________________________6.7.3. CLASS CONDITION........................................................................................526.7.4. CONDITION-NAME CONDITION....................................................................536.7.5. NEGATED SIMPLE CONDITION....................................................................536.7.6. COMPOUND CONDITION...............................................................................537. FILE HANDLING....................................................................................................537.1. SEQUENTIAL FILES..........................................................................................547.2. INDEXED FILES..................................................................................................547.3. DIRECT ACCESS FILES....................................................................................547.4. STEPS INVOLVED IN FILE HANDLING............................................................547.4.1. EXAMPLE........................................................................................................567.5. SELECT STATEMENT.......................................................................................567.5.1. ORGANIZATION CLAUSE..............................................................................577.5.2. ACCESS MODE CLAUSE..............................................................................587.5.3. RECORD KEY PHRASE..................................................................................587.5.4. ALTERNATE KEY PHRASE...........................................................................587.6. FD ENTRY...........................................................................................................587.6.1. BLOCK CONTAINS / RECORD CONTAINS PHRASE..................................597.6.2. RECORDING MODE CLAUSE.......................................................................597.7. INPUT / OUTPUT STATEMENTS......................................................................617.8. VSAM DATA SET...............................................................................................627.8.1. VSAM DATASETS AND ACCESS MODES....................................................637.8.1.1. ORGANIZATION CLAUSE...........................................................................63_______________________________________________________________________________ COBOL 6
  • 7. User Manual for COBOL_______________________________________________________________________________7.8.2. ENVIRONMENT DIVISION ENTRIES FOR VSAM FILES..............................647.8.3. COBOL STATEMENTS USABLE WITH SEQUENTIAL FILES.....................657.8.4. COBOL STATEMENTS WITH INDEXED FILES (KSDS) AND RELATIVE(RRDS).......................................................................................................................657.8.5. PROCEDURE DIVISION STATEMENTS TO UPDATE VSAM FILES...........667.8.6. ERROR PROCESSING FOR VSAM................................................................677.8.7. APPLICATIONS BEST SUITED TO VSAM DATASETS................................677.8.7.1. ESDS.............................................................................................................677.8.7.2. KSDS.............................................................................................................687.8.7.3. RRDS.............................................................................................................688. SUBPROGRAMS...................................................................................................698.1. LINKAGE SECTION............................................................................................698.1.1. STATIC / DYNAMIC CALLS............................................................................698.1.2. PASSING RETURN CODE INFORMATION...................................................719. STRING , UNSTRING AND INSPECT STATEMENTS.........................................729.1. STRING STATEMENT........................................................................................729.2. UNSTRING STATEMENT...................................................................................739.3. INSPECT STATEMENT......................................................................................749.4. DECLARATIVES.................................................................................................7610. SORT AND MERGE STATEMENTS...................................................................7711. INTRINSIC FUNCTIONS.....................................................................................7911.1. NUMBER HANDLING......................................................................................79_______________________________________________________________________________ COBOL 7
  • 8. User Manual for COBOL_______________________________________________________________________________11.2. DATE / TIME....................................................................................................7911.3. FINANCE..........................................................................................................8011.4. MATHEMATICS & STATISTICS.....................................................................8012. COMPILER OPTIONS........................................................................................8113. APPENDIX...........................................................................................................8313.1. ERROR CODES...............................................................................................8313.2. EXERCISES:....................................................................................................8413.2.1. BASIC PROBLEM SOLVING........................................................................8413.2.2. REPORT PREPARATION.............................................................................8513.2.3. ARRAY HANDLING.......................................................................................8613.2.4. FILE HANDLING............................................................................................8613.3. JCL...................................................................................................................87_______________________________________________________________________________ COBOL 8
  • 9. User Manual for COBOL_______________________________________________________________________________1. OBJECTIVESThe main objective after the completion of this course, 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. ♦ Submit jobs to Compile and Link-edit COBOL source codes. ♦ Write programs using modular design techniques._______________________________________________________________________________ COBOL 9
  • 10. User Manual for COBOL_______________________________________________________________________________2. INTRODUCTION TO COBOLCOBOL => COMMON BUSINESS ORIENTED LANGUAGECobol can be referred to as : 1. High-Level Programming language oriented towards business applications. 2. A procedure oriented language. A Procedure is a module having its own task. A Problem may be segmented into several tasks. Each task is written as a Paragraph in Procedure Division and executed in a logical sequence as mentioned. 3. Problem Oriented and Machine independent2.1. LANGUAGE CONSTRUCTION ♦ COBOL is like an English language. ♦ Character is the lowest component. ♦ Word is made up of one or more characters. ♦ Clause consists of word and characters. It specifies an attribute for an entry ♦ Statement is syntactically valid combination of words and clauses ♦ 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 divisions2.2. COBOL CHARACTER SETSet of 52 characters 0,..9 DIGITS A,..Z LETTERS b SPACE/BLANK CHARACTER +,-,*,/,(,),= SPECIAL SYMBOLS $,;,“,>,<,.,:2.3. COBOL WORDSUser defined words_______________________________________________________________________________ COBOL 10
  • 11. User Manual for COBOL_______________________________________________________________________________ ♦ Words declared by programmer to coin identifiers, paragraph names, file names and section names.Reserved words ♦ Words which are having specific meaning to the compiler.2.4. COBOL CODING FORMColumns1- 6 Sequence numbers identifying pages or lines of a program7 Continuation, comment or starting of a new page8-11 Area A12-72 Area B73-80 Remarks2.5. DIVISIONS OF COBOL ♦ IDENTIFICATION DIVISION ♦ ENVIRONMENT DIVISION ♦ DATA DIVISION ♦ PROCEDURE DIVISION_______________________________________________________________________________ COBOL 11
  • 12. User Manual for COBOL_______________________________________________________________________________3. IDENTIFICATION DIVISIONThe Identification division is: ♦ First division of a Cobol program. ♦ Paragraph program-id followed by a user-defined name is compulsory. Other paragraphs are optional but essential for documentation. ♦ Should begin in Area A. ♦ Length of PROGRAM-ID differs from compiler to compiler. For example, in the case of IBM COBOL, it is 8 characters.3.1. SYNTAX OF IDENTIFICATION DIVISIONIDENTIFICATION DIVISION.PROGRAM-ID. PROGRAM NAME.AUTHOR.COMMENT ENTRY.INSTALLATION.COMMENT ENTRY.DATE-WRITTEN.COMMENT ENTRY.DATE-COMPILED.COMMENT ENTRY.SECURITY.COMMENT ENTRY.]Security here does not pertain to the operating system security, but the information that is passed tothe user of the program about the Security features of the program._______________________________________________________________________________ COBOL 12
  • 13. User Manual for COBOL_______________________________________________________________________________4. ENVIRONMENT DIVISION ♦ It is a machine dependent division. ♦ The Division itself is optional but for file handling it is essential. ♦ Should begin in Area A. ♦ Division is terminated by a period. ♦ Describes the computer used, peripheral devices, etc. ♦ Contains two sections namely, CONFIGURATION and INPUT-OUTPUT.4.1. CONFIGURATION SECTIONMentions the name of the source-computer, object-computer, special-names, symbolic-names andclasses defined by programmer.The paragraphs of configuration section are SOURCE-COMPUTER, OBJECT-COMPUTER, andSPECIAL-NAMES.4.1.1. SOURCE-COMPUTER ♦ Used to specify the name of the Source Computer compiling the COBOL program. ♦ 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). It can also include the debug Declaratives in PROCEDURE DIVISION.4.1.2. OBJECT COMPUTER ♦ Used to specify the target system. ♦ The program collating sequence can also be specified in this paragraph for SORTING and STRING COMPARISON. By default, EBCDIC code is followed in MVS. We can change it to ASCII, or any other order if we define SPECIAL-NAMES.4.1.3. SPECIAL-NAMES ♦ Specifies collating sequence._______________________________________________________________________________ COBOL 13
  • 14. User Manual for COBOL_______________________________________________________________________________ ♦ Maps IBM specified environment names to user defined mnemonic names. ♦ Substitutes character for currency sign. ♦ Indicates that ‘ ; ‘ and ‘ . ‘ are to be interchanged in the PIC clause. ♦ We can also specify symbolic characters, such as, PERCENTAGE-SIGN IS 38. ♦ Regardless of the number of entries in this paragraph, there should be only one period at the end._______________________________________________________________________________ COBOL 14
  • 15. User Manual for COBOL_______________________________________________________________________________4.2. INPUT-OUTPUT SECTION ♦ Contains information regarding files to be used in the program. ♦ Consists of two paragraphs FILE-CONTROL and I-O CONTROL.4.2.1. FILE-CONTROLAssociates each file used in a COBOL program with an external ddname.Physical dataset is assigned in DD statement of JCL at execution time.Three formats for the FILE-CONTROL paragraph are : ♦ Sequential file entries ♦ Indexed file entries ♦ Relative file entriesCoding rules for FILE-CONTROL paragraph. ♦ SELECT clause must appear first ♦ Other clauses may appear in any order ♦ Each clause must start in Area B4.2.2. I-O CONTROL ♦ Optional Paragraph. ♦ Specifies when check points are to be taken. ♦ Specifies the storage areas to be shared by different files. ♦ The key word I-O control must begin in Area A._______________________________________________________________________________ COBOL 15
  • 16. User Manual for COBOL_______________________________________________________________________________Example:IDENTIFICATION DIVISION.PROGRAM-ID. DSQ001.AUTHOR. A343.INSTALLATION. AT DSQ. MAD.DATE-WRITTEN. 06-04-94.DATE-COMPILED. XX-XX-XX.SECURITY. ONLY FOR TRAINEES.ENVIRONMENT DIVISION.CONFIGURATION SECTION.SOURCE-COMPUTER. ES-9000 WITH DEBUGGING MODE.OBJECT-COMPUTER. ES-9000 PROGRAM COLLATING SEQUENCE IS A01.SPECIAL-NAMES. C12 IS BOTTOM OF PAGE. ALPHABET A01 IS “A” ALSO “a” “B” ALSO “b” ALPHABET A IS STANDARD-1. SYSIN IS PROGIN CURRENCY IS @ DECIMAL POINT IS COMMAINPUT-OUTPUT SECTION.FILE-CONTROL SELECT OUTFILE ASSIGN TO DD1 ORGANIZATION IS SEQUENTIAL ACCESS MODE SEQUENTIAL FILE STATUS IS WS-FST._______________________________________________________________________________ COBOL 16
  • 17. User Manual for COBOL_______________________________________________________________________________5. DATA DIVISIONData division is used to define data needed to be accessed by the program. The three sections of thisdivision areFILE SECTION ♦ Describes Record Structure of FilesWORKING-STORAGE SECTION ♦ Succeeds file section ♦ Used for intermediate storage ♦ Common practice to group related items together.LINKAGE SECTION ♦ Describes data made available from another program.5.1. LITERALS AND FIGURATIVE CONSTANTS. ♦ Literal is a constant representing a number or Non number (Alpha numeric) like 45.3 / ‘MANAGER’. ♦ 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. ♦ Figurative constants are used in the program as such for better readability as. ♦ MOVE SPACES TO WS-REC. ♦ Literals are classified in to NUMERIC and NON-NUMERIC literals._______________________________________________________________________________ COBOL 17
  • 18. User Manual for COBOL_______________________________________________________________________________5.1.1. NUMERIC LITERAL ♦ Must contain at least one digit ♦ Sign, if used must be the left-most character ♦ Not more than one decimal point ♦ Decimal may not be the right most character ♦ Maximum of 18 digits. ♦ TOTAL-MARK PIC 9(3) VALUE 100.. ♦ Here 100 is a numeric constant assigned in identifier TOTAL-MARK.5.1.2. 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 chars05 COMPANY-NAME PIC X(3) VALUE ‘DSQ’.Here ‘DSQ’ is a Alphanumeric constant assigned in identifier COMPANY-NAME,5.1.3. LIST OF FIGURATIVE CONSTANTSZERO/ZEROES/ZEROS ONE OR MORE ZEROSQUOTE/QUOTES ONE OR MORE“SPACE/SPACES ONE OR MORE SPACEHIGH VALUE/HIGHEST VALUE HIGHEST VALUE IN COLLATING SEQUENCELOW VALUE/LOWEST VALUE LOWEST VALUE IN COLLATING SEQUENCEALL ONE or MORE STRING CHARACTERS_______________________________________________________________________________ COBOL 18
  • 19. User Manual for COBOL_______________________________________________________________________________5.2. Data DescriptionThe general format of the data description is ♦ Level-number data-name/FILLER clauses5.2.1. LEVEL NUMBERS ♦ A Record is a Collection of all the fields pertaining to an Item/person/Transaction. ♦ A record structure is a structure of all the fields of a record. It may be available in the FILE SECTION/ WORKING-STORAGE SECTION/ LINKAGE SECTION. ♦ The level-number specifies the hierarchy of data within a record, and identifies special- purpose data entries. A level-number begins a data description entry, a renamed or redefined item, or a condition-name entry. ♦ A level-number has a value taken from the set of integers between 1 and 49, or from one of the special level-numbers, 66, 77, or 88.01 This level - number specifies the record itself. ♦ A level - 01 entry may be either a group item or an elementary item. ♦ It must begin in Area A.02-49 These level numbers specify group and elementary items within a record. ♦ They may begin in Area A or B ♦ Group Level Data Names Will not have Picture Clause. EMPLOYEE-REC. EMP-NO PIC XXXX. EMP-NAME 03 FIRST-NAME PIC A(30). 03 INITIAL-1 PIC A. 03 INITIAL-2 PIC A. 03 INITIAL-3 PIC A._______________________________________________________________________________ COBOL 19
  • 20. User Manual for COBOL_______________________________________________________________________________5.2.1.1. SPECIAL LEVEL NUMBERS66 Identifies items that contain the RENAMES clause.77 Identifies independent elementary data item.Identifies any condition name that is associated with a particular value of conditional variableLevel Number 01 can appear as a Group Level Number as well as Elementary data item level number.It can appear only as an elementary Data Item Level Number.Example01 TOTAL PIC 9(5).77 WS=FLAG PIC XX.5.2.2. Data Names ♦ Identifier name/ Data name should not exceed 30 Characters. ♦ There should be at least one Alphabet anywhere in the name. ♦ Only special Character allowed is – ( Hyphen) but should not be at the Beginning or EndExamples of datanames ♦ EMPLOYEE-NAME , COMPANY, 0001AB, 999-EMPLOYEE-RECORD ♦ Dataname must be unique within a Record ♦ If ‘Name’ is duplicated across Records, it has to be qualified as Identifier-name of Record Name. ♦ Display balance of stock-record ♦ Here balance is an identifier declared in Stock-record._______________________________________________________________________________ COBOL 20
  • 21. User Manual for COBOL_______________________________________________________________________________5.2.2.1. FILLERWhenever there is no need for specific reference to fields in a record structure, we name it asFILLER Or F . This Data name is used wherever there is fixed information like SPACES OrHeadingsAre stored.Example 01 Detail-record. 05 FILLER PIC X(10) VALUE SPACES. 05 NAME PIC X(30) . 05 FILLER PIC X(10) VALUE SPACES. . 05 BASIC PIC 9(05) . 05 FILLER PIC X(10) VALUE SPACES. 05 DA PIC 9(04) . 05 FILLER PIC X(10) VALUE SPACES. 05 GROSS PIC 9(6).5.2.3. CLAUSEA Clause specifies certain characteristics of the data item being described.The detail of each Clause is explained below._______________________________________________________________________________ COBOL 21
  • 22. User Manual for COBOL_______________________________________________________________________________5.2.3.1. PICTURE CLAUSEDescribes the class (numeric, alphabetic, alphanumeric), sign(signed/unsigned), decimal pointlocation and size characteristics of a data item.Specified for every elementary itemFormat of Picture Clause.PICTURE character string TYPE CHARACTER STRING REMARK Numeric 9 Used for arithmetic operations V Assumed Decimal Point S Data item is Signed P Position of Assumed decimal point when the point lies outside the data item Alphabetic A Data Item contains only a Letter Or Space B Blank insertion character Alpha X Data item contains any allowable character Numeric from the COBOL character set.EXAMPLESVAR1 PIC A(04) (Defines 4 alphabetic characters.)VA R2 PIC 9(4) (Defines 4 Numeric digits)5.2.3.1.1. EDITED PICTURE CLAUSESUsed to display Numeric and other data in the human readable form.Displaying the number as 77,419.56 is easier to read instead of 7741958.5.2.3.1.2. EDIT TYPES - NUMERIC DATAZ ZERO SUPPRESSION_______________________________________________________________________________ COBOL 22
  • 23. User Manual for COBOL_______________________________________________________________________________* ASTERISK$ CURRENCY SIGN- MINUS SIGN+ PLUS SIGNCR DB CREDIT DEBIT SIGNPERIOD(.) COMMA(,) BLANK(‘b‘) ZERO(0) SLASH(/)BLANK WHEN ZERO (Inserts blanks when data value is zero)_______________________________________________________________________________ COBOL 23
  • 24. User Manual for COBOL_______________________________________________________________________________5.2.3.1.3. EDIT TYPES - ALPHABETICUsed To Insert Blank within Alphabetic Characters.Example: 10 Var1 PIC A(2)BBBA(3) VALUE “xyabc”5.2.3.1.4. EDIT TYPES - ALPHANUMERIC BLANK, ZERO and SLASH INSERTION PIC OF THE NUMERIC VALUE EDITED VALUE FIELD ZZZV99 38^4 b3840 * * 999 00052 * * 052 $ * *999 985 $**985 -ZZZV99 -46^52 -b4652 +999 -382 -382 +999 382 +382 9999+ -382 0382- ZZ,Z99 2456 b2,456 ZZZZ.ZZ 5 bbbb.05 $$$$9.99 342 b$342.00 99B99B99 46 00b00b46 09990 456 04560 999/999/99 3254 000/032/54 BLANK WHEN ZERO ZZZ.99 BLANK WHEN ZERO 25 bb2.50 999.99 BLANK WHEN ZERO 0 bbbbbb5.2.3.1.5. EDIT COMBINATION_______________________________________________________________________________ COBOL 24
  • 25. User Manual for COBOL_______________________________________________________________________________+, -, CR, DB Are Mutually Exclusive$, +, -, Z, * Are Mutually Exclusive.$ can appear at first place and * as Floating($****.**)V and . Are Mutually Exclusive5.2.3.2. VALUE CLAUSEAssigns initial value to a data itemVALUE IS literalLiteral can be Numeric, Non-Numeric(in Quotes) or Figurative ConstantNot for items whose size is variableValue of item should not exceed picture sizeConsistent with class of PIC clauseEXAMPLES01 WS-REC. 05 WS-NAME PIC X(30) VALUE ‘ABC COMPANY ‘. 05 FILLER PIC X(20) VALUE ALL ‘ - ‘.01 WS-NUM1 PIC 9(5) VALUE ZERO.01 WS-CHAR2 PIC X(5) VALUE ZERO.5.2.3.3. USAGE CLAUSESpecifies how a data item is represented internally. ♦ DISPLAY ♦ COMPUTATIONALSYNTAXUSAGE IS [DISPLAY ][COMPUTATIONAL] [COMP-1] [COMP-2] [COMP-3]5.2.3.3.1. DISPLAY USAGE.Each character of the data is represented in one byte .The number of bytes required is equal to the size of the item.DISPLAY is the default usage_______________________________________________________________________________ COBOL 25
  • 26. User Manual for COBOL_______________________________________________________________________________5.2.3.3.2. COMPUTATIONAL(COMP) USAGE ♦ Maintained in binary ♦ Only integral numbers ♦ Depending on the size of the data item, it can be stored either in half word or full word ♦ Should be numeric only ♦ NUMBER OF digits IN PIC LENGTH OF ITEM IN BYTES 1 TO 4 2 5 TO 9 4 10 TO 18 801 WS - NUM PIC S9(004) USAGE COMP.COMP-1 USAGE . ♦ One word in floating point form ♦ The number is represented in hexadecimal ♦ The picture clause cannot be specified ♦ Suitable for arithmetic operationsWS - NUM USAGE COMP1 .COMP-2 USAGE. ♦ Same as COMP 1 except that data is represented internally in two words ♦ Increases the precision of the data_______________________________________________________________________________ COBOL 26
  • 27. User Manual for COBOL_______________________________________________________________________________COMP-3 USAGE. ♦ 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 signEXAMPLE FOR USAGE COMP - 310 A PIC S9(3) USAGE COMP-3 VALUE 123.Internally stored as0001 0010 0011 11111 2 3 F10 A PIC S9(04) USAGE COMP-3 VALUE 123.is stored as0000 0000 0001 0010 0011 1111(Extra Byte)5.2.3.4. SIGN CLAUSE ♦ [SIGN IS][LEADING] [SEPARATE CHAR ] [TRAILING] ♦ Specifies the position and mode of representation of sign ♦ Only for numeric elementary items ♦ Picture string should contain ‘S’ ♦ Usage should be DISPLAY ♦ Default is TRAILING without separate characterEXAMPLE PIC VALUE SIGN REPRESENTATION S9(3) -243 LEADING K 4 3 S9(3) -243 TRAILING 2 4 L_______________________________________________________________________________ COBOL 27
  • 28. User Manual for COBOL_______________________________________________________________________________5.2.3.5. OCCURS CLAUSEThere may be a need to keep a table of values in the memory for calculations. We use OCCURSclause to allocate physically contiguous memory locations to store the table values and access themwith subscripts.Example,01 WS-TABLE. 10 WS-NAME OCCURS 10 TIMES PIC X(20).01 WS-TABLE. 10 WS-REC OCCURS 10 TIMES. 15 X PIC X(5). 15 Y PIC X(8).WS - REC (1) = 13 BYTES (i.e. X(1) = 5 bytes, Y(1) = 8 bytes)Hence, 10 such group items (WS-REC) are allocated memory space contiguously.5.2.3.6. REDEFINES CLAUSEThis clause allows the same area of memory to be referenced by more than one data-name withdifferent formats and sizes.SYNTAX AND RULES< Lvl.no > <Data-item-1> REDEFINES <Data-item-2>.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.5.2.3.6.1. Explicit Use OF REDEFINESREDEFINES must be used for remapping record areas outside the FILE-SECTION, or within theFILE-SECTION if a part of a record is to be remapped._______________________________________________________________________________ COBOL 28
  • 29. User Manual for COBOL_______________________________________________________________________________Example,FD CARDIN.01 D-TYPE-1 05 CARD-CODE PIC 9. 05 NAME-ADD. 10 NAME PIC X(20). 10 ADD-LN-1 PIC X(40). 05 NAME-DD REDEFINES NAME-ADD. 10 ADD-LN-2 PIC X(60).5.2.3.6.2. RESTRICTIONS ON USE OF REDEFINESRedefinition ceases whenever a level number is less than or equal to that of <data-item-1 > or <data-item-2>Multiple redefinition’s of the same area is possible provided there are no new storage areasdefined in between . < data-item - 1 > and <data-item-2>Value clauses are allowed only in condition names in a redefined data-item.At 01 level, OCCURS and REDEFINES cannot be combined<data-name-2> may not have an OCCURS clause5.2.3.7. RENAMESRegrouping of elementary data items in a Record.01 W-RESPONSE 05 W-CHAR-123 PIC XXX. 05 W-CHAR-4 PIC X. 05 W-CHAR-56 PIC XX. 66 ADD-RESPONSE RENAMES W-CHAR-123. 66 VIEW-RESPONSES RENAMES W-CHAR-123 THRU W-CHAR-4. 66 DELETE-RESPONSE RENAMES W-CHAR-123 THRU W-CHAR-56.5.2.3.8. JUSTIFIED CLAUSE_______________________________________________________________________________ COBOL 29
  • 30. User Manual for COBOL_______________________________________________________________________________Overrides standard positioning rules for a receiving stem of the alphabetic or alphanumericcategories.01 WS-CHAR PIC X(05) JUSTIFIED RIGHT.Default is left justifiedJustified clause does not alter initial settings as determined by the value clauseJustified clause must not be specified with level 66(RENAMES) and level 88(condition-names)clauses.5.2.4. CONDITION NAMES ♦ Allow users to assign acceptable values for data names ♦ Are used as an abbreviation for condition checking01 W-PERSON-STATUS PIC 9(02). 88 C-PER-MINOR VALUE O THRU 20 88 C-PER-ADULT VALUE 21 THRU 99_______________________________________________________________________________ COBOL 30
  • 31. User Manual for COBOL_______________________________________________________________________________6. PROCEDURE DIVISION ♦ Last division in a COBOL program ♦ Contains statements which specify the operations to be performed ♦ Contains the following structureSTRUCTURE PROCEDURE DIVISION SECTION PARAGRAPHS SENTENCES STATEMENTS VERBS ♦ 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, it has to be qualified as paragraph-name { of / in } section name6.1. STATEMENTS IN PROCEDURE DIVISIONProcedure division statements can be broadly classified as ♦ Imperative Statements ♦ Statement which directs the program to take a specific action during executionExamples MOVE, ADD, GOTO, EXIT. ♦ Conditional Statements ♦ A conditional statement specifies that the truth value of a condition is to be determined, and that the subsequent action of the object program is dependent on this truth value.Examples: IF , EVALUATE , ADD...ON SIZE ERROR, ADD...NOT ON SIZE ERROR COMPUTE...ON SIZE ERROR, COMPUTE...NOT ON SIZE ERROR ♦ Compiler DirectivesA Compiler-Directing Statement is a statement, beginning with a compiler directing verb, that causesthe compiler to take a specific action during compilation.Example : Use, Copy_______________________________________________________________________________ COBOL 31
  • 32. User Manual for COBOL_______________________________________________________________________________ ♦ Explicit Scope TerminatorAn EXPLICIT SCOPE TERMINATOR terminates the scope of conditional statements. This includesstatements which contain conditional expression (like IF statement) and imperative statements (likeADD)ExamplesEND-ADD, END-IF, END-COMPUTE, END-DELETE, END-SUBTRACT, END-EVALUATE,END-CALL,END-MULTIPLY ♦ Implicit Scope TerminatorAt the end of any sentence, an IMPLICIT SCOPE TERMINATOR is a separator period thatterminates the scope of all previous statements not yet terminated._______________________________________________________________________________ COBOL 32
  • 33. User Manual for COBOL_______________________________________________________________________________6.2. Data Movement6.2.1. MOVETo move data into a place in memory.Format,MOVE {IDENTIFIER-1/LITERAL-1} TO IDENTIFIER-2[,IDENTIFIER-3],..6.2.1.1. DATA MOVEMENT RULESOnly one sending field , One or more receiving fields.Value of the sending field remains unaltered after the statement execution.6.2.1.2. NUMERIC DATA TRANSFER RULESWhen sending field is numeric or numeric-edited, the Data Movement is called Numeric.The dominant factor in the numeric data transfer is the alignment of decimal points of the two fieldsIf the decimal point is not explicitly indicated, the decimal point is assumed to be at the right of therightmost digitIf the receiving field is not large enough to hold the data received, truncation can take place at eitherends or at both endsIf the significant integral positions are likely to be lost, a warning to that effect is issued by thecompilerIf the receiving field is larger than the sending field, the unused positions will be filled with zeros,which is known as ‘ zero fill ‘_______________________________________________________________________________ COBOL 33
  • 34. User Manual for COBOL_______________________________________________________________________________6.2.1.3. ALPHANUMERIC DATA TRANSFER.When both the sending and receiving fields are alphabetic, alphanumeric or alphanumeric edited, theData Movement is called as Alphanumeric.In the case of alphanumeric data transfer, receiving area is filled from left to rightWhen the receiving field is smaller, truncation occurs from the right and the compiler gives a warningto that effectIf the receiving field is larger than the field, the unused positions will be filled with spaces, which iscalled as ‘ space fill ‘ExamplesMOVE A TO BA BPIC 9999 PIC ZZZ9bb34MOVE 15 TO A.If A has picture of 999, after execution A will contain 015MOVE “DSQ SOFTWARE Ltd.“ TO COMPANY-MNAME.MOVE A TO B, C, D.6.2.1.4. GROUP MOVESWhen At Least One Of The Fields is a Group item, it is called A Group MoveEXAMPLE 01 REC-1. 05 A1 PIC 9999. 05 A2 PIC AA. 05 A3 PIC XXXX. 01 REC-2 05 B1 PIC 9999. 05 B2 PIC AA. 05 B3 PIC XXXX.MOVE REC-1 TO REC-2_______________________________________________________________________________ COBOL 34
  • 35. User Manual for COBOL_______________________________________________________________________________6.2.1.5. MOVE CORRESPONDINGWhen the names of the corresponding data item of two groups are the same, this statement can beused to substitute for a set of move statementsMOVE CORRESPONDING IDENTIFIER-1 TO IDENTIFIER-2.Source and destination groups can include data names that are not commonOnly the fields having identical names in the two records will take part in the data movementsThe remaining data items in the destination group will remain unchangedEXAMPLE01 PAY-REC. 05 EMP-NO. PIC 9(5) 05 EMP-NAME PIC X(30). 05 EMP-BASIC PIC 9(5)V99.01 PRINT-REC. 05 FILLER PIC X(5). 05 EMP-NO PIC 9(5). 05 FILLER PIC X(5). 05 EMP-NAME PIC X(30). 05 FILLER PIC X(5). 05 EMP-SAL PIC 9(6).99.MOVE CORRESPONDING PAY-REC TO PRINT-REC._______________________________________________________________________________ COBOL 35
  • 36. User Manual for COBOL_______________________________________________________________________________6.3. ARITHMETIC VERBS6.3.1. ADDThis verb is used to find the sum of two or more numbers and to store the resultant sumADD [CORRESPONDING] [IDENTIFIER-1 / LITERAL-1] [IDENTIFIER-2 / LITERAL-2] [TO / GIVING] IDENTIFIER-3, IDENTIFIER-4, ...Example:-ADD A TO BADD A B GIVING C.ADD CORR OLD-REC TO NEW-REC.In the case of TO option, the previous value of the last named operand takes part in the summationand then this value is replaced by the result.Whereas in the case of GIVING option, the value of the last named operand does not take part in thesummation and only the result is stored there.In the group add, numeric elementary items in the group referred to by first identifier are added toand stored in the corresponding elementary items of the second group.Data items in identifier-1 and identifier-2 take part in the summation, only if they have the Same dataname and same qualifiersCorresponding items can have different locations within the group and the field sizes Can also bedifferent_______________________________________________________________________________ COBOL 36
  • 37. User Manual for COBOL_______________________________________________________________________________6.3.2. SUBTRACTThis verb is used to subtract one or the sum of two or more numbers from one or more numbers.Subtract [CORR] [IDENTIFIER-1 / LITERAL-1] [IDENTIFIER-2 / LITERAL-2] [FROM / GIVING] IDENTIFIER-3, IDENTIFIER-4, ...If GIVING option is used literals can be used in place of identifier-4.Example:-SUBTRACT A FROM B.SUBTRACT A B FROM C.SUBTRACT A B FROM C D.SUBTRACT 10 FROM A.6.3.3. MULTIPLYMultiply verb is used to multiply one or more multiplicands by multiplier .MULTIPLY {IDENTIFIER-1 BY IDENTIFIER-2 [ , IDENTIFIER-3]... LITERAL - 1} [GIVING IDENTIFIER-4 [ , IDENTIFIER-5]...]If giving option is used, LITERALS can be used in place of identifier-2 and identifier-3.Example:-MULTIPLY A BY B.MULTIPLY A BY B C D.MULTIPLY A BY B GIVING C.MULTIPLY 0.5 BY B.6.3.4. DIVIDEDivide verb is used to divide one number by another._______________________________________________________________________________ COBOL 37
  • 38. User Manual for COBOL_______________________________________________________________________________DIVIDE {Identifier-1 / Literal-1} INTO[BY] identifier-2 { ,identifier-3}.... [GIVING identifier-4 [ ,identifier-5]...] [REMAINDER identifier-6].ExampleDIVIDE 5 INTO A ..DIVIDE A INTO B GIVING C.DIVIDE A BY B GIVING C D.DIVIDE A BY B GIVING C REMAINDER D.6.3.5. ROUNDED OPTIONThis can be used with any arithmetic verb. It will round the number to the picture clause.ADD A B GIVING C ROUNDED.This phrase cannot be specified for the identifier that receives the remainder in a divide operation._______________________________________________________________________________ COBOL 38
  • 39. User Manual for COBOL_______________________________________________________________________________6.3.6. ON SIZE ERRORIf after an arithmetic operation, the result exceeds the largest value that can be accommodated in theresult field, the error is called a “size error”.Can be used with any arithmetic verbWhen a size error occurs, the contents of the resultant field after the operation is unpredictable.When a size error occurs, the processing is not terminated and the next statement will be taken up forfurther execution.When this phrase is used, the statement becomes a conditional statement.Example:-ADD A TO B ON SIZE ERROR GO TO ERROR-PARA._______________________________________________________________________________ COBOL 39
  • 40. User Manual for COBOL_______________________________________________________________________________6.3.7. COMPUTEThis verb is very powerful and is used as a substitute for any of the other arithmetic verbs like add,subtract, multiply, divide.COMPUTE IDENTIFIER-1 [ROUNDED] [ , IDENTIFIER-2 [ ROUNDED ] ] = ARITHMETIC-EXPRESSION [ : ON SIZE ERROR] IMPERATIVE STATEMENT.6.3.8. ARITHMETIC OPERATORSArithmetic expression is formed with numeric operands, numeric LITERALS and numeric operators..Arithmetic expression always assumes a numeric value.Arithmetic operators permitted in COBOL are ** => EXPONENTIATION. / => DIVISION. * => MULTIPLICATION.. - => SUBTRACTION. + => ADDITION._______________________________________________________________________________ COBOL 40
  • 41. User Manual for COBOL_______________________________________________________________________________6.4. Miscellaneous6.4.1. ACCEPTAccept statement can transfer data from an input/output device, or system information contained inthe specified conceptual data items DATE, DAY, DAY-OF-WEEK, or TIMEFormatACCEPT IDENTIFIER [ FROM mnemonic name DATE DAY TIME DAY-OF-WEEK}]When ‘FROM’ is omitted, the data is read from the operator’s terminal.At the time of execution, program is suspended until the operator enters the data.Mnemonic name option is implementation dependent and has to be defined in SPECIAL-NAMESparagraph.The date option returns six digit [9(6)] current date in YYMMDD format.The day option returns five digit [9(5)] current date in YYDDD format.The time option returns eight digit [9(8)] time in HHMMSSTT formatThe day-of-week option returns a single digit [9(1)] value as follows:1 - Monday, 2 - Tuesday, 3 - Wednesday and so on.ACCEPT THIS-DATE FROM DATE._______________________________________________________________________________ COBOL 41
  • 42. User Manual for COBOL_______________________________________________________________________________6.4.2. DISPLAYDisplay statement is used to display data on the terminal.FormatDISPLAY {identifier-1 identifier-2 literal-1} , literal - 2 [upon mnemonic-name]ExampleDISPLAY “RESULT b IS “,THE-RESULT6.4.3. CONTINUEThe CONTINUE statement allows you to specify a no operation statement. CONTINUE indicatesthat no executable instruction is present.6.4.4. STOP RUNThis verb is used to terminate the execution of the program.6.4.5. EXITThe EXIT statement provides a common end point for a series of paragraphs.This statement indicates a no operation and when executed, no action takes place6.4.6. INITIALIZEThis statement is used to initialize value of either an elementary or group item._______________________________________________________________________________ COBOL 42
  • 43. User Manual for COBOL_______________________________________________________________________________ INITIALIZE {identifier-1 } . . . REPLACING { ALPHABETIC ALPHANUMERIC NUMERIC ALPHA-NUMERIC-EDITED. NUMERIC-EDITED } DATA BY { identifier-2 literal-2 }Example:-INITIALIZE WS - REC. 01 WS - REC. 05 A PIC 9(4). 05 B PIC A(4). 05 C PIC X(4). DATAITEM PIC BEFORE AFTER EXECUTION EXECUTION A 9(4) 1000 0000 B A(4) LIFE bbbb C X(4) A2BC bbbbINITIALIZE B REPLACING NUMERIC DATA BY 105 REPLACING ALPHANUMERIC DATA BY “ LOVE “ REPLACING NUMERIC-EDITED DATA BY 1500.23._______________________________________________________________________________ COBOL 43
  • 44. User Manual for COBOL_______________________________________________________________________________6.5. CONDITIONAL AND UNCONDITIONAL TRANSFER6.5.1. SIMPLE IF STATEMENT.IF condition [THEN] statement-1ELSE statement-2END-IF.The condition can be any one of the conditions mentioned before.Statement-1 represents one or more COBOL statements If the condition is found to be true, thestatements represented in the THEN part will be executed. Statement-1 and Statement-2 representsone or more COBOL statementsIf the condition is found to be FALSE, the statements represented in the ELSE part will be executedAfter execution of this statement control will be implicitly transferred to the next sentence followingthe IF statement.Period (.) is placed only at the end of the IF structure. i.e. after the connective END-IF.Example:-IF AMOUNT > 5000 THEN ADD AMOUNT TO TOTAL-1ELSE ADD AMOUNT TO TOTAL-2END-IF.NEXT SENTENCE will be used to make either the THEN or ELSE part dummy._______________________________________________________________________________ COBOL 44
  • 45. User Manual for COBOL_______________________________________________________________________________6.5.2. NESTED IFInclusion of one or more IF statements within its scope is called as Nesting.The most inclusive IF statement must have terminating period. IF condition-1 [THEN] IF condition-2 [THEN ] statement-1 ELSE statement-2 END-IF END-IF.Indent nested ‘if‘ s properly to improve readability and maintainability.6.5.3. EVALUATE STATEMENTUsed for decisions and can be used when many branches are thereCan be used as a substitute for nested if “sEVALUATE SUBJECT-1 [ALSO SUBJECT-2]... {WHEN OBJECT-1 [ALSO OBJECT-2}...} [WHEN OTHER {IMPERATIVE-STATEMENT-2}...][END-EVALUATE]A list of subjects and several lists of objects are associated with an Evaluate.A list of subjects is specified between the word EVALUATE and the first appearance of WHENSubject can be an Identifier / Literal /Expression or key words True / FalseEach WHEN specifies a list of objectsNumber of subjects and number of objects should tallySubjects and their corresponding objects should be comparableWHEN phrases are taken up for a “ match “ in the order they appear.Imperative statements corresponding to the matching WHEN will be executed.WHEN OTHER phrase is selected only if none of the previous WHEN phrases are selected.Objects can be Numeric value , Non-numeric value, Range of Numeric values, Range of non-numeric values, Conditional Values, keywordsExample:-_______________________________________________________________________________ COBOL 45
  • 46. User Manual for COBOL_______________________________________________________________________________EVALUATE TRUE WHEN MONTH = 4 OR 6 OR 9 OR 11 MOVE 30 TO NO - OF - DAYS WHEN MONTH = 2 MOVE 28 TO NO - OF - DAYS WHEN OTHER MOVE 31 TO NO - OF - DAYS END-EVALUATE.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 COMMISSIONEND-EVALUATE.6.5.4. GO TO STATEMENT.It is an unconditional transferring control to the specified paragraph .There is no any comparison being made by the system before branching off .Example GOTO DISPLAY-PARA.Note:- It is advised to avoid GOTO Statements as the structured programmingTechnique does not support unconditional transfer statements.6.5.5. GO TO WITH DEPENDINGThis verb is used to conditionally transfer the control to elsewhere in the program.Depending on whether the value of the identifier is 1,2 . . . n , the control is transferred to procedure-name-1, procedure-name-2, . . . procedure-name-n respectively.If the value of the identifier is anything other than the specified range of 1, 2 . n, the said go to isineffective and the control is transferred to the next statement._______________________________________________________________________________ COBOL 46
  • 47. User Manual for COBOL_______________________________________________________________________________GO TO PROCEDURE-NAME-1 [ , PROCEDURE-NAME-2 ]... PROCEDURE-NAME-NDEPENDING ON identifierThe statement transfers control to one of the procedures named in the statement depending on thevalue of the identifierThe identifier specified in the statement must be a numeric, integral, elementary item.Example:-GO TO RECEIPT-PARA, ISSUE-PARA, ADJUSTMENT-PARADEPENDING ON TRANSACTION - TYPE.6.5.6. ALTERThe alter statement can be used to modify the targets of goto statements written elsewhere in theprocedure division. ALTER PROCEDURE-NAME-1 TO [PROCEED TO ] PROCEDURE-NAME-2 [PROCEDURE-NAME-3 TO {PROCEED TO } PROCEDURE-NAME-4 ]....Each of the PROCEDURE-NAME-1, PROCEDURE-NAME-3 is the name of the paragraph thatcontains only one sentence.This sentence must consist of a single goto statement without the depending clause.During the execution each of the PROCEDURE-NAME-1 , PROCEDURE-NAME-3, . . . will bereplaced by PROCEDURE-NAME-2, PROCEDURE-NAME-4 ...respectively.6.6. PERFORM STATEMENTSA PERFORM statement is used to execute a group of consecutive statements specified elsewhere inthe program, under a paragraph.6.6.1. Basic PerformPERFORM PARA-name-1.Para-name-1 specifies the range , which contains statements to be executed_______________________________________________________________________________ COBOL 47
  • 48. User Manual for COBOL_______________________________________________________________________________Upon execution of this statement the control is transferred to the beginning of the paragraph andexecutes all the statements in that paragraph till the last statement.After executing the said range, the control is implicitly , transferred to the next line after thePERFORM statementExample:- 100-MAIN-PARA. PERFORM 1000-ACCEPT-PARA. PERFORM 2000-COMPUTE-PARA.PERFORM para-name-1 thru para-name-2.This statement executes all the statements beginning in the para-name-1 till the last statement in thepara-name-2If there are any other paragraphs placed in between these two paragraphs, those are also executedAfter executing the said range, the control is implicitly , transferred to the next line after thePERFORM statementExample:-PERFORM BEGIN-PARA THRU END-PARA._______________________________________________________________________________ COBOL 48
  • 49. User Manual for COBOL_______________________________________________________________________________6.6.2. PERFORM with TIMES phrasePERFORM para-name-1 [THRU para-name-2] {identifier-1/ integer} TIMES.This is a looping statement which executes the specified range of statements a fixed no. of times.Example:- PERFORM READ-RTN 10 TIMES.This statement executes all the stmts. in READ-RTN 10 times without testing any condition.6.6.3. PERFORM with UNTIL phrasePERFORM para-name-1 [THRU para-name-2] UNTIL condition.This statement executes a series of instructions in para-name-1 repeatedly till the condition becomesTRUE.Initially the condition is expected to be false.The condition should be made true, within the paragraph being performed.If the condition is true initially, the range is not executed at allExample:- MOVE 0 TO I. PERFORM 000-CALC-PARA UNTIL I>10000-CALC-PARA. -- ADD 1 TO I.Here 000-CALC-PARA is performed 10 TIMES._______________________________________________________________________________ COBOL 49
  • 50. User Manual for COBOL_______________________________________________________________________________6.6.4. PERFORM with VARYING phrase.PERFORM VARYING{identifier-1 FROM {identifier-2 /integer-1} BY {identifier-3 / integer-2} UNTIL Condition-1 AFTER identifier-1 FROM {identifier-2/integer-1} BY {identifier-3/integer-2} UNTIL Condition-2 [imperative statement]END-PERFORM.This is also a looping statement which executes imperative statement for all possible values ofidentifier-1 and identifier-3 until Condition-1 and Condition-2 are TRUE.ExamplePERFORM VARYING I FROM 1 BY 1 UNTIL I > 3AFTER J FROM 1 BY 1 UNTIL J > 4Display SALE ( I , J )END-PERFORM. The above example will take I and j vales as1,1 1,2 1,3 1,4 2,1 2,2 2,3 2,4 3,1 3,2 3,3 3,4_______________________________________________________________________________ COBOL 50
  • 51. User Manual for COBOL_______________________________________________________________________________6.7. Conditional expressionsIn COBOL there are various types of conditions as follows :RELATIONAL CONDITIONSIGN CONDITIONCLASS CONDITION.CONDITION - NAME CONDITIONNEGATED SIMPLE CONDITION.COMPOUND CONDITION6.7.1. RELATIONAL CONDITIONA relation condition compares two operands, either of which can be an identifier, literal, arithmeticexpression, or index-name. A non-numeric literal can be enclosed in parentheses within a relationcondition.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 ._______________________________________________________________________________ COBOL 51
  • 52. User Manual for COBOL_______________________________________________________________________________6.7.2. SIGN CONDITIONThe sign condition determines whether or not the algebraic value of a numeric operand is greaterthan, less than, or equal to zero. The Possible SIGN conditions are POSITIVE / NEGATIVE /ZERO. IF CURR-STOCK-ISS-QTY IS NEGATIVE DISPLAY “ ISSUE CANNOT BE MADE” GO TO NO-STOCK-PARA END-IF.6.7.3. CLASS CONDITIONThe class condition determines whether the content of a data item is alphabetic,alphabetic-lower, alphabetic-upper, numeric, or contains only the characters in the set of charactersspecified by the CLASS clause as defined in the SPECIAL-NAMES paragraph of the EnvironmentDivision.The possible CLASS Conditions are ALPHABETIC / NUMERIC / ALPHANUMERIC IF A IS NUMERIC ADD 1 TO A ELSE DISPLAY “ NON - NUMERIC DATA FOR A “ GO TO ERROR-PARA END-IF._______________________________________________________________________________ COBOL 52
  • 53. User Manual for COBOL_______________________________________________________________________________6.7.4. CONDITION-NAME CONDITIONA condition-name condition tests a conditional variable to determine whether its value is equal to anyvalue(s) associated with the condition-name.Condition names are not memory locations but names assigned to data ranges .Comparisons can be simplified . 01 WS-MARITAL-STATUS 88 SINGLE VALUE IS 0. 88 MARRIED VALUE IS 1. IF SINGLE ADD 1 TO SINGLE-COUNT.6.7.5. NEGATED SIMPLE CONDITIONA simple condition is negated through the use of the logical operator NOT. IF NOT MARRIED DISPLAY “ELIGIBLE FOR RS 1000 ONLY “ END-IF.6.7.6. COMPOUND CONDITIONTwo or more conditions can be logically connected to form a compound condition.The possible Compound Conditions are AND OR NOT . IF AGE IS LESS THAN 18 AND MARRIED DISPLAY “EARLY MARRIAGE “ END-IF.7. FILE HANDLING_______________________________________________________________________________ COBOL 53
  • 54. User Manual for COBOL_______________________________________________________________________________A data file is a collection of relevant records of an application.A record is a collection of relevant fields pertaining to an item/case/ account/transaction .File is organized in storage media in one of the following ways ♦ SEQUENTIAL ♦ INDEXED ♦ RELATIVE7.1. Sequential FilesIf 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 can not be inserted. ♦ Records cannot be deleted7.2. Indexed FilesIndexed File Organization is to do random Processing or sequential processing.In this Organization ♦ Record can be accessed in any order by key called Primary Key. ♦ There can be more than one key called Alternate Keys to access records ♦ Records can be inserted added and deleted.7.3. Direct Access FilesThis record is best suited if there are records which can be accessed on record number basis ratherthan based on a field of the record.Each record has a unique address and is identified by a relative record number.7.4. STEPS INVOLVED IN FILE HANDLINGTo handle a file the following operations are to done.Step 1._______________________________________________________________________________ COBOL 54
  • 55. User Manual for COBOL_______________________________________________________________________________ ♦ All files handled in a program should be assigned a logical name chosen by the programmer as per the syntax similar to Cobol identifier. The organization of the file ,DDNAME assigned for the dataset and its primary and alternate key, if any, have to be specified in the File-Control para of Environment Division. This is specified using SELECT statement of File-Control para.Step2. ♦ Describe the File with detail like record name ,record structure in the File Section of DATA DIVISION .Also specify as how many records are grouped as a BLOCK for Input Output Operation.Step3. ♦ All files described as explained above should be first opened to do read/write operations. Open statement is used to connect dataset to the Cobol program. This statements are coded in procedure division . Files can be opened for reading, writing ,appending .Step4. If we have to read a file READ statement is used in procedure Division. SYNTAX Read File -name. If we have to write in to a file WRITE command is used in procedure Division. The record attached to the concerned file alone can be used to write into the file. SYNTAX WRITE Record -name.Step5. After read / write operations are over the file must be closed to disconnect the file from theCobol program. SYNTAX CLOSE File-name._______________________________________________________________________________ COBOL 55
  • 56. User Manual for COBOL_______________________________________________________________________________7.4.1. EXAMPLEIDENTIFICATION DIVISION.PROGRAM-ID. F1.ENVIRONMENT DIVISION.INPUT-OUTPUT SECTION.FILE -CONTROL. SELECT CUSTOMER-FILE ASSIGN TO DD1. ORGANIZATION IS INDEXED. ACCESS MODE IS SEQUENTIAL. RECORD KEY IS CUST-NO. FILE STATUS KEY IS WS-FST1.FILE SECTION.FD CUSTOMER - FILE RECORDING MODE IS F RECORD CONTAINS 80 CHARACTERS DATA RECORD IS CUSTOMER - RECORD.01 CUSTOMER RECORD. 05 CUSTOMER - NAME PIC X(13). 05 CUSTOMER - UNITS PIC 9(3). 05 ADDRESS PIC X(64).WORKING-STORAGE SECTION..01 WS-FST1 PIC X(2).PROCEDURE DIVISION.000-MAIN-PARA. OPEN OUTPUT CUSTOMER-FILE. DIASPLAY WS-FST1.100-WRITE-PARA. ACCEPT CUSTOMER-NAME ACCEPT CUSTOMER-UNITS ACCEPT ADDRESS WRITE CUSTOMER-RECORD. Display WS-FST1.200-CLOSE -PARA. CLOSE CUSTOMER-FILE. STOP RUN.7.5. SELECT Statement_______________________________________________________________________________ COBOL 56
  • 57. User Manual for COBOL_______________________________________________________________________________ Syntax : SELECT file-name ASSIGN TO DD Name ORGANIZATION IS [ SEQUENTIAL/INDEXED/RELATIVE] ACESS MODE IS [SEQUENTIAL/DYNAMIC/RELATIVE] [RECORD KEY data-name-1 ] [ALTERNATE KEY IS data-name-2. WITH DUPLICATE] FILE-STATUS IS data-name-2.7.5.1. ORGANIZATION CLAUSEThis clause should appear in Environment division.We can choose File OrganizationSEQUENTIAL This Option is to handle a PS data set or VSAM ESDS .Once the file is Organised 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. This is called primary key And is to be unique like ROLLNO, EMPLYEE NO.RELATIVE This Option is to handle a VSAM RRDS . Record Numbers areidentifying the records to access.._______________________________________________________________________________ COBOL 57
  • 58. User Manual for COBOL_______________________________________________________________________________7.5.2. ACCESS MODE CLAUSEThis clause should appear in the access mode statement of Environment division.Files can be accessed in different modes based on the type of Organization.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 / RelativeFileprovided the Record key must be set before read / write operation.Dynamic Access Mode will facilitate to access a particular record or in sequential order froman Indexed File / Relative FileWe give below all possible access modes on organization. Seq. access Random access Dynamic access Organization Sequential Order of write Invalid Invalid Relative Ascending rel rec. no Value of rel key Seq. or random Indexed Ascending key value Value of rel key Seq. or random7.5.3. RECORD KEY PHRASEThis Phrase is to be defined in the Environment Division and essential when the file is an IndexedFile.This key is to be Unique and is to be a part of the Indexed record.7.5.4. ALTERNATE KEY PHRASEThis Phrase is to be defined in the Environment Division when we want to access record in the orderof 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_______________________________________________________________________________ COBOL 58
  • 59. User Manual for COBOL_______________________________________________________________________________Syntax FD FILENAME[BLOCK CONTAINS [int-1 TO ] int-2 RECORDS[CHARACTERS][RECORD CONTAINS [int-3 TO } int-4 CHARACTERS[LABEL RECORD/RECORDS IS/ARE STANDARD/OMITTEDRECORDING MODE IS [ F/ V][; DATA RECORD/RECORDS IS/ARE data-name-2]]record-name field1 Pic ..7.6.1. BLOCK CONTAINS / RECORD CONTAINS PHRASEWe can specify the length of the file record in this Clause in terms of Characters this is to be specifiedin Data Division. We can specify the number of characters / records contains in a Block.7.6.2. RECORDING MODE CLAUSEThis Phrase is to be defined in the File section Data division. When the file is with Fixed lengthrecord is chosen as F.This key represent s only the record Number.RECORDING MODE [F] [V].F => Fixed which Indicates that every record of same length FD BLOCK CONTAINS 500 CHARACTERS. RECORD CONTAINS 50 CHARACTERS. DATA-RECORD IS EMP-RECORD.EMP-RECORD01 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._______________________________________________________________________________ COBOL 59
  • 60. User Manual for COBOL_______________________________________________________________________________V => Variable which Indicates that record length may vary from I1 to I2.ExampleFD BLOCK CONTAINS 320 THRU 640 CHARACTERS. RECORD CONTAINS 32 THRU 64 CHARACTERS.DATA RECORD IS MARK-RECORD.01 MARK-RECORD02 P1 PIC 99.02 MARKS OCCURS 10 THRU 20 Depending P1 03 SCORE PIC 999.The above record length is based on P1._______________________________________________________________________________ COBOL 60
  • 61. User Manual for COBOL_______________________________________________________________________________7.7. INPUT / OUTPUT STATEMENTSOpen statement can be used for opening the file with different mode.OPEN OUTPUT file-name :- connects data set to your COBOL programto write records when the file is even with out a single record..OPEN INPUT file-name :- connects data set to your COBOL programto records from the first .OPEN EXTEND file-name :- connects data set to your COBOL program for writing new recordsin an existing non empty file.OPEN I-O file-name :- connects data set to your COBOL program for processingto do read/write /Rewrite.WRITE :- Add records to a file or load a file . When this command is used in an Indexed filekey must be newer one always.START Establish the current location in the cluster for a READ NEXT statementSTART does not retrieve a record , it only sorts the current record pointer described under FilePosition indicatorREAD statement is used to read a record from a file. If it is used to read a sequential file it willread the next record always . If it used to read from an Indexed/Relative file it will read thecorresponding key record, The key field must have value before read.If we have read sequentially from an Indexed file READ NEXT RECORD will retrieve recordsfrom a file in sequence REWRITE Update records. DELETE Logically remove records from indexed and relative files only CLOSE Disconnect the VSAM data set from your program_______________________________________________________________________________ COBOL 61
  • 62. User Manual for COBOL_______________________________________________________________________________7.8. VSAM DATA SETCOMPARISON ON VSAM DATASETS Entry - sequenced Key - sequenced Relative - Record Records are in order in which Records are in collating Records are in relative record they are written sequence by key field number order Access is sequential Access is by key through an Access is by relative record index number , which is treated like a key May have one or more May have one or more May not have alternate indexes alternate indexes alternate indexes. A record’s RBA cannot change A record RBA can change A record relative record number cannot change Space at the end of the data set Distributed free space is used for fixed length RRDS empty is used for adding records for inserting record and slots in the data set are used changing their lengths in place for adding records. For variable - length RRDS, 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 you can reuse its space for a shortened record is record can be reused record of the same length automatically reclaimed within a control interval Can have spanned records can have spanned records Can be reused as a word file Can be reused as a word file can be reused as a work file can be reused as work file unless it has an alternate index unless it has an alternate index associated with key ranges or associated with key ranges or exceeds 123 extents per volume exceeds 123 extents per volume_______________________________________________________________________________ COBOL 62
  • 63. User Manual for COBOL_______________________________________________________________________________7.8.1. VSAM DATASETS AND ACCESS MODES File Organization Seq. Ran. Dyna. Fixed Variable Access Access Access Length Length VSAM sequential Yes No No Yes Yes (ESDS) VSAM indexed Yes Yes Yes Yes Yes (KSDS) VSAM Relative Yes Yes Yes Yes NO (RRDS)7.8.1.1. ORGANIZATION CLAUSEORGANIZATION IS SEQUENTIAL - for VSAM sequential files (ESDS)ORGANIZATION IS INDEXED - for VSAM indexed files (KSDS)ORGANIZATION IS RELATIVE - for VSAM relative files (RRDS)._______________________________________________________________________________ COBOL 63
  • 64. User Manual for COBOL_______________________________________________________________________________7.8.2. ENVIRONMENT DIVISION ENTRIES FOR VSAMFILESExample :VSAM Sequential File SELECT S -FILE ASSIGN TO SEQUENTIAL - FILE ORGANIZATION IS SEQUENTIAL ACCESS IS SEQUENTIAL FILE STATUS KEY IS FSTAT - CODE VSAT - CODEExample :VSAM Indexed File SELECT I - FILE ASSIGN TO INDEXED - FILE 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 VSAM - CODEExample:- VSAM Relative File SELECT R - FILE ASSIGN TO RELATIVE - FILE ORGANIZATION IS RELATIVE ACCESS IS RANDOM RELATIVE KEY IS RFILE - RELATIVE - KEY FILE STATUS KEY IS FSTAT - CODE VSAM - CODE_______________________________________________________________________________ COBOL 64
  • 65. User Manual for COBOL_______________________________________________________________________________7.8.3. COBOL STATEMENTS USABLE WITH SEQUENTIALFILESAccess Mode COBOL / OPEN OPEN OPEN OPEN 370 INPUT OUTPUT I-O EXTEND StatementSequential OPEN X X X X WRITE X X START READ X X REWRITE X DELETE CLOSE X X X X7.8.4. COBOL STATEMENTS WITH INDEXED FILES(KSDS) AND RELATIVE (RRDS) Access COBOL/370 OPEN OPEN OPEN OPEN Mode Statement INPUT OUTPUT I-O EXTEND Sequential OPEN X X X X WRITE X X START x x READ X X REWRITE X DELETE x CLOSE X X X X Random OPEN X X X WRITE X X START READ X X REWRITE X DELETE X CLOSE X X X_______________________________________________________________________________ COBOL 65
  • 66. User Manual for COBOL_______________________________________________________________________________ Dynamic OPEN X X X WRITE X X START X X READ X X REWRITE X DELETE X CLOSE X X X7.8.5. PROCEDURE DIVISION STATEMENTS TO UPDATEVSAM FILESESDS KSDS RRDSACCESS IS SEQUENTIAL ACCESS IS SEQUENTIAL ACCESS ISSEQUENTIALOPEN EXTEND OPEN EXTEND OPEN EXTENDWRITE WRITE WRITECLOSE CLOSE CLOSEOPEN I - O OPEN I - O OPEN I - OREAD READ READREWRITE REWRITE REWRITE DELETE DELETECLOSE CLOSE CLOSEACCESS IS RANDOM ACCESS IS RANDOM ACCESS IS RANDOM OPEN I - O OPEN I - O READ READNot Applicable WRITE WRITE REWRITE REWRITE DELETE DELETE CLOSE CLOSEACCESS IS DYNAMIC ACCESS IS DYNAMIC ACCESS ISDYNAMICSequential processing Sequential processing Sequential processing OPEN I - O OPEN I - O_______________________________________________________________________________ COBOL 66
  • 67. User Manual for COBOL_______________________________________________________________________________ READ NEXT READ NEXTNot Applicable WRITE WRITE REWRITE REWRITE DELETE DELETE CLOSE CLOSEACCESS IS DYNAMIC ACCESS IS DYNAMIC ACCESS ISDYNAMICRandom processing Random processing Random processing OPEN I - O OPEN I - O READ NEXT READ NEXTNot Applicable WRITE WRITE REWRITE REWRITE DELETE DELETE CLOSE CLOSE7.8.6. ERROR PROCESSING FOR VSAMThe end - of - file - phrase ( AT END ) available .While file is read sequentially AT END CLAUSE is to be used to know whether a record is read.The EXCEPTION / ERROR declarative statement can be used to trap the errors in any I/O handling.The FILE STATUS clause (file status key and VSAM return code )can be used in ENVIRONMENTDIVISION to trap standard errors in all FILE HandlingThe INVALID KEY phrase can be used to trap the errors while COBOL reads a record at random.7.8.7. APPLICATIONS BEST SUITED TO VSAMDATASETS.7.8.7.1. ESDSApplications that require sequential access only. Example : Payroll Processing._______________________________________________________________________________ COBOL 67
  • 68. User Manual for COBOL_______________________________________________________________________________7.8.7.2. KSDSApplications that require that each record have a key field and require both direct and sequentialaccess.Applications that use High Level Languages which do not support RBA(Relative Byte Address)Applications that require ALTERNATE KEY to access any record . Example : BANK ACCOUNT TRANSACTIONS.7.8.7.3. RRDSApplications that require only Direct Access.Applications that have one to one correspondence between records.Applications that require that each record have a key field._______________________________________________________________________________ COBOL 68
  • 69. User Manual for COBOL_______________________________________________________________________________8. SUBPROGRAMSIn many cases, an application will consist of several separately compiled programs bound together.The program that calls another program is referred to as the calling program and the program it callsis referred to as the called program . This called program may itself call yet another program. In theProcedure Division, a program can call another program (generally called a subprogram in COBOLterms). When the called program is completed, the program can either transfer control back to thecalling program or end the run unit. No specific source code statements or options identify a COBOLprogram to be a main program or a subprogram.8.1. LINKAGE SECTION.Describes data made available from another programStorage for data items within the program is not reserved because the data area exists elsewhere .Value clause may not be specified for items other than level - 88 itemsExample:-IDENTIFICATION DIVISIONPROGRAM - ID. XYZLINKAGE SECTION01 PARAM1 PIC X(05)01 PARAM2 PIC 9(5)PROCEDURE DIVISION USING PARAM1 PARAM2....STOP RUNIDENTIFICATION DIVISIONPROGRAM -ID. ABC......PROCEDURE DIVISION .CALL XYZ USING A BSTOP RUN.8.1.1. STATIC / DYNAMIC CALLS_______________________________________________________________________________ COBOL 69
  • 70. User Manual for COBOL_______________________________________________________________________________To Transfer control from one COBOL program to another COBOL program you can use one of thesemethods :STATIC CALLThe Compiler treats the CALL Literal statement ( Where literal is the name of a subprogram ) as astatic call when the NODYNAM compiler option is in effect.DYNAMIC CALLA dynamic call loads the subprograms at run time.8.1.1.1. CALL BY REFERENCE OR BY CONTENT.If you want to pass an identifier’s value only to a called program, specify CALL . . . BY CONTENT identifier.If you want to pass a literal value to a called program, specify : CALL . . . BY CONTENT LENGTH OF Identifier.If you want to pass both item and its length to a subprogram, specify a combination of BYREFERENCE and BY CONTENTExample:-CALL ‘ ERRPROC’ USING BY REFERENCE A BY CONTENT LENGTH OF A Common Data Items in Subprogram Linkage Calling Program Description Called Program Description WORKING - STORAGE SECTION. LINKAGE SECTION USING - LIST. 01 PARAM - LIST. 10 PART - ID PIC X(5). 05 PARTCODE PIC A. 10 SALES PIC 9(5). 05 PARTNO PIC X(4). PROCEDURE DIVISION 05 U - SALES PIC 9(5). USING LIST PROCEDURE DIVISION CALL CALLED - PROG USING PARAM - LIST In the calling program the code for In the called program, the code for parts parts (PARTCODE) and the number and the part number are combined into one (PARTNO) are referred to separately data item (PART _ ID ). In the called program a reference to PART _ ID is the valid reference to them_______________________________________________________________________________ COBOL 70
  • 71. User Manual for COBOL_______________________________________________________________________________8.1.2. PASSING RETURN CODE INFORMATION.You can use the RETURN-CODE special register to pass and receive return codes between programs.When a COBOL / 370 program returns to its caller, the contents of the RETURN - CODE specialregister contains the return code of the called program.When control is returned to a COBOL program from a call, the contents of register 15 are stored intothe calling program ‘s RETURN - CODE special register.When control is returned from a COBOL program to the operating system, the special registercontents are returned as a user return code._______________________________________________________________________________ COBOL 71
  • 72. User Manual for COBOL_______________________________________________________________________________9. STRING , UNSTRING AND INSPECT STATEMENTS9.1. STRING STATEMENTString statement strings together the partial or complete contents of two or more DATA ITEMS orLITERALS into one single data item. FORMATSTRING IDENTIFIER1 DELIMITED BY IDENTIFIER 2LITERAL1 LITERALSSIZEINTO IDENTIFIER3 WITH POINTER IDENTIFIER4ON OVERFLOW IMPERATIVE STATEMENT1NOT ON OVERFLOW IMPERATIVE STATEMENT2END-STRINGIdentifiers should be with USAGE clause DISPLAYShould not be with picture clauseLITERALS should be non numeric literals/figurative constant except ALL(considers a character non numeric for figurative constant)THRU (all) should not be with P pictureIdentifiers 1 & 2 are representing sending fieldIdentifiers 3(last) is representing sending fieldDELIMITED BY phrase is used to limit the data to be transferredSIZE sends the complete sending area.INTO represents the receiving fieldPOINTER represents pointer field which represents the last character position in the receiving field.It should be an integer data item with enough picture clause to hold the countIt should be initialized to 1.It will return the length of the received data plus 1.OVER FLOW executed when pointer is < 1 or > the picture length of the receiving fieldSTRING ID-1 ID-2 DELIMITED BY SPACE ID-4 ID-5 DELIMITED BY SIZE INTO ID-7 WITH POINTER ID-8END-STRING._______________________________________________________________________________ COBOL 72
  • 73. User Manual for COBOL_______________________________________________________________________________9.2. UNSTRING STATEMENTUnstring statement causes contiguous data in a Sending Field to be separated and placed intomultiple receiving fields.UNSTRING IDENTIFIER1 DELIMITED BY ALL IDENTIFIER 2LITERAL1OR ALL IDENTIFIER-3LITERAL2INTO IDENTIFIER4 DELIMITER IN IDENTIFIER5 COUNT INIDENTIFIER6WITH POINTER IDENTIFIER7 TALLYING IN IDENTIFIER8ON OVERFLOW IMPERATIVE STATEMENT1NOT ON OVERFLOW IMPERATIVE STATEMENT2END-UNSTRINGIdentifiers should be with USAGE clause DISPLAYShould not be with P pictureLITERALS should be non numeric literals/figurative constant except ALL(considers a character non numeric for figurative constant)Identifier1 must be an alphanumeric itemMay not be reference modified. Represents the sending field.DELIMITED BY phrase is used to limit the data to be transferred .SIZE sends the complete sending area.INTO represents the receiving fieldPOINTER contains a value that indicates a relative position in the sending field.It should be initialized to 1It will return the length of the received data plus 1.All data receiving fields have been acted upon and the sending still contain the unexamined character.OVER FLOW executed when pointer is < 1 or > the picture length of the receiving fieldTALLYING in this count field is increased by the number of data receiving fields acted uponexecution.UNSTRING ID-SEND DELIMITED BY DEL-ID OR ALL “ * ” INTO ID-R1 DELIMITER IN ID-D1 COUNT IN ID-C1 ID-R2 DELIMITER IN ID-D2 ID-R3 DELIMITER IN ID-D3 COUNT IN ID-C3_______________________________________________________________________________ COBOL 73
  • 74. User Manual for COBOL_______________________________________________________________________________ ID-R4 COUNT IN ID-C4WITH POINTER ID-PTALLYING IN ID-TON OVERFLOW PERFORM FLOW-EXIT-PARAEND-UNSTRING.9.3. INSPECT STATEMENTThis statement specifies that characters or group of characters in a data item are to be counted or(tallied) or replaced or both.It will count the occurrences of a specific character(ALPHABETIC, NUMERIC OR SPECIALCHARACTER)It will fill all portions of data item with specified characters such as spaces or zeroes.It will convert all occurrences of specific characters in a data item to user supplied replacementcharacters.FORMAT1INSPECT IDENTIFIER1 TALLYING IDENTIFIER2FOR [ALL/LEADING] [IDENTIFIER3/LITERAL1] [PHRASE][PHRASE] here is AFTER / BEFORE [INITIAL]IDENTIFIER4/LITERAL2.Example:-INSPECT ITEM-1 TALLYING C1 FOR ALL SPACES.INSPECT ITEM-1 TALLYING C2 FOR ALL CHARACTERS.INSPECT ITEM-1 TALLYING C3 FOR LEADING SPACES.DATA ITEM1 BB56BB will yield 4 ,2,1 respectively.FORMAT 2INSPECT IDENTIFIER1 REPLACING CHARACTERSBY [IDENTIFIER2/LITERAL1]BEFORE/AFTER INITIAL [IDENTIFIER3 / LITERAL 2] AFTER /LEADING/FIRST [IDENTIFIER/LITERAL.]By IDENTIFIER/LITERAL [PHRASE]PHRASE] here is AFTER / BEFORE [INITIAL]IDENTIFIER4/LITERAL2.Example:-_______________________________________________________________________________ COBOL 74
  • 75. User Manual for COBOL_______________________________________________________________________________INSPECT ITEM-4 REPLACING “ - “ BY “ / “.DATA ITEM1 10-07-97OUTPUT 20 / 07 / 97_______________________________________________________________________________ COBOL 75
  • 76. User Manual for COBOL_______________________________________________________________________________9.4. DECLARATIVES It is used for tracing the paragraph or procedures executed by the program as per the Instruction given by the programmer. DEBUG-NAME is a special register storing the nameof the paragraph it is executing . We have to specify the Option " WITH DEBUGGING MODE" option in the OBJECT-COMPUTER Paragraph to include this option for Compilation. The following rules should be followed.It is a Section To Be Defined in Procedure Division.If this Section is in Procedure Division it should be the First Section.The rest of the paragraphs may be placed in User defined Section.The Debug Declarative -para should be immediate to the "USE" instruction.PROCEDURE DIVISION.DECLARATIVES.DEBUG -DECLARATIVES SECTION.USE FOR DEBUGGING ALL PROCEDURE .DEBUG -DECLARATIVES -PARA.DISPLAY “ TRACING “ DEBUG-NAMEEND DECLARATIVES.ACTUAL-PROCEDURE-PARA.This declarative section of the program will be executed before the start of execution of eachparagraph defined in the program. i.e. "TRACING paraname " will be displayed before the executionof each paragraph._______________________________________________________________________________ COBOL 76
  • 77. User Manual for COBOL_______________________________________________________________________________10. SORT AND MERGE STATEMENTSSORT 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 PROCEDUREor in an output file. This statement can appear anywhere in the PROCEDURE DIVISION except indeclarative section.FORMAT 1:SORT file-name-1 ON [ASCENDING/DESCENDING KEY] data-name-1[WITH DUPLICATES ] [IN ORDER COLLATING SEQUENCE ISalphabet-name-1]USING [filename-2 ] GIVING [file-name-3]FORMAT 2:SORT file-name-1 ON [ASCENDING/DESCENDING KEY] data-name-1[WITH DUPLICATES ] [IN ORDER COLLATING SEQUENCE ISAlphabet-name-1]INPUT PROCEDURE IS procedure-name-1 THRU procedure-name-2OUTPUT-PROCEDURE IS procedure-name-3 THRU procedure-name-4File-name -1 is the name given in the SD entry that describes the records to be sorted .data-name-1 specifies a KEY data item on which the SORT statement will be based .Each data name must identify a data item in a record associated with file-name -1There can be any number of datanames in file-name -1Can be used in ascending or descending statementThe first key referred is taken as major key and the next referred is taken as the next significant keyand so onSorting in ascending order will be done from lowest key value to highest key value.Sorting in descending order will be done from highest key value to lowest key value.Duplicates is specified to place the similar records in the order they are accessed.Alphabet-name1 must be specified in the alphabet clause of SPECIAL-NAMES para.USING and INPUT-PROCEDURE are mutually exclusiveFile-name-2 is the actual file to be sorted. Multiple files can specified.Input-Procedure is specified to Select or Modify the Input Record before Sort.This Procedure can do any modifications in the record and copy Using RELEASE Statement.Example:-SORT LEAVE-DETAIL-FILE ON EMP-NO LEAVE-TYPE_______________________________________________________________________________ COBOL 77
  • 78. User Manual for COBOL_______________________________________________________________________________USING EMPLOYEE-ABSENT-FILE GIVING LEAVE-SEQUENCE-FILE.LEAVE-DETAIL-FILE Should be specified in SD entry with Fields descriptions to know the keyposition.SD LEAVE-DETAIL-FILE01 LEAVE-RECORD 05 EMPNO PIC X(5). 05 EMPLOYEE-NAME PIC X(25) 05 LEAVE-TYPE PIC XX . 05 FILLER PIC X(48).FD EMPLOYEE-ABSENT-FILE01 ABSENT-RECORD 05 FILLER PIC X(80).FD LEAVE-SEQUENCE-FILE01 LEAVE-SEQ-RECORD 05 FILLER PIC X(80).GIVING and OUTPUT-PROCEDURE are mutually exclusive.File-name 3 is the actual output sorted file. FD entries should be present for these files.Output-Procedure is specified to Select or Modify the output Record After Sort.This Procedure can do any modifications in the record and copy Using RETURN Statement. ♦ FD entries should be coded for file-name-2 and file-name-3The MERGE statement is a PROCEDURE DIVISION statement which merges two or more inputfiles on some common key. The merged records are then written to an output file or made available toan output procedure.MERGE file-name-1 ON [ASCENDING/DESCENDING KEY] data-name-1USING file-name-2 file-name-3[COLLATING SEQUENCE IS Alphabet-name-1]GIVING file-name-4 /OUTPUT-PROCEDURE IS procedure-name-3 THRU procedure-name-4File-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. Multiple files can specified.File-name-4 is the actual output merged file. ♦ GIVING and POUTPUT-PROCEDURE are mutually exclusiveOther rules remain same as that of SORT statement._______________________________________________________________________________ COBOL 78
  • 79. User Manual for COBOL_______________________________________________________________________________11. INTRINSIC FUNCTIONSFrequently Used functions are Listed here for reference.11.1. Number HandlingLENGTH Returns the length of the Picture Clause FUNCTION LENGTH(NAME) Will return the Picture Clause value of NAME.MAX Returns the content of the argument that contains the maximum value Ex:- FUNCTION MAX(MARK)MIN Returns the content of the argument that contains the minimum value Ex:- FUNCTION MIN (MARK)NUMVAL Returns the numeric value represented by the alphanumeric character string specifiedin the argumentNUMVAL-C Returns the numeric value represented by the alphanumeric character string specifiedin the argument .Any optional Currency sign mentioned in argument 2 and decimal point are missedon conversion.11.2. Date / TimeCURRENT-DATE Returns 21 Chars alphanumeric Value 1..4 Year in the Gregorian Calendar 5, 6 month of the year 7, 8 Day of the Month 9,14 HHMMSS and so on.DATE-OF-INTEGER Converts a Date in the Gregorian Calendar from integer date form to standard date form yyyymmdd. 01-01-1601 =1 and 30,67,671=31-12-9999DAY-OF-INTEGER Converts a Date in the Gregorian Calendar from integer date form to standard date form yyyyddd 01-01-1601 =1 and 30,67,671=31-12-9999INTEGER-OF-DATE Reverse of DATE-OF-INTEGER_______________________________________________________________________________ COBOL 79
  • 80. User Manual for COBOL_______________________________________________________________________________INTEGER-OF-DAY Reverse of DAY-OF-INTEGER11.3. FinanceANNUITY FUNCTION ANNUITY(Argument1, Argument2) Argument1= Rate Of Interest Argument2 = No.of periods Formula is Argument1/(1-(1-Argument1)**Argument2 Or 1/argument2 if Argument1=0PRESENT - VALUE Returns a Value that approximate the present value of a series offuture period-end amounts specified by argument1 at a discount rate argument211.4. Mathematics & StatisticsCOS FACTORIAL INTEGER MEAN MEDIAN MIDRANGE RANDOMRANGESTANDARD - DEVIATION_______________________________________________________________________________ COBOL 80
  • 81. User Manual for COBOL_______________________________________________________________________________12. COMPILER OPTIONSA compiler directing Statement is a statement beginning with a compile directing verb (CBLProcess) that causes the compiler to take specific action during compilation.Compiler options can be coded in the Program itself but the action is controlled in the JCL asfollows.ADV = YES ♦ Instructs the compiler to add one byte to the record length for the printer control character. ♦ The option may be useful to programmers who use WRITE.ADVANCING in their source files. ♦ The first character of the record does not have to be explicitly reserved by the programmerADV = NO ♦ Instructs the compiler not to adjust the record length for WRITE.ADVANCING. ♦ The compiler uses the first character of the specified record area to place the printer control character. ♦ The application programmer must ensure that the record description allows for this additional byte. ♦ Default Value is Yes.ALOWCBL = YES ♦ Instructs the compiler to allow the use of the process ( or CBL) statements in COBOL programs ♦ Default is YesLIB ♦ It indicates that the source program contains COPY statementsSOURCE = YES ♦ It Indicates the listing of source statements should be included in compiler generated o/p. This listing also includes any statements embedded by COPY ♦ By default SOURCE = YESCMPR2 =YES ♦ Causes the compiler to generate code that is run-time compatible with valid VS COBOL II Version 1 Release 2 programs. ♦ Default CMPR2 = NOCOMPILE ♦ Indicates that you want full compilation including diagnostics and object codeNOC ♦ indicates that you want only a syntax checkNOC (W) NOC (E) NOC (S) ♦ Specifies an error message level : W is warning ; E is error : S is severe. When an error of the level specified or of a more severe level occurs, compilation stops and only syntax checking is done for the balance of the compilation ♦ Default COMPILE = NOC (S)_______________________________________________________________________________ COBOL 81
  • 82. User Manual for COBOL_______________________________________________________________________________CURRENCY ♦ Default symbol is the dollar sign ($). This option allows you to define an alternate default currency symbolDYNAM ♦ 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. However individual applications may experience some performance degradation due to a longer path length but overall system performance may be slightly improved.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._______________________________________________________________________________ COBOL 82
  • 83. User Manual for COBOL_______________________________________________________________________________13. APPENDIX13.1. ERROR CODESThe File Status Code attached to a file will have Picture Clause of length 2 digits.The first digit will denote the general category under which the return code falls.The second digit will denote the particular type of Error/Message under that category.The first digit category are as follows : 0 Returned When Successful Open / Read / Write / Operation. 1 Returned When At End Condition Fails 2 Returned When Index Key Fails 3 Returned When Permanent Open Error Occurs. 4 Returned When Logic Error in opening/closing/deleting etc 9 Implementator Defined0 Successful Open / Read / Write / Operation. 0 Successful Completion 2 A duplicate key was detected. 4 The length of the record just read did not conform to the fixed file attributes for the file. 5 The referenced optional file was not present when the OPEN statement was executed. If theopen mode is I-O or EXTEND, the file is created. (This does not apply to VSAM sequential files;file status 0 is returned.) 7 An OPEN or CLOSE statement was executed with a phrase that implies a tape file (i.NOREWIND, REEL/UNIT, or FOR REMOVAL but the referenced file is not a tape file.1 When At End Condition Fails 0 A sequential READ was attempted on an optional file that was not present or afterend of file was reached. 4 A sequential READ was attempted for a relative file and the relative record number islarger than the maximum number that can be stored in the relative key data item.2 This Error Will Occur When Index Key Fails1 A sequence error exists for a sequentially accessed indexed file.2 An attempt was made to WRITE a record that would create a duplicate key.3 An attempt was made to access a record that does not exist or an optional file that was not present.4 An attempt was made to WRITE beyond the boundaries for a relative or indexed file.3 Permanent Open Error Occurs._______________________________________________________________________________ COBOL 83
  • 84. User Manual for COBOL_______________________________________________________________________________ 4 An attempt was made to WRITE beyond the boundaries of a sequential file.5 An OPEN statement was attempted on a non-optional file that was not present. 7 An OPEN statement was attempted on a file that would not support the open modespecified in the OPEN statement. 8 An OPEN statement was attempted on a file previously closed with lock. 9 An OPEN statement was unsuccessful because of a conflict between the fixed file attributesand the attributes specified for the file in the program.4 Logic Error in opening/closing/deleting etc. 1 An OPEN statement was attempted for a file in the open mode. 2 A CLOSE was attempted for a file not in the open mode. 3 The last I/O statement executed for the file prior to the execution of a REWRITE orDELETE statement was not a successfully executed READ statement. 4 An attempt was made to REWRITE a record with an invalid length. 6 A sequential READ was attempted but no valid next record had been established.7 A READ was attempted for a file not open in the input or I-O mode. 8 A WRITE was attempted on a file not open in the I-O, output, or extend mode. 9 A DELETE or REWRITE was attempted on a file not open in the I-O mode.9 Implementator Defined0 No further information.1 VSAM password error.2 Logic error.3 VSAM resource not available.4 No file position indicator for sequential request.5 Invalid or incomplete VSAM file information.6 No DD statement specified for VSAM file.7 File integrity verified for VSAM file.13.2. EXERCISES:The following problems are only models. You can select similar problems and write programs.13.2.1. BASIC PROBLEM SOLVING 1. Write a program to ACCEPT your name and display the same the number of times you specify. Follow the Program Coding standard strictly. 2. Write a program to ACCEPT the following details from the user and compute payslip, showing the given details along with GROSS and NET. EMPLOYEE-NUMBER XXXXX. EMPLOYEE-NAME X(30)._______________________________________________________________________________ COBOL 84
  • 85. User Manual for COBOL_______________________________________________________________________________ EMPLOYEE-BASIC 99999. PERCENTAGE -OF- CCA 99. PERCENTAGE OF HRA 99. PERCENTAGE-OF-PF 99. ANY OTHER ALLOWANCE 9999. ANY OTHER DEDUCTION 9999. 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. Basic Condition :.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 More13.2.2. REPORT PREPARATION. 1. For the above programs give a proper report heading and column headings and print the report in the formatted form. 2. Use necessary edited picture clauses. Edit numeric data with comma for clarity._______________________________________________________________________________ COBOL 85
  • 86. User Manual for COBOL_______________________________________________________________________________13.2.3. ARRAY HANDLING. 1. Write a program to input the temperature for a week and display the temperature on any day of the week. 2. Find the day on which there was the highest temperature. 3. Expand the Table to Two dimensional array to accept week as well as the temperature on any day of the week. Display the temperature detail on Input.13.2.4. FILE HANDLING 1. Transfer the output of Problem 2 to a PS DATA SET. 2. Write a program to Input the data in a ESDS Dataset and display the Data. 3. Write a program to create a KSDS for the Stock Master File ITEM NUMBER XXXXX. ITEM NAME X(30). BALANCE QUANTITY 99999. UNIT OF MEASUREMENT XXX. 4. 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._______________________________________________________________________________ COBOL 86
  • 87. User Manual for COBOL_______________________________________________________________________________13.3. JCLIGYWCL is a catalogued procedure to Compile and Linkedit any COBOL Program.IGYWCLG is a catalogued procedure to Compile, Linkedit and execute any COBOL Program.JCL for IGYWCL//&SYSUIDZZ JOB CLASS=B,MSGCLASS=X,MSGLEVEL=(1,1),NOTIFY=&SYSUID,// REGION=2M,TIME=(00,45)//* ----------------------------------------------------------------//* ------------COMPILING & LINK EDITING----------------------------//* ----------------------------------------------------------------//* CHECK JOBNAME AND USERID BEFORE SUBMITTING//* THIS JCL COMPILES AD/CYCLE COBOL/370 PROGRAM SPECIFIED BY//* COB.SYSIN DD NAME AND PRODUCES LOAD MODULE IN THE DATA SET//* MEMBER SPECIFIED BY LKED.SYSLMOD DD NAME .//* ----------------------------------------------------------------//CMPCOB EXEC IGYWCL or IGYWCLG//COBOL.SYSIN DD DSN=&SYSUID.TRG1.COBOL(MEMBER1),DISP=SHR//LKED.SYSLMOD DD DSN=&SYSUID.TRG1.LOAD(MEMBER1),DISP=SHR//JCL for IGYWCLG//&SYSUIDZZ JOB CLASS=B,MSGCLASS=X,MSGLEVEL=(1,1),NOTIFY=&SYSUID,// REGION=2M,TIME=(00,45)//* ----------------------------------------------------------------//* ------------COMPILING ,LINK EDITING & EXECUTING----------------//* ----------------------------------------------------------------//* CHECK JOBNAME AND USERID BEFORE SUBMITTING//* THIS JCL COMPILES AD/CYCLE COBOL/370 PROGRAM SPECIFIED BY//* COB.SYSIN DD NAME AND PRODUCES LOAD MODULE IN THE DATA SET//* MEMBER SPECIFIED BY LKED.SYSLMOD DD NAME AND EXECUTES THE/* MEMBER.//* ----------------------------------------------------------------//CMPCOB EXEC IGYWCLG//COBOL.SYSIN DD DSN=&SYSUID.TRG1.COBOL(VTOCLIST),DISP=SHR//LKED.SYSLMOD DD DSN=&SYSUID.TRG1.LOAD(VTOCLIST),DISP=SHR//GO.SYSIN DD */*//_______________________________________________________________________________ COBOL 87
  • 88. User Manual for COBOL______________________________________________________________________________________________________________________________________________________________ COBOL 88

×