Presentation is loading. Please wait.

Presentation is loading. Please wait.

COBOL (Common Business Oriented Language). 1. Introduction to COBOL History of COBOL Coding rules Program Structure Data names and Identifiers Figurative.

Similar presentations


Presentation on theme: "COBOL (Common Business Oriented Language). 1. Introduction to COBOL History of COBOL Coding rules Program Structure Data names and Identifiers Figurative."— Presentation transcript:

1 COBOL (Common Business Oriented Language)

2 1. Introduction to COBOL History of COBOL Coding rules Program Structure Data names and Identifiers Figurative constants

3 History of COBOL ANSI (American National Standards Institute) is an Organization for COBOL Standards. Like CODASYL, ANSI's COBOL committee consists of representatives of academia, user groups and computer manufacturers. In 1968 ------ The first ANS version of COBOL was developed and approved. In 1974 ------ A 2nd version of ANS COBOL was developed to make the Language more efficient and standardized. In 1985------ The 1985 version of ANS COBOL is now most widely used.

4 Coding Rules Columns 1 - 6 : Used for comment tags, sequence numbers, page or line numbers. Column 7 : Used for comment, continuation or starting a new page. 1. An asterisk ( * ) is used to denote a line as a comment. 2 An underscore ( _ ) is used for the continuation of non-numeric literals. A slash ( / ) is used to print subsequent instructions on the next page of the source listing Columns 8 – 11: These columns are referred as Area A. contd…

5 Coding Rules Columns 12 – 72 : These columns are also referred to as Area B. Entries such as 1. File names associates with FD or SD. 2. Level numbers 02 to 49, 66 and 88. 3. PROCEDURE DIVISION sentences. Columns 73 - 80 : Used to identify the program. These entries are optional and usually we omit this entry.

6 Structure of a Program Every COBOL Program consists of four separate divisions, each with specific function The Four Divisions : IDENTIFICATION DIVISION : Identifies the name of the program to the computer. It also can provide documentation about the program. ENVIRONMENT DIVISION: Defines the file-names and describes the specific computer equipment that will be used by the program.

7 Structure of a Program DATA DIVISION : Describes the input and output format to be used by the program. It also defines any constant and work areas necessary for the processing of data. PROCEDURE DIVISION : Contains the instructions necessary for reading input, processing it, and creating output. Each COBOL is coded on a single line using 80 characters per line.

8 Structure of a Program Following is the structure of a typical COBOL program. IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. author-name.] [INSTALLATION. installation-name.] [DATE-WRITTEN. written-date.] [DATE-COMPILED. compiled-date.] [SECURITY. authorization.] [REMARKS. prologue.] contd…

9 Structure of a Program ENVIRONMENT DIVISION CONFIGURATION SECTION. [SOURCE-COMPUTER. source- computer name.] [OBJECT-COMPUTER. object- computer name.] [SPECIAL NAMES. special-names entry.] [INPUT-OUTPUT SECTION. FILE-CONTROL. {file-control entry},... [I-O-CONTROL. input-output control entry.]] contd…

10 Structure of a Program DATA DIVISION. [FILE SECTION. file section entries.] [WORKING-STORAGE SECTION. working-storage section entries.] [LINKAGE SECTION. linkage section entries.] PROCEDURE DIVISION. [section name SECTION. [paragraph name. [sentence..... ]....]....]

11 Data names and Identifiers Data name A data name is a reference to the storage space in the memory where the actual value is stored. This value takes part in the operation when that particular data name is used in the PROCEDURE DIVISION. Identifier A data name can be qualified by another data name or can be indexed or subscripted. A data name qualified, indexed or subscripted is normally referred to as identifier.

12 Figurative Constants Figurative constants are literals representing values that may be frequently used by most programs. ZERO / ZEROS / ZEROES Represents the value 0 SPACE / SPACES Represents one or more spaces or blanks HIGH-VALUE / HIGH-VALUES Represents the highest value in the collating sequence LOW-VALUE / LOW-VALUES Represents the lowest value in the collating sequence For slides 1 to 12 refer chapter 3 in Roy & Dastidar.

13 2. COBOL Divisions Identification Division Environment Division Data Division Procedure Division Sample Program

14 Identification Division The IDENTIFICATION DIVISION is the first division of every COBOL source program. It is the smallest, simplest division of a COBOL source program Of all the paragraphs in this division, the paragraph PROGRAM-ID is essential contd…

