html5-img
1 / 96

COBOL (Common Business Oriented Language)

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

orinda
Télécharger la présentation

COBOL (Common Business Oriented Language)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. • 2An 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. FD EMP-FILE RECORDING MODE IS V LABEL RECORDS ARE STANDARD DATA RECORDS ARE EMP-RECORD BLOCK CONTAINS 0 RECORDS.   01 EMP-RECORD. 05 EMP-NO PIC 9(05). 05 FILLER PIC X(03). 05 EMP-NAME PIC X(15). 05 FILLER PIC X(03). 05 GRADE PIC 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 9 Data 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 Z Zero 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 • Example : MOVE AMT-IN TO AMT-OUT AMT-INAMT-OUT PIC 999 9(4) VALUE 123 0123 PIC 999v99 9(4)v999 VALUE 123^15 0123 150 PIC XXX X(4) VALUE ABC ABCb

  35. Arithmetic Verbs • ADD ·Elementary numeric data items alone can be added ·Numeric literals alone can be added ·Decimal point alignment is automatic • Arithmetic StatementABC 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 ABC 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 StatementA 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 • 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? • 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 • JUSTIFIED/JUST RIGHT CLAUSE Example : With a field description: 02 TITLE PIC X(10). The command: MOVE "JONES" TO TITLE Stores in TITLE a value equal to "JONESbbbbb", with the name left- justified; but, if the field description is: 02 TITLE PIC X(10) JUSTIFIED RIGHT. The above command stores in TITLE a value equal to "bbbbbJONES"

  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).

More Related