1 / 64

COBOL (COMMON BUSINESS ORIENTED LANGUAGE)

COBOL (COMMON BUSINESS ORIENTED LANGUAGE). Chapter-2. Contents. Divisions—General Formats. Level structure. Data Description Entries.—PITURE and VALUE Clause. Editing Characters. Special –names Paragraph, Classes and categories of Data. IDENTIFICATION DIVISION.

senona
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) Chapter-2

  2. Contents • Divisions—General Formats. • Level structure. • Data Description Entries.—PITURE and VALUE Clause. • Editing Characters. • Special –names Paragraph, Classes and categories of Data.

  3. IDENTIFICATION DIVISION • Provides identifying information about program. • Divided into paragraphs. • PROGRAM-ID only required paragraph . The entry in the PROGRAM-ID paragraph contains the program name to be used to identify the object program. • Other paragraphs are optional. • Used mainly for documentation purpose. • The division heading and paragraph names should be coded as area A entries.

  4. IDENTIFICATION DIVISION Format IDENTIFICATIONDIVISION. PROGRAM-ID. entry. [AUTHOR. entry.] [INSTALLATION. entry.] [DATE-WRITTEN. entry.] [DATE-COMPILED. entry.] [SECURITY. entry.]

  5. IDENTIFICATION DIVISION … Compiler takes this as Program Identifier. PROGRAM-ID comes immediately after ID Division. IDENTIFICATION DIVISION. PROGRAM-ID. PROG1. AUTHOR. R.R. BHATT. INSTALLATION. ABC CORP. DATE-WRITTEN. 01-JAN-2005. DATE-COMPILED. 01-JAN-2005. SECURITY. HIGH. OPTIONAL

  6. ENVIRONMENT DIVISION • The computer and all peripheral devices required by the program are described in this division. • This division is machine-dependent since devices differ from computer to computer. • It consists of 2 sections. • ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. entry. OBJECT-COMPUTER. entry. [SPECIAL NAMES. Entry]. [INPUT-OUTPUT SECTION. FILE-CONTROL. entry. [I-O-CONTROL. entry].]

  7. ENVIRONMENT DIVISION ENVIRONMENT DIVISION CONFIGURATION SECTION INPUT-OUTPUTT SECTION Identifies the computer used for compiling of programs Identifies the resources used for executing the program

  8. 1.CONFIGURATION SECTION This section contains an overall specification of the computer used for the purpose of compilation and execution of the program. • The SOURCE-COMPUTER paragraph specifies the name of the computer used to compile the COBOL program. • The OBJECT-COMPUTER paragraph describes the computer on which the program is to be executed. • The SPECIAL_NAMES is used to relate some hardware names to user-specified mnemonic names. This is optional in all computers. SOURCE-COMPUTER. ICL-1901. OBJECT-COMPUTER. ICL-1900. SPECIAL NAMES. DECIMAL-POINT IS COMMA.

  9. 2.INPUT-OUTPUT SECTION • INPUT-OUTPUT SECTION This section contains information regarding files to be used in the program. • The INPUT-OUTPUT SECTION consists of two paragraphs namely FILE CONTROL paragraph and I-O CONTROL paragraph. • In the FILE CONTROL paragraph a file name is selected for each file to be used in the program and assigned to a device. The simplified format of a file control entry is given below SELECT file-name ASSIGN TO hardware-name. • This section as a whole is optional in many computers.

  10. ENVIRONMENT DIVISION ENVIRONMENT DIVISION CONFIGURATION SECTION INPUT-OUTPUTT SECTION Identifies the computer used for compiling of programs Identifies the resources used for executing the program

  11. DATA DIVISION • The DATA DIVISION is used to describe the data structures used in the program. • There are sections in the DATA DIVISION • FILE SECTION • WORKING-STORAGE SECTION • LINKAGE SECTION • REPORT SECTION The two most commonly used components (sections) are a) WORKING-STORAGE SECTION Internal data structures are defined here. b) FILE SECTION File I/O buffer areas are defined here.

  12. DATA DIVISION • General Format DATA DIVISION. [ FILE SECTION. file section entries. ………….. ] [ WORKING-STORAGE SECTION. working-storage entries. ……….. ]

  13. PROCEDURE DIVISION The PROCEDURE DIVISION consists of the following • Sections • Paragraphs • Sentences • Statements General Format PROCEDURE DIVISION. [ section-name SECTION. [paragraph-name. [sentence] …. ] …. ]

  14. PROCEDURE DIVISION Section contain one or more Paragraphs. Section PROCEDURE DIVISION. 0001-ACCOUNT SECTION. 001-ACCOUNT-READ-PARA. READ ACC-FILE AT END MOVE ‘Y’ TO EOF. MOVE TAX-REDUCT TO TAX-AMOUNT 001-ACCOUNT-VALIDATE-PARA. ADD AMOUNT TO TOT-AMOUNT. ACCEPT EMPLOYEE-SALARY DISPLAY “Current Employee Salary “ EMPLOYEE-SALARY. 001-EXIT-PARA. STOP RUN. Paragraph A PARAGRAPH comprises of one or more sentences Sentences A SENTENCE is a combination of one or more statements and is terminated by a full stop. statement A STATEMENT is a combination of a COBOL verb and one or more operands.

  15. First COBOL program IDENTIFICATION DIVISION. PROGRAM-ID. FIRSTPG. PROCEDURE DIVISION. MAIN-PARA. DISPLAY ‘-------------------------------’. DISPLAY ‘ WELCOME TO COBOL’. DISPLAY ‘--------------------------------’. STOP RUN.

  16. DATA Description Entries • A data description entry describes a data item. • A component in this context is a level number, a data name or a clause. • Except for the level number, no other component can appear in area A. • There must be at least one space between any two consecutive components of an entry.

  17. Description of data names • All the data names used in the PROCEDURE DIVISION must be described in the DATA DIVISION. • The description of a data name is done with the aid of the following – (1) Level number (2) PICTURE clause (3) VALUE clause DATA DIVISION. 01 EMP-NO PIC X(10) VALUE 1001. VALUE Clause Picture Clause LEVEL NO Data Name

  18. DATA NAME  LEVEL NO Level number • It is a two-digit number starting from 01 .Is used to specify the data hierarchy. Level Number Purpose 01 Record description and independent items 02 to 49 Fields within records and sub items 66 RENAMES clause 77 Independent items 88 Condition names

  19. Picture Clause • The PICTURE Clause describes the general characteristics of an elementary data item. The characteristics are 1.CLASS—A data item may be one of the 3 classes. NUMERIC---Digits 0 to9. ALPHABETIC---A to Z & Space (Blank) Character. ALPHANUMERIC---Digits, Letters, Special Characters. 2.SIGN---A numeric data item can be signed or unsigned. Implicitly, unsigned, ie Positive. Sign can be specified in the PICTURE clause to describe a signed data item.

  20. Picture Clause 3.POINT LOCATION---The position of the decimal point is another characteristic that can be specified in the case of numeric data items. 4.SIZE---Which specify the number of characters or digits required to store the data item in the memory. General format for PICTURE clause PICTURE [PIC] IS character-string. • The PICTURE clause is only to be specified for elementary items. It can’t be used for a group item. • The size of a group item is equal to the total of the sizes of all subordinate elementary items. • The class of a group item is alphanumeric.

  21. Picture Clause Code Characters Meaning 9 Numeric A Alphabetic X Alphanumeric S (Signed) Sign bit V position of Assumed Decimal point P position of Assumed Decimal point when the point lies outside the data item

  22. Rules • 1. In Alphabetic item the picture may contain only A. • 2.In Numeric item the picture may contain only 9,V,P,S.These are called operational characters. It must contain at least one 9. and V & S can appear only once. And S, if it is included, must be the leftmost character of the picture string. The Symbol P can be repeated as many times as is required to indicate the position of the assumed decimal point. • 3. In Alphanumeric item, the picture may contain all Xs or a combination of 9, A and X (except all 9 or all A).

  23. Example 1.PIC IS S999V99 Means data is signed numeric with size 5 characters. The position of decimal point is before 2 places from the rightmost end. 2. PIC IS PPP999 Means data is of 3 characters in size & 6 positions after the assumed decimal point. Data is 234, the value will be taken as .000234. 3. PIC IS 999PP Data is 234, the value will be taken as 23400.

  24. COBOL ‘PICTURE’ Clauses • Some examples • PICTURE 999 a three digit (+ive only) integer • PICTURE S999 a three digit (+ive/-ive) integer • PICTURE XXXX a four character text item or string • PICTURE 99V99 a +ive ‘real’ in the range 0 to 99.99 • PICTURE S9V9 a +ive/-ive ‘real’ in the range ? • If you wish you can use the abbreviation PIC. • Numeric values can have a maximum of 18 (eighteen) digits (i.e. 9’s). • The limit on string values is usually system-dependent.

  25. Abbreviating recurring symbols • Instead of repeating 9, X,A or P in the picture string, it is possible to write the number of occurrences of a character enclosed within parentheses immediately after the said character. • Recurring symbols can be specified using a ‘repeat’ factor inside round brackets • PIC A(6) is equivalent to PICTURE AAAAAA. • PIC 9(6)V99 is equivalent to PIC 999999V99 • PICTURE X(10) is equivalent to PIC XXXXXXXXXX • PIC S9(4)V9(4) is equivalent to PIC S9999V9999 • PIC 9(18) is equivalent to PIC 999999999999999999

  26. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 999 VALUE ZEROS. 01 VatRate PIC V99 VALUE .18. 01 StudentName PIC X(10) VALUE SPACES. DATA Num1 VatRate StudentName 000 .18 Declaring DATA in COBOL • In COBOL a variable declaration consists of a line containing the following items; Œ A level number.  A data-name or identifier. Ž A PICTURE clause. • We can give a starting value to variables by means of an extension to the picture clause called the value clause.

  27. VALUE clause • Is used to assign an initial value to a elementary data item. Syntax: VALUE IS literal. • The initial value can be numeric literal, non- numeric literal or figurative constant. • Is an optional clause. • Examples: 1)VALUE IS 23.5. 2)VALUE IS “ Apples”. Or VALUE “Apples”. 3) VALUE ZERO.

  28. VALUE clause • If a VALUE clause is used at a group level , it should not be used for any item within the group. Only nonnumeric literals and figurative constants can be used to specify the value of a group item. Example—1). 03 num1 PIC S9(3)V99 VALUE -2.34. Here data item is level 3 elementary item belonging to a group. 2) 01 num2 VALUE IS “234567”. 02 data-1 PIC 9(2). ----- 23 } 02 data-2 PIC 9(3). ----- 456 } Values Stored 02 data-3 PIC 9(1). ----- 7 }

  29. Group and elementary items • In COBOL the term “group item” is used to describe a data item which has been further subdivided. • A Group item is declared using a level number and a data name. It cannot have a picture clause. • Where a group item is the highest item in a data hierarchy it is referred to as a record and uses the level number 01. • Picture clauses are NOT specified for ‘group’ data items because the size of a group item is the sum of the sizes of its subordinate, elementary items and its type is always assumed to be PIC X. WORKING-STORAGE SECTION. 01 EMPLOYEE-DETAILS PIC X(30). 01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12).

  30. Group Items/Records - Example WORKING-STORAGE SECTION. 01 EMPLOYEE-DETAILS PIC X(20). 01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12). Group item Sub-Items

  31. Group Items/Records - Example 123456789012345678901234567890 (cols) 1234JyothiS E&R Bangalore 2234Archana E&R Marathi 9999Bhushan E&R C++ Data in input file Variable for file read Value WORKING-STORAGE SECTION. 01 EMPLOYEE-DETAILS PIC X(30). 1234JyothiS E&R Bangalore

  32. Group Items/Records - Example Data in input file 123456789012345678901234567890 (cols) 1234JyothiS E&R Bangalore 2234Archana E&R Mysore 9999Bhushan E&R Chennai Variable for file read Value WORKING-STORAGE SECTION. 01 EMPLOYEE-DETAILS PIC X(30). 01 EMPLOYEE-DETAILS. 05 EMP-NUM PIC 9(4). 05 EMP-NAME PIC X(10). 05 EMP-DEPT PIC X(4). 05 EMP-LOC PIC X(12). 1234JyothiS E&R Bangalore 1234 JyothiS E&R Bangalore

  33. LEVEL Numbers & DATA hierarchy • In COBOL, Level numbers are used to express data hierarchy. The higher the level number, the lower the item is in the hierarchy. • So Group items contain sets of elementary items with lower level numbers. At the lowest level the data is completely atomic. WORKING-STORAGE SECTION. 01 POLICY-DETAILS. 05 POLICY-NO. 10 POLICY-TYP PIC X(4). 10 POLICY-LOC PIC X(2). 10 POLICY-ID PIC X(5). 05 POLICY-TYPE PIC X(10). 05 POLICY-EXPDT PIC X(10).

  34. Description of data names DATA DIVISION. WORKING-STORAGE SECTION. 01 REGNO PIC X(5). 01 NAME. 05 FIRST-NAME PIC A(15). 05 MID-NAME PIC A(15). 05 LAST-NAME PIC A(10). 01 AGE PIC 99V99. 01 SCHOLARSHIP PIC 9(4) VALUE 1000.

  35. Group Items/Records WORKING-STORAGE SECTION. 01 StudentDetails PIC X(26). StudentDetails H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F

  36. Group Items/Records WORKING-STORAGE SECTION. 01 StudentDetails. 02 StudentName PIC X(10). 02 StudentId PIC 9(7). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X. StudentDetails H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F StudentName StudentId CourseCode Grant Gender

  37. Group Items/Records WORKING-STORAGE SECTION. 01 StudentDetails. 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 StudentId PIC 9(7). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X. StudentDetails H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F StudentName StudentId CourseCode Grant Gender Surname Initials

  38. FILE SECTION • This contain a file description entry followed by one or more record description entries for each of the files used in a program. • Format for file description entry is FD file-name LABEL RECORDS ARE STANDARD RECORD IS OMITTED • The label indicator FD must begin in Area A and rest of the file description entry must appear only in Area B. • The file-name must be identical with the file name specified in the select clause of the ENVIRONMENT section. • STANDARD option should be specified for disk files, OMITTED option should be specified for card reader and printer files. • LABEL RECORD clause---it is mandatory in ANSI 74. Many compilers treat it as optional.

  39. FILE SECTION • The coding rule for an FD entry is similar to that of level 01 entry. • The description entries that follow the file description entry, should describe the record types in the file. There should be one record description entry for each type of record. • A record description entry is a 01 level group item along with all its subdivisions. • Example FD card-file. 01 card-records. 02 num pic 9(3). 02 price pic 9(2)v9(2) 02 amount pic 9(2)v9(2)

  40. WORKING-STORAGE SECTION • The data in the working storage can be group item, containing all its subdivisions same as record description. • There may also be elementary data item which do not belong to a group. Such data items should be defined at a special level number 77. • Level number 77 must begin in Area A. • Elementary item in this section need not always be defined at the level 77. It can as well be defined at the level 01.Example---- • WORKING-STIRAGE SECTION. 77 num PIC X(7). 01 date. 05 day pic 99. 05 month pic 99. 05 year pic 9999. 01 address pic x(10).

  41. EDITING PICTURE CLAUSE

  42. EDITING • The data to be printed in a report requires some editing. • Example—To print a numeric data item ,by suppressing the leading zeros. • Editing is normally performed by moving a numeric data item to a field containing special editing characters in its picture clause. • Following characters can be used in the PICTURE clause to indicate editing Z * $ - + CR DB . , B 0 /

  43. Edited picture symbols Edit symbol Meaning Z Zero suppression * Check protection , Comma insertion - Minus sign insertion + Plus or minus sign insertion

  44. Edited picture symbols

  45. Z-Zero suppression • The Z has the same meaning as that of 9 in the picture except that the leading zeros in the source data. • If any, in the digit positions indicated by Z will be suppressed—Replaced by space characters. • It is obvious that Z cannot appear to the right of any 9. • After the decimal point either the digit positions are indicated by all Z or none at all. • In the below examples The character b ---is used to indicate a space character. The character ^ ---is used to indicate the position of the decimal point.

  46. Z (Zero Suppression)---Example Edit symbol Value Edited value ZZ999 01234 b1234 ZZ999 00034 bb034 ZZ999 1^23 bb001 ZZZV99 12^3 b1230 ZZZV99 0^12 bbb12 ZZZZVZZ 0^01 bbbb01 ZZZZVZZ 0 bbbbbb

  47. *(Asterisk) Example • This is same as Z except that the leading zeros are replaced by * instead of space. Edit symbol Value Edited value **999 01234 *1234 **999 00012 **012 **999 1^23 **001

  48. $(Currency Sign) Example • A single currency sign can appear at the leftmost position of a picture. In that case the $ character is inserted. Edit symbol Value Edited value $99999 123 $00123 $99999 12345 $12345 $ZZ999 123 $bb123 $ZZ999 12345 $12345 $**999 123 $**123

  49. -(Minus Sign) Example • It can appear at leftmost or rightmost position of the picture. If the value of an item is –ve, a - sign will be inserted, If value is +ve, a space character will be inserted. Edit symbol Value Edited value -9999 -123 -0123 -9999 123 b0123 9999- -123 0123- 9999- 123 0123b -ZZZV99 -12^34 -b1234 -ZZZV99 12^34 bb1234

  50. +(Plus Sign) Example • It is same as minus sign except that when the item is +ve, + sign will be inserted. If value is –ve, - sign will be inserted,. Edit symbol Value Edited value +9999 -123 -0123 +9999 123 +0123 9999+ -123 0123- 9999+ 123 0123+ +ZZZV99 -12^34 -b1234 +ZZZV99 12^34 +b1234

More Related