15 Identification Division Example: IDENTIFICATION DIVISION. PROGRAM-ID. PHBOADR. AUTHOR. CSCI. INSTALLATION. CSCI. DATE-WRITTEN. 01-01-1997. DATE-COMPILED. 01-01-1997. SECURITY. RESTRICTED TO THE TRAINING DEPT. REMARKS. THIS PROGRAM ISSUES A POLICY.

16 Environment Division The ENVIRONMENT DIVISION must follow the IDENTIFICATION DIVISION in a COBOL source program. This is the only machine-dependent division of a COBOL program and contains two sections, viz., CONFIGURATION SECTION and INPUT-OUTPUT SECTION. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMP-FILE ASSIGN TO SYS022-DA- 3380-S-EMPFILE FILE STATUS W2- EMPFILE-STATUS. Note: for slides 14 to 16 refer chapter no.4

17 Data Division DATA DIVISION. The DATA DIVISION is that part of the COBOL program where every data item processed by the program is described. This division consists of three sections. FILE SECTION WORKING-STORAGE SECTION LINKAGE SECTION Contd…

18 Data Division DATA DIVISION. FILE SECTION. FDEMP-FILE RECORDING MODE IS V LABEL RECORDS ARE STANDARD DATA RECORDS ARE EMP- RECORD BLOCK CONTAINS 0 RECORDS. 01EMP-RECORD. 05 EMP-NOPIC 9(05). 05 FILLERPIC X(03). 05 EMP-NAMEPIC X(15). 05 FILLERPIC X(03). 05 GRADEPIC X(01).

19 Procedure Division  Contains statements, which specify the operations to be performed by the computer  Each of these statements is formed with COBOL words and literals  A statement always starts with a COBOL verb Contd…

20 Procedure Division PROCEDURE DIVISION. 0001-MAIN-PARA. DISPLAY "ENTER FIRST NUMBER" AT 0510. ACCEPT WS-SUM1. DISPLAY "ENTER SECOND NUMBER" AT 0710. ACCEPT WS-SUM2. COMPUTE WS-TOTAL = WS-SUM1 + WS- SUM2. DISPLAY "THE SUM IS "WS-TOTAL. STOP RUN. 0001-MAIN-EXIT-PARA. EXIT. Note: for slides 17 to 20 refer chapters 5 and 6.

21 Sample Program SAMPLE PROGRAM - 01 IDENTIFICATION DIVISION. PROGRAM-ID.EXAMPLE-01. AUTHOR. EMP991. DATE-WRITTEN 01-01-1999. DATE-COMPILED 01-01-1999. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER PMSI-PC-nn. OBJECT-COMPUTER PMSI-PC-nn. Contd...

22 Sample Program DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-ALL-VARS. 05 WS-SUM1 PIC 999. 05 WS-SUM2 PIC 999. 05 WS-TOTAL PIC 9(4). PROCEDURE DIVISION 0001-MAIN-PARA. DISPLAY "ENTER FIRST NUMBER" AT 0510. ACCEPT WS-SUM1. Contd...

23 Sample Program DISPLAY "ENTER SECOND NUMBER" AT 0710. ACCEPT WS-SUM2. COMPUTE WS-TOTAL= WS-SUM1 + WS-SUM2. DISPLAY "THE SUM IS "WS-TOTAL. STOP RUN. 0001-MAIN-EXIT-PARA. EXIT.

24 3. Data Definition and Editing File Section Working Storage Section Picture Clause Editing

25 File Section The FILE SECTION includes the descriptions of all data items that should be read from or written onto some external file. It contains the File Description (FD) entry for each file in the program followed by the record description.

26 Working-Storage Section & Linkage Section Any field necessary for processing that is not part of input or output, i.e., the data items which are developed internally as intermediate results, may be defined in the WORKING-STORAGE SECTION. The LINKAGE SECTION is an optional section in the DATA DIVISION. The LINKAGE SECTION describes data made available from another program or method.

27 Picture Clause Specified for every elementary data item. Code Character Meaning 9Data item contains a numeral X Data item contain any allowable character from the COBOL character set. A Data item contains only a letter or space V Data item contains an assumed decimal point S Data item is signed (specified as the left most character)

28 Editing Editing Symbols Need for editing data Edit Types Numeric Data ZZero Suppression * Asterisk $ Currency sign - Minus sign + Plus sign CR DB Credit Debit Sign B Z / Blank, Zero, Slash Insertion

29 Editing Pic of the Field Numeric Value Edited Value 9999CR -4625 4625CR 9999CR 4625 4625bb ZZZCR -42 b42CR ZZ9V99DB -152^25 15225DB ZZZ9V99DB -152^25 b15225DB Note: for slides from 24 to 29 refer chapter 5.

30 4.Procedure Division and Basic Verbs Structure of Procedure Division Move Statement Arithmetic Verbs Control verbs I/O verbs Conditional verbs

31 Structure of procedure Division The following format shows the simplified structure of the Procedure Division. PROCEDURE DIVISION. [Paragraph-name. [sentence] …]… A paragraph can consists of one or more sentences that constitute its body.

32 MOVE Statement  Copies the contents of one data item (the sending field) to another data item (the receiving field), keeping the contents of the first data item unchanged Syntax MOVE { identifier-1 } TO identifier-2 [,identifier-3]... { literal-1 } Sending Field Receiving Field contd…

33 MOVE Statement Moving an integer  Movement is from right to left (right aligned)  Non-filled higher-order (leftmost) integers are replaced by 0s Moving a decimal  Movement is decimal aligned  Non-filled lower-order (rightmost) integers are replaced by 0s contd…

34 MOVE Statement

35 Arithmetic Verbs ADD  Elementary numeric data items alone can be added  Numeric literals alone can be added  Decimal point alignment is automatic Arithmetic Statement A B C ADD A TO B C A B+A C+A ADD A TO B A B B+A GIVING C

36 Arithmetic Verbs SUBTRACT  Elementary numeric data items alone can be subtracted  Numeric literals alone can be subtracted  Decimal point alignment is automatic Arithmetic Statement A BC SUBTRACT A B A B C-(A+B) FROM C

37 Arithmetic Verbs MULTIPLY  Elementary numeric data items alone can be multiplied.  Numeric literals alone can be multiplied.  Decimal point alignment is automatic. Arithmetic Statement A B C MULTIPLY A BY B A B A*B GIVING C

38 Arithmetic Verbs DIVIDE Arithmetic Statement A B C DIVIDE A INTO B C A B/A C/A DIVIDE A BY B A B A/B GIVING C

39 Arithmetic Verbs Compute  Combination of more than one arithmetic operation in a single statement.  Shortens programs, avoids intermediate data names. Example : COMPUTE A = 2 + (3 * 5).

40 Control Verbs The statements are executed sequentially one after another. This sequence can be altered with the help of Control Verbs. PERFORM EXIT GO TO STOP

41 I/O Verbs DISPLAY ACCEPT OPEN READ WRITE CLOSE

42 Conditional Verbs IF followed by END-IF. Nested IF sentence. EVALUATE followed by END-EVALUATE. Note: for slides 30 to 42 refer chapter 6.

43 5. Writing a sample Program IDENTIFICATION DIVISION. PROGRAM-ID.EXAMPLE-01. AUTHOR. RAJU. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER PMSI-PC-nn. OBJECT-COMPUTER PMSI-PC-nn. contd…

44 Writing a sample program DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-ALL-VARS. 05 WS-SUM1 PIC 999. 05 WS-SUM2 PIC 999. 05 WS-TOTAL PIC 9(4). contd…

45 Writing a sample Program PROCEDURE DIVISION 0001-MAIN-PARA. DISPLAY "ENTER FIRST NUMBER" AT 0510. ACCEPT WS-SUM1. DISPLAY "ENTER SECOND NUMBER" AT 0710. ACCEPT WS-SUM2. COMPUTE WS-TOTAL= WS-SUM1 + WS-SUM2. DISPLAY "THE SUM IS “ WS-TOTAL. STOP RUN. 0001-MAIN-EXIT-PARA. EXIT.

46 Exercise - 1 1) Accept data from the user in the format DDMMCCYY. Find difference between the current date and the user date in terms of number of days? 2) Accept a number( N between 1 - 99) from the user and write a multiplication table for the given number. Example 1 * 20 = 20 2 * 20 = 40 | | 20 * 20 = 400 Note: for slides 43 to 46 refer chapter 7

47 6. More About Data Division USAGE Clause JUSTIFIED clause REDEFINES RENAMES

48 USAGE clause USAGE IS COMPUTATIONAL/COMP COMP COMP-1 COMP-2 COMP-3

49 Justified clause

50 REDEFINES It is used for the purpose of conservation of storage space. Example: 01 SALES-RECORD. 02 SALES-TYPE PIC X. 02 SALES-BY-UNIT 03 QTY PIC 9(4). 03 UNIT-PRICE PIC 9(8)V99. 02 TOTAL-SALES REDEFINES SALES-BY- UNIT. 03 AMOUNT PIC 9(10)V99. 03 FILLER PIC X(2).

51 RENAMES Regrouping of elementary data items. It must be used with the special level number 66. 66 data-name-1 RENAMES data-name-2 THRU data-name-3. Note: for slides 47 to 51 refer chapter no. 8

52 7. TABLE Handling OCCURS Clause PEFORM verb INDEXING SET verb SEARCH SEARCH ALL

53 OCCURS Clause TO be used for putting data in a tabular format. This clause cannot be specified for an item whose level number is 01, 66, 77 and 88. Example : 01 DIRECT-TAX-RATE 02 TAX-RATE PIC 99 OCCURS 10 TIMES.

54 PERFORM Different types of PERFORM Statements. PERFORM PROCEDURE-NAME-1. PROCEDURE-NAME-1 is executed only once. PERFORM PROCEDURE-NAME-1 N TIMES. PROCEDURE-NAME-1 is executed N number of times. contd…

55 PERFORM The other types of PERFORM statement PERFORM PROCEDURE-NAME-1 THRU PROCEDURE-NAME-2. PERFORM PROCEDURE-NAME-1 UNTIL Condition. PERFORM PROCEDURE-NAME-1 with VARYING option.

56 INDEXING INDEX: It is a Data item associated with a table, denotes a displacement of the element from the beginning of the table. Example : 01 EMP-TABLE. 02 DEPT OCCURS 10 TIMES INDEXED BY D1. 03 MANAGER OCCURS 5 TIMES INDEXED BY M1.

57 SET Verb This Verb is used to set, increase or decrease the values of the Indexes. Examples : SET D1 to 4. SET D1 UP BY 2. SET D1 DOWN BY 2.

58 SEARCH This verb is used to locate elements in table. It will Search the elements in the table sequentially. Example : PARA-REPEAT. SEARCH ACCOUNT-TABLE AT END GO TO PARA-REPEAT-EXIT WHEN AMOUNT (A1) > 5000 ADD 1 TO TOTAL-NUM SET A1 UP BY 1. GO TO PARA-REPEAT. PARA-REPEAT-EXIT.

59 SEARCH ALL This verb is used to locate elements in table. The table should be in some order(ascending/descending). The advantage is total comparisons are less compared to sequential Search. Example : PARA-REPEAT. SEARCH ALL ACCOUNT-TABLE AT END GO TO PARA-REPEAT-EXIT WHEN AMOUNT (A1) > 5000 ADD 1 TO TOTAL-NUM SET A1 UP BY 1. GO TO PARA-REPEAT. PARA-REPEAT-EXIT.

60 Exercise - 2 1) Write a program to accept 2 3x3 matrices and add them. Program should accept maximum of 3 digit number excluding sign digit.Display the result on the screen in the matrix form. 2) Accept N 3 digit number excluding sign from the user. Accept one more number from the user to search, whether that number is already in the entered numbers using BINARY SEARCH (SEARCH ALL). Note: for slides 53 to 60 refer chapter no.11

61 8. Structured Programming Enabling optimisation of code by presenting the logic in the most structured way possible. Using the three kinds of control structures that facilitate Structured Programming namely. Simple Sequencing Selection Repetition

62 Simple Sequencing Simple Sequencing is a sequence of of two or more operations. Example............ 0001-MAIN-PARA. PERFORM 0002-OPEN-PARA. PERFORM 0003-PROCESS-PARA. PERFORM 0004-CLOSE-PARA............. : in sequence of execution

63 Selection Execution of one of two operations depending on a condition Example............ IF WS-EOF = "N" PERFORM 0002-OPEN-PARA ELSE PERFORM 0003-DISPLAY-PARA............

64 Repetition Continually performing an operation until a certain condition holds true Example............ PERFORM 0002-OPEN-PARA UNTIL WS-EOF = "Y" : iteration of a para (set of instructions) till a condition is true.

65 Exercise - 3 1) Write a program to calculate sales tax based on entered sales-amount and Tax-rates. Sales-tax = Sales-Amount * Tax-Rates Validate the Sales-Amount is in between 1 to 10000 and Tax-Rate is 1 to 20%. If the entered data is invalid then it should display proper message like “Invalid entry”.

66 Exercise – 3 (Optional) 2) Write a program by using Evaluate verb to calculate electricity bill rate based on number of units. No-of-units(1 to 100) the rate per unit is 1 Rs. 101 to 200 “ is 2 Rs. 201 to 500 “ is 2.5 Rs. 501 to Any “ is 3.5 Rs Accept the data like name and no-of units from the user calculate Bill Amount. Bill-Amount = No-of-units * rate per unit. Note: for slides 61 to 66 refer chapter no.12

67 9. Sequential Files Important features are:  Records are stored serially-one after the other.  Used when data volume is very high or when all the records stored in the file are to be processed. File-Control entries File Description Statements for Sequential Files Example of Sequential File

68 File-control Entries Organization Access File Status SELECT FILE-NAME ASSIGN TO HARDWARE-NAME [; ORGANIZATION IS SEQUENTIAL ] [;ACCESS MODE IS SEQUENTIAL ] [;FILE STATUS IS Data-name- 1]

69 File Description Block Contains Record Contains Label Record FD File-name [; BLOCK CONTAINS integer-1 {RECORDS/CHARACTERS} ] [; RECORD CONTAINS integer-2 {CHARACTERS} ] [; LABEL RECORDS ARE {STANDARD/OMITTED}]

70 Statements for Sequential File OPEN READ WRITE REWRITE CLOSE

71 Statements for Sequential File OPEN { INPUT } file-name-1, [,filename-2]… { OUTPUT } { EXTEND } { I-O } READ file-name RECORD [ INTO identifier- 1 ] AT END imperative-statement

72 Statements for Sequential File WRITE record-name [ FROM identifier ] REWRITE record-name [FROM identifier ] CLOSE file-name-1 [, file-name-2 ] …

73 Exercise - 4 1)Write a program to create a data file which contains the Name of the person and Phone number by accepting data from the user. 2) Write a program to read records from the Input-file and write the records in the output-file. product-amount = quantity-in- hand * unit-price input-file output file Position Field position field 1-10 product name 11-25 description 11-13 spaces 26-30 quantity in hand 14-28 description 31-36 price/unit 29-33 spaces 34-41 product-amount Note: for slides 67 to 73 refer chapter no.13

74 10. Sorting and Merging of Files Simple SORT Verb Simple Merge Verb INPUT and OUTPUT Procedures in SORT statement MERGE Verb with Output Procedure

75 SORT Verb It is used for Sorting an Input-file, after sorting a new Output file is created contains the records in sorted order. SORT file-name-1 ON {ASCENDING/DESCENDING} KEY data-name-1 [,data-name-2]… USING file-name-2 GIVING file- name-3. Here file-name-1 is the Work file, defines under SD entry. File-name-2 is the Input file and File-name-3 is the Output file.

76 Merge Verb It is used to Merge two or more Input files. MERGE file-name-1 ON {ASCENDING/DESCENDING} KEY data-name-1 [,data-name-2]… USING file-name-2, file-name-3 [,file-name-4 ] GIVING file-name-5. Here file-name-1 is the Work file, define under SD entry. file-name-2, file-name-3 are the Input file and file-name-4 is the Output file.

77 INPUT OUTPUT Procedures INPUT PROCEDURE: The records which meet certain conditions are to be selected for sorting. RELEASE statement is part of the INPUT PROCEDURE OUTPUT PROCEDURE: Used for editing of sorted records. RETURN statement is a part of OUTPUT PROCEDURE Only Output Procedure is used in MERGE statement. Note: for slides from 74 to 77 refer chapter no.14

78 11. Direct Access Files RELATIVE FILES INDEXED FILES I/O statements for different File Organizations

79 Relative Files Organized in such a way each record is identified by a relative Record number.  The relative record number specifies the position of the records from the beginning of the file. FILE-CONTROL for Relative files Example: SELECT HISTORY ASSIGN TO DISK ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS REL-POSITION

80 Relative Files PROCEDURE DIVISION for Relative files READ WRITE REWRITE DELETE START contd…

81 Relative Files READ READ file-name RECORD [ INTO identifier ] [ ; INVALID KEY imperative- statement ] WRITE WRITE record-name [ FROM identifier ] [ ; INVALID KEY imperative- statement ] REWRITE REWRITE record-name [ FROM identifier ] [ ; INVALID KEY imperative- statement ]

82 Relative Files DELETE DELETE file-name RECORD [ ; INVALID KEY imperative-statement ] START START file-name [ KEY IS { EQUAL TO / } data-name ] GREATER THAN / NOT LESS THAN [ ; INVALID KEY imperative- statement ]

83 INDEXED Files Records are accessed by the value of one or more keys within them. FILE-CONTROL for Indexed files Example: SELECT HISTORY ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS data-name-1 ALTERNATE RECORD KEY IS data name-2

84 INDEXED Files PROCEDURE DIVISION for Indexed files READ WRITE REWRITE DELETE START The syntax is same as Relative files. Note: for slides 78 to 84 refer chapter no.16

85 I/O statements for different files FILE ACESS TABLESequential Organization Indexed Organizatio n Relative Organizat ion Statement Open Modes I0I- O EIO IO FILEFILE Seque ntial READ WRITE REWRI TE START DELETE X X XXXX X XXXX X XXXXXXXX XXXX X XXXXXXXX ACCESSACCESS Rand om READ WRITE REWRI TE START DELETE X X XXXXXXXX X X XXXXXXXX MODEMODE Dyna mic READ WRITE REWRI TE START DELETE XXXX X XXXXXXXXXX X X XXXXXXXXXX

86 12. Character Handling A string refers to a sequence of characters. We can do string manipulations by using the following verbs. Examine Inspect String Unstring

87 Examine Verb EXAMINE Verb It is used to scan a string to find the number of occurrences of a given character. It is also used to replace some or all occurrences of a said character. Example : 01 NAME PIC X(5) VALUE IS “DAVID”. EXAMINE NAME TALLYING ALL “D” REPLACING BY “H” After the execution the contents of NAME is HAVIH and TALLY register contains 2.

88 INSPECT Verb It is used to tally and/or replace the the occurrence of a single or group of characters in a data field. Example : 01 MY-STRING PIC X(20) VALUE IS “ BACDABCZPABCABCPQ.“ INSPECT MY-STRING TALLYING TALLY-1 FOR ALL “ABC” BEFORE INITIAL “.” AFTER INITIAL “Z”. After execution TALLY-1 contains 02.

89 STRING

90 UNSTRING Splits the contents of a data item into separate character strings and stores them. Example : 01 WS-A PIC X (13) VALUE 'HUMPTY DUMPTY' 01 WS-B PIC X (6) 01WS-C PIC X (6) UNSTRING WS-A DELIMITED BY ' ' INTO WS-B WS-C. After execution WS-B contains HUMPTY and WS-C contains DUMPTY.

91 Reference Modification It is possible to refer part of a data field by specifying the leftmost character position and length. Example : 01 DATA-FIELD1 PIC X(11) VALUE “MATHEMATICS”. MOVE DATA-FIELD-1(4:2) TO DATA- FILED-2. After the execution the value “HE” is moved to DATA-FIELD-2. Note: for slides 86 to 91 refer chapter no.17

92 13. Subroutines Structure of a COBOL Subroutine Calling of a Subroutine State of a Subroutine and Cancel statement

93 Structure of a Subroutine The PROCEDURE DIVISION header must have using phrase. The format is PROCEDURE DIVISION [ USING data- name-1 [, data-name-2]…] Data-name-1 and data-name-2 must be defined in the LINKAGE SECTION of called Program. The corresponding data items in the calling program may be defined in any section of the DATA DIVISION.

94 Calling a Subroutine Main program(calling program) will call the subroutine by using CALL statement. Actual Parameters The data-names defined in the Calling Program which is establishing connection with formal parameters. Formal parameters The data items defined in the Linkage section of the Called program. Example : CALL “CALDA” USING GROSS-PAY D-A.

95 Cancel Statement When a subroutine is called for the first time, it is said to be in its initial state.When same subroutine is called next, it will be in its last used state. CANCEL : Used for setting the subroutine in its initial state rather than the last used state. CANCEL { identifier-1 / literal-1 } [, identifier-2 / literal-2 ]… Note: for slides from 92 to 95 refer chapter no.19

96 COBOL END


Download ppt "COBOL (Common Business Oriented Language). 1. Introduction to COBOL History of COBOL Coding rules Program Structure Data names and Identifiers Figurative."

Similar presentations


Ads by Google