section3 - Business Oriented Programming Course 92-252-01...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Business Oriented Programming Course 92-252-01 – Spring 2005 SECTION 3 – Declaring Data in COBOL There are three categories of data item used in COBOL programs: Variables. Literals. Figurative Constants A data-name or identifier is the name used to identify the area of memory reserved for a variable. A variable is a named location in memory into which a program can put data, and from which it can retrieve data. Every variable used in a COBOL program must be described in the DATA DIVISION. In addition to the data-name, a variable declaration also defines the type of data to be stored in the variable. This is known as the variable's data type. In COBOL, there are really only three data types - numeric alphanumeric (text/string) alphabetic The distinction between these data types is a little blurred and only weakly enforced by the compiler. For instance, it is perfectly possible to assign a non-numeric value to a data item that has been declared to be numeric. The problem with this lax approach to data typing is that, since COBOL programs crash (halt unexpectedly) if they attempt to do computations on items that contain non-numeric data, it is up to the programmer to make sure this never happens. COBOL programmers must make sure that non-numeric data is never assigned to numeric items intended for use in calculations. Programmers who use strongly typed languages don't need this level of discipline because the compiler ensures that a variable of a particular types can only be assigned appropriate values. A literal is a data-item that consists only of the data-item value itself. It cannot be referred to by a name. By definition, literals are constant data-items. There are two types of literal - String/Alphanumeric Literals Numeric Literals String/Alphanumeric literals are enclosed in quotes and consist of alphanumeric characters. For example: "Mrs. LaMacchia", "-123", "123.45"
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Numeric literals may consist of numerals, the decimal point, and the plus or minus sign. Numeric literals are not enclosed in quotes. For example: 123, 123.45, -256, +2987 Unlike most other programming languages COBOL does not provide a mechanism for creating user-defined constants but it does provide a set of special constants called Figurative Constants. A Figurative Constant may be used wherever it is legal to use a literal but unlike literals, when a Figurative Constant is assigned to a data-item it fills the whole item overwriting everything in it. The Figurative Constants are:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/10/2009 for the course CIS 252 taught by Professor Unknown during the Spring '05 term at Bloomsburg.

Page1 / 6

section3 - Business Oriented Programming Course 92-252-01...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online