1 / 29

COBOL (COMMON BUSINESS ORIENTED LANGUAGE)

COBOL (COMMON BUSINESS ORIENTED LANGUAGE). Chapter-1. Text Books. M.K.Roy and D. Ghosh Dastidar , COBOL Programming , Tata McGraw Hill , 2001, COBOL—85,2 nd Edition. Nancy Stern and Robert A Stern , 8 th edition, Structured COBOL Programming , John Wiley & Sons , 1998. Contents.

angelo
Download Presentation

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-1

  2. Text Books • M.K.Roy and D. Ghosh Dastidar, COBOL Programming, Tata McGraw Hill, 2001, COBOL—85,2nd Edition. • Nancy Stern and Robert A Stern, 8th edition, Structured COBOL Programming, John Wiley & Sons, 1998.

  3. Contents • History of COBOL • Features & Language Fundamentals • Program Structure • Coding Format for COBOL Programs • Character Set, Words, Data Names, Literals.

  4. Nature of COBOL • popular Business-oriented language • Standard language • English-like language • Relatively easy to understand

  5. History of COBOL • 1959 – United States Department of Defense • 1960 - COBOL initial specifications presented by CODASYL (Conference on Data Systems Languages) • 1964 – BASIC COBOL extended to Visual COBOL • 1968 – ANSI (American National Standards Institute) developed American National Standard (ANS) COBOL • 1974 – ANSI published revised version of (ANS) COBOL – Business applications needed to manipulate character as well as numeric data – String operations added • 1985 – COBOL 85 Standards was introduced with revised version of COBOL-74.

  6. COBOL • What does COBOL stand for? COmmon Business Oriented Language. • Which are target area of COBOL applications? Defense, Aircraft, Insurance, Finance, Retail etc (file & data oriented applications involved) • So we can say that COBOL is basically used for writing business applications and not for developing system software

  7. COBOL – Program Structure PROGRAM Principal portions of a program. There are 4 divisions – • Identification (Required) • Environment (Optional) • Data (Optional) • Procedure (Required) DIVISIONS User defined chunk of code which consists of one/more paragraphs. e.g. a) U000-CHECK-LOG SECTION. b) FILE SECTION. SECTIONS User defined chunk of code which consists of one/more sentences. e.g. a) P000-PRINT-FINAL-TOTALS. b) PROGRAM-ID. PARAGRAPHS A SENTENCE consists of one or more statements and is terminated by a full stop. e.g. a) MOVE .21 TO VAT-RATEb) COMPUTE VAT-AMOUNT = PRODUCT-COST * VAT-RATE. A STATEMENT consists of a COBOL verb and an operand or operands. e.g. SUBTRACT T-TAX FROM GROSS-PAY GIVING NET-PAY SENTENCES RESERVED WORDS CHARACTERS STATEMENTS USER DEFINED WORDS

  8. Example IDENTIFICATION DIVISION. PROGRAM-ID. Multiplier. DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 PIC 9 VALUE ZEROS. 01 Num2 PIC 9 VALUE ZEROS. 01 Result PIC 99 VALUE ZEROS. PROCEDURE DIVISION. DISPLAY "Enter first number (1 digit) : " . ACCEPT Num1. DISPLAY "Enter second number (1 digit) : “. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN.

  9. COBOL CHARACTER SET Overview

  10. COBOL coding sheet

  11. COBOL coding rules • Each line is considered to be made up of 80 columns. • Columns 1 to 6 are reserved for sequence numbers.1 to 3 ---Page Number. 4 to 6 ---Line Number • Column 7 is an indicator column and has specialmeaning to the compiler.Hyphen ( - ) indicates continuation. Slash ( / ) indicates comment line, the comment line will be printed after page ejection. Asterisk ( * ) indicates comment line, no such page ejection. • Columns 8 to 11 are called Area A. All COBOL DIVISIONs, SECTIONs, paragraphs and some special entries must begin in Area A. • Columns 12 to 72 are called Area B. All COBOL statements must begin in Area B.

  12. COBOL coding sheet Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are - AREA A *) Between Column 8 to 11 *) Division, Section, Paragraph names, FD entries & 01 level entries must start in Area A AREA B *) Between Column 12 to 72 *) All Sentences & Statements start in Area B

  13. coding rules • Columns 73 to 80 are identification area. Anything written in this area , will be ignored by the compiler but will appear in the source listing. • Columns 1-6 and 73-80 optional and rarely used today • Column 7 for continuation, comment, starting new page • Columns 8-72 for COBOL program statements Column 7 * (asterisk) designates entire line as comment / (slash) forces page break when printing source listing - (dash) to indicate continuation of nonnumeric literal

  14. Margin Rules • Columns 8-72 divided into two areas • Area A - columns 8, 9, 10, 11 • Area B - columns 12-72 • Division, section and paragraph-names must all begin in Area A • First letter of name must begin in column 8, 9, 10 or 11 • Entry may extend into Area B • All other statements, clauses, and sentences begin anywhere in Area B (column 12, 13, 14, etc.) • Select entries in ENVIRONMENT DIVISION • Data description entries in DATA DIVISION • All PROCEDURE DIVISION instructions

  15. Data names and Identifiers • Data names Are named memory locations. • Data Names must be described in the DATA DIVISION before they can be used in the PROCEDURE DIVISION. • Can be of elementary or group type. • Can be subscripted for Arrays. • Are user defined words (refer Rules) . • Indexed or subscripted is normally referred to by the general term identifier. • Example---A12, sum-natural, net-pay,…

  16. Rules for forming User-defined words/Data names • Can be at most 30 characters in length. • At least one alphabetic character. • Only alphabets, digits and hyphen are allowed. • Blanks are not allowed. • May not begin or end with a hyphen. • Should not be a COBOL reserved word like ADD,SUBTRACT,MOVE,DISPLAY etc….

  17. Data-Name Guidelines • Use meaningful data-names that describe contents of field • Use prefixes or suffixes in data-names when appropriate • -IN and -OUT for fields (Emp-Salary-IN and Emp-Salary-OUT) • -FILE and -RECORD for file and record names (Emp-File and Emp-Record) • Amount-Due-In instead of A1

  18. Identify the valid data-names • Identify the valid data-names • Date-Of-Birth • Amount$Out • -First-Name • 98-6 • Time out • ADD

  19. Literals • Literals are symbols whose value does not change in a program. • A data name may have different values at different points of time whereas a literal means the specific value which remains unchanged throughout the execution of the program. For this reason a literal is often called a constant. Example--- MOVE 0 to sum. (Here 0 is literal) • There are 3 types of literals namely (1) Numeric literals. (2) Non-numeric literals. (3) Figurative constants.

  20. Rules for Numeric Literals • A numeric literal can be formed with the help of digits only. • The maximum number of digits allowed in a numeric literal varies from compiler to compiler. can have a maximum of 18 digits. • + or - sign may be included to left of first digit. • Decimal point permitted within literal. May not follow last digit.Valid numeric literals23 , +2359.4 , .125 , -68734

  21. Rules for Nonnumeric Literals • Composed of characters which are enclosed within quotation marks. • Generally used for output messages or headings. • Any character in COBOL character set except quotation mark. • The maximum number of characters that are allowed is compiler dependent. ANSI 74-120 characters.Valid Nonnumeric Literals “123 Main St.” “$14.99” “12,342” “Enter a value from 1 to 10”

  22. Figurative Constants • These are literals representing values that may be frequently used by most programs. • These are given some fixed names and when the compiler recognizes these names it sets up the corresponding values in the object program. • Example--- MOVE ZERO TO sum. • The following is the list of figurative constants and their meanings.

  23. Literals – Figurative Constants Figurative constants Meaning ZERO(S) or ZEROES Represents the value 0, one or more depending on the context SPACE(S) Represents one or more spaces HIGH-VALUE(S) Represents the highest value LOW-VALUE(S) Represents the lowest value QUOTE(S) Represents single or double quotes ALL literalFill With Literal

  24. 01 GrossPay PIC 9(5)V99 VALUE 13.5. MOVE TO GrossPay. ZERO ZEROS ZEROES StudentName M I K E ¨ ¨ ¨ ¨ ¨ ¨ Figurative Constants - Examples GrossPay 0 0 0 1 3 5 0 ñ l 01 StudentName PIC X(10) VALUE "MIKE". MOVE ALL "-" TO StudentName.

  25. 01 GrossPay PIC 9(5)V99 VALUE 13.5. MOVE TO GrossPay. ZERO ZEROS ZEROES StudentName - - - - - - - - - - Figurative Constants - Examples GrossPay 0 0 0 0 0 0 0 ñ l 01 StudentName PIC X(10) VALUE "MIKE". MOVE ALL "-" TO StudentName.

  26. Continuation of Lines • A statement or an entry may be continued to the area B of the next line as and when necessary. • A hyphen(-) is used in the indicator field for continuation of lines. • Actually, a hyphen in the indicator field means that the first non-blank character in the area B of the current line is the character immediately following the last non-blank character of the previous line. • Example—In case of non numeric literal Indicator line Area A Area B Continued line “Enter the Continuation Line - “Number”.

  27. Is Cobol still used ? • 75% of all business data is processed in COBOL. • There are between 180 billion and 200 billion lines of COBOL code in use worldwide. • 15% of all new applications (5 billion lines) through 2009 will be in COBOL.

  28. Thank You

More Related