COBOL: Wikis

  
  
  

Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.

Encyclopedia

From Wikipedia, the free encyclopedia

COBOL
Paradigm procedural,
object-oriented
Appeared in 1959 (1959)
Designed by Grace Hopper, William Selden, Gertrude Tierney, Howard Bromberg, Howard Discount, Vernon Reeves, Jean E. Sammet
Stable release COBOL 2002 (2002)
Typing discipline strong, static
Major implementations OpenCOBOL, Micro Focus International
Dialects HP3000 COBOL/II, COBOL/2, IBM OS/VS COBOL, IBM COBOL/II, IBM COBOL SAA, IBM Enterprise COBOL, IBM COBOL/400, IBM ILE COBOL, Unix COBOL X/Open, Micro Focus COBOL, Microsoft COBOL, Ryan McFarland RM/COBOL, Ryan McFarland RM/COBOL-85, DOSVS COBOL, UNIVAC COBOL, Realia COBOL, Fujitsu COBOL, ICL COBOL, ACUCOBOL-GT, DEC COBOL-10, DEC VAX COBOL, Wang VS COBOL, Visual COBOL
Influenced by FLOW-MATIC, COMTRAN, FACT
Influenced PL/I, CobolScript, ABAP

COBOL (pronounced /ˈkoʊbɒl/) is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments.

The COBOL 2002 standard includes support for object-oriented programming and other modern language features.[1]

Contents

History and specification

A specification of COBOL was initially created during the second half of 1959 by Grace Hopper. The scene was set on April 8, 1959 at a meeting of computer manufacturers, users, and university people at the University of Pennsylvania Computing Center; subsequently, the United States Department of Defense agreed to sponsor and oversee the next activities. A meeting was held at the Pentagon on May 28 and 29 of 1959 (exactly one year after the Zürich ALGOL 58 meeting), chaired by Charles A. Phillips. There it was decided to set up three committees, short, intermediate and long range (the last one was actually never formed). It was the Short Range Committee, chaired by Joseph Wegstein of the US National Bureau of Standards, that during the next months would create a description of the first version of COBOL.[2] The committee was formed to recommend a short range approach to a common business language. The committee was made up of members representing six computer manufacturers and three government agencies. The six computer manufacturers were Burroughs Corporation, IBM, Minneapolis-Honeywell (Honeywell Labs), RCA, Sperry Rand, and Sylvania Electric Products. The three government agencies were the US Air Force, the David Taylor Model Basin, and the National Bureau of Standards (now National Institute of Standards and Technology). The intermediate-range committee was formed but never became operational. In the end a sub-committee of the Short Range Committee developed the specifications of the COBOL language. This sub-committee was made up of six individuals:

This subcommittee completed the specifications for COBOL in December 1959. The specifications were to a great extent inspired by the FLOW-MATIC language invented by Grace Hopper, commonly referred to as "the mother of the COBOL language", the IBM COMTRAN language invented by Bob Bemer, and the FACT language from Honeywell.

The decision to use the name "COBOL" was made at a meeting of the committee held on 18 September 1959.

The first compilers for COBOL were subsequently implemented during the year 1960 and on 6 and 7 December essentially the same COBOL program was run on two different makes of computers, an RCA computer and a Remington-Rand Univac computer, demonstrating that compatibility could be achieved.

Since 1959 COBOL has undergone several modifications and improvements. In an attempt to overcome the problem of incompatibility between different versions of COBOL, the American National Standards Institute (ANSI) developed a standard form of the language in 1968. This version was known as American National Standard (ANS) COBOL. In 1974, ANSI published a revised version of (ANS) COBOL, containing a number of features that were not in the 1968 version. In 1985, ANSI published still another revised version that had new features not in the 1974 standard. The language continues to evolve today.

COBOL 2002 and object-oriented COBOL

In the early 1990s it was decided to add object-orientation in the next full revision of COBOL. The initial estimate was to have this revision completed by 1997 and an ISO CD (Committee Draft) was available by 1997. Some implementers (including Micro Focus, Fujitsu, and IBM) introduced object-oriented syntax based on the 1997 or other drafts of the full revision. The final approved ISO Standard (adopted as an ANSI standard by INCITS) was approved and made available in 2002.

Like the C++ programming language, object-oriented COBOL compilers are available even as the language moves toward standardization. Fujitsu and Micro Focus currently support object-oriented COBOL compilers targeting the .NET framework.[4]

The 2002 (4th revision) of COBOL included many other features beyond object-orientation. These included (but are not limited to):

  • National Language support (including but not limited to Unicode support)
  • Locale-based processing
  • User-defined functions
  • CALL (and function) prototypes (for compile-time parameter checking)
  • Pointers and syntax for getting and freeing storage
  • Calling conventions to and from non-COBOL languages such as C
  • Support for execution within framework environments such as Microsoft's .NET and Java (including COBOL instantiated as Enterprise JavaBeans)
  • Bit and Boolean support
  • “True” binary support (up until this enhancement, binary items were truncated based on the (base-10) specification within the Data Division)
  • Floating-point support
  • Standard (or portable) arithmetic results
  • XML generation and parsing

History of COBOL standards

The specifications approved by the full Short Range Committee were approved by the Executive Committee on January 3, 1960, and sent to the government printing office, which edited and printed these specifications as Cobol 60.

The American National Standards Institute (ANSI) produced several revisions of the COBOL standard, including:

  • COBOL-68
  • COBOL-74
  • COBOL-85
  • Intrinsic Functions Amendment - 1989
  • Corrections Amendment - 1991

After the Amendments to the 1985 ANSI Standard (which were adopted by ISO), primary development and ownership was taken over by ISO. The following editions and TRs (Technical Reports) have been issued by ISO (and adopted as ANSI) Standards:

  • COBOL 2002
  • Finalizer Technical Report - 2003
  • Native XML syntax Technical Report - 2006
  • Object Oriented Collection Class Libraries - pending final approval...

From 2002, the ISO standard is also available to the public coded as ISO/IEC 1989.

Work is progressing on the next full revision of the COBOL Standard. It is expected to be approved and available in the early 2010s. For information on this revision, to see the latest draft of this revision, or to see what other works is happening with the COBOL Standard, see the COBOL Standards Website.

Legacy

COBOL programs are in use globally in governmental and military agencies, in commercial enterprises, and on operating systems such as IBM's z/OS, Microsoft's Windows, and the POSIX families (Unix/Linux etc.). In 1997, the Gartner Group reported that 80% of the world's business ran on COBOL with over 200 billion lines of code in existence and with an estimated 5 billion lines of new code annually.[5]

Near the end of the twentieth century the year 2000 problem was the focus of significant COBOL programming effort, sometimes by the same programmers who had designed the systems decades before. The particular level of effort required for COBOL code has been attributed both to the large amount of business-oriented COBOL, as COBOL is by design a business language and business applications use dates heavily, and to constructs of the COBOL language such as the PICTURE clause, which can be used to define fixed-length numeric fields, including two-digit fields for years.

Features

COBOL as defined in the original specification included a PICTURE clause for detailed field specification. It did not support local variables, recursion, dynamic memory allocation, or structured programming constructs. Support for some or all of these features has been added in later editions of the COBOL standard.

COBOL has many reserved words (over 400), called keywords. The original COBOL specification supported self-modifying code via the infamous "ALTER X TO PROCEED TO Y" statement. This capability has since been removed.

Syntactic features

COBOL provides an update-in-place syntax, for example

      ADD YEARS TO AGE

The equivalent construct in many procedural languages would be

age := age + years

This syntax is similar to the compound assignment operator later adopted by C:

age += years

The abbreviated conditional expression

      IF SALARY > 9000 OR SUPERVISOR-SALARY OR = PREV-SALARY

is equivalent to

      IF SALARY > 9000
          OR SALARY > SUPERVISOR-SALARY
          OR SALARY = PREV-SALARY

COBOL provides "named conditions" (so-called 88-levels). These are declared as sub-items of another item (the conditional variable). The named condition can be used in an IF statement, and tests whether the conditional variable is equal to any of the values given in the named condition's VALUE clause. The SET statement can be used to make a named condition TRUE (by assigning the first of its values to the conditional variable).

COBOL allows identifiers to be up to 30 characters long. When COBOL was introduced, much shorter lengths (e.g., 6 characters for FORTRAN) were prevalent.

The concept of copybooks was introduced by COBOL; these are chunks of text which can be inserted into a program's code. This is done with the COPY statement, which also allows parts of the copybook's text to be replaced with other text (using the REPLACING ... BY ... clause).

Data types

Standard COBOL provides the following data types:

Data type Sample declaration Notes
Character PIC X(20)
PIC A(4)9(5)X(7)
Alphanumeric and alphabetic-only
Single-byte character set (SBCS)
Edited character PIC X99BAXX Formatted and inserted characters
Numeric fixed-point binary PIC S999V99
[USAGE] COMPUTATIONAL

or
BINARY
Binary 16, 32, or 64 bits (2, 4, or 8 bytes)
Signed or unsigned. Conforming compilers limit the maximum value of variables based on the picture clause and not the number of bits reserved for storage.
Numeric fixed-point packed decimal PIC S999V99
PACKED-DECIMAL
1 to 18 decimal digits (1 to 10 bytes)
Signed or unsigned
Numeric fixed-point zoned decimal PIC S999V99
[USAGE DISPLAY]
1 to 18 decimal digits (1 to 18 bytes)
Signed or unsigned
Leading or trailing sign, overpunch or separate
Numeric floating-point PIC S9V999ES99 Binary floating-point
Edited numeric PIC +Z,ZZ9.99
PIC $***,**9.99CR
Formatted characters and digits
Group (record) 01 CUST-NAME.
  05 CUST-LAST PIC X(20).
  05 CUST-FIRST PIC X(20).
Aggregated elements
Table (array) OCCURS 12 TIMES Fixed-size array, row-major order
Up to 7 dimensions
Variable-length table OCCURS 0 to 12 TIMES
DEPENDING ON CUST-COUNT
Variable-sized array, row-major order
Up to 7 dimensions
Renames (variant or union data) 66 RAW-RECORD
  RENAMES CUST-RECORD
Character data overlaying other variables
Condition name 88 IS-RETIRED-AGE
  VALUES 65 THRU 150
Boolean value
dependent upon another variable
Array index [USAGE] INDEX Array subscript

Most vendors provide additional types, such as:

Data type Sample declaration Notes
Numeric floating-point
single precision
PIC S9V999ES99
[USAGE] COMPUTATIONAL-1
Binary floating-point
(IBM extension)
Numeric floating-point
double precision
PIC S9V999ES99
[USAGE] COMPUTATIONAL-2
Binary floating-point
(IBM extension)
Numeric fixed-point packed decimal
PIC S9V999
[USAGE] COMPUTATIONAL-3
same as PACKED DECIMAL
(IBM extension)
Numeric fixed-point binary PIC S999V99
[USAGE] COMPUTATIONAL-4
same as COMPUTATIONAL or BINARY
(IBM extension)
Numeric fixed-point binary
(native binary)
PIC S999V99
[USAGE] COMPUTATIONAL-5
Binary 16, 32, or 64 bits (2, 4, or 8 bytes)
Signed or unsigned. The maximum value of variables based on the number of bits reserved for storage and not on the picture clause.
(IBM extension)
Numeric fixed-point binary
in native byte order
PIC S999V99
[USAGE] COMPUTATIONAL-4
Binary 16, 32, or 64 bits (2, 4, or 8 bytes)
Signed or unsigned
Numeric fixed-point binary
in big-endian byte order
PIC S999V99
[USAGE] COMPUTATIONAL-5
Binary 16, 32, or 64 bits (2, 4, or 8 bytes)
Signed or unsigned
Wide character PIC G(20) Alphanumeric
Double-byte character set (DBCS)
Edited wide character PIC G99BGGG Formatted and inserted wide characters
Edited floating-point PIC +9.9(6)E+99 Formatted characters and decimal digits
Data pointer [USAGE] POINTER Data memory address
Code pointer [USAGE] PROCEDURE-POINTER Code memory address
Bit field PIC 1(n) [USAGE] COMPUTATIONAL-5 n can be from 1 to 64, defining an n-bit integer
Signed or unsigned
Index [USAGE] INDEX Binary value corresponding to an occurrence of a table element
May be linked to a specific table using INDEXED BY

Hello, world

An example of the "Hello, world" program in COBOL:

      IDENTIFICATION DIVISION.
      PROGRAM-ID. HELLO-WORLD.
      PROCEDURE DIVISION.
          DISPLAY 'Hello, world'.
          STOP RUN.

Criticism

In his letter to an editor in 1975 titled "How do we tell truths that might hurt?", which was critical of several programming languages contemporary to COBOL, computer scientist and Turing Award recipient Edsger Dijkstra remarked that "The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense."[6]

In his dissenting response to Dijkstra's article and the above "offensive statement", computer scientist Howard E. Tompkins defended structured COBOL: "COBOL programs with convoluted control flow indeed tend to 'cripple the mind'", but this was because "there are too many such business application programs written by programmers that have never had the benefit of structured COBOL taught well...". [7]

COBOL 85 was not fully compatible with earlier versions, resulting in the "cesarean birth of COBOL 85". Joseph T. Brophy, CIO, Travelers Insurance, spearheaded an effort to inform users of COBOL of the heavy reprogramming costs of implementing the new standard. As a result the ANSI COBOL Committee received more than 3,200 letters from the public, mostly negative, requiring the committee to make changes. On the other hand, conversion to COBOL 85 was thought to increase productivity in future years, thus justifying the conversion costs. [8]

Defenses

COBOL syntax has often been criticized for its verbosity. However, this is considered a strength by proponents, because "It has made COBOL the most readable, understandable and self-documenting programming language in use today"... "Not only does this readability generally assist the maintenance process but the older a program gets the more valuable this readability becomes."

Traditional COBOL is a simple language with a limited scope of function, encouraging a straightforward coding style. This has made it well-suited to its primary domain of business computing.

COBOL is highly portable, because the standard does not belong to any particular vendor. This allows it to be used on a wide variety of hardware platforms and operating systems. The rigid hierarchical structure restricts the definition of external references to the Environment Division, which simplifies platform changes. [9]

See also

Other third- and fourth-generation programming languages

References

  1. ^ Oliveira, Rui (2006). The Power of Cobol. City: BookSurge Publishing. ISBN 0620346523. 
  2. ^ Garfunkel, Jerome (1987). The Cobol 85 Example Book. New York: Wiley. ISBN 0471804614. 
  3. ^ Wexelblat, Richard (1981). History of Programming Languages. Boston: Academic Press. ISBN 0127450408. 
  4. ^ NetCOBOL for .NET supports COBOL migration and software development in the .NET environment
  5. ^ "Future of COBOL" (PDF). LegacyJ Corporation. 2003. pp. 5. http://www.legacyj.com/cobol/FutureOfCobol.pdf. Retrieved 2006-11-08. 
  6. ^ Dijkstra (2006). "E. W. Dijkstra Archive: How do we tell truths that might hurt? (EWD498)". University of Texas at Austin. http://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EWD498.html. Retrieved August 29 2007. 
  7. ^ "In Defense of Teaching Structured COBOL as Computer Science", Howard E. Tompkins, ACM SIGPLAN Notices, Vol. 18, Issue 4, April 1983.
  8. ^ (The COBOL 85 Example Book)
  9. ^ COBOL Tutorial - Introduction to COBOL

Sources

  • Ebbinkhuijsen, Wim B.C., COBOL Alphen aan den Rijn/Diegem: Samson Bedrijfsinformatie bv, 1990. ISBN 90-14-04560-3. (Dutch)

External links

Standards:

Reference manuals:

Compilers and other products:


COBOL
Paradigm procedural,
object-oriented
Appeared in Did not recognize date. Try slightly modifying the date in the first parameter.
Designed by Grace Hopper, William Selden, Gertrude Tierney, Howard Bromberg, Howard Discount, Vernon Reeves, Jean E. Sammet
Stable release COBOL 2002 (2002)
Typing discipline strong, static
Major implementations OpenCOBOL, Micro Focus International
Dialects HP3000 COBOL/II, COBOL/2, IBM OS/VS COBOL, IBM COBOL/II, IBM COBOL SAA, IBM Enterprise COBOL, IBM COBOL/400, IBM ILE COBOL, Unix COBOL X/Open, Micro Focus COBOL, Microsoft COBOL, Ryan McFarland RM/COBOL, Ryan McFarland RM/COBOL-85, DOSVS COBOL, UNIVAC COBOL, Realia COBOL, Fujitsu COBOL, ICL COBOL, ACUCOBOL-GT, DEC COBOL-10, DEC VAX COBOL, Wang VS COBOL, Visual COBOL
Influenced by FLOW-MATIC, COMTRAN, FACT
Influenced PL/I, CobolScript, ABAP
COBOL at Wikibooks

COBOL (pronounced /ˈkoʊbɒl/) is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments.

The COBOL 2002 standard includes support for object-oriented programming and other modern language features.[1]

Contents

History and specification

The COBOL specification was created by Grace Murray Hopper during the second half of 1959. The scene was set on April 8, 1959 at a meeting of computer manufacturers, users, and university people at the University of Pennsylvania Computing Center. The United States Department of Defense subsequently agreed to sponsor and oversee the next activities. A meeting chaired by Charles A. Phillips was held at the Pentagon on May 28 and 29 of 1959 (exactly one year after the Zürich ALGOL 58 meeting); there it was decided to set up three committees: short, intermediate and long range (the last one was never actually formed). It was the Short Range Committee, chaired by Joseph Wegstein of the US National Bureau of Standards, that during the following months created a description of the first version of COBOL.[2] The committee was formed to recommend a short range approach to a common business language. The committee was made up of members representing six computer manufacturers and three government agencies. The six computer manufacturers were Burroughs Corporation, IBM, Minneapolis-Honeywell (Honeywell Labs), RCA, Sperry Rand, and Sylvania Electric Products. The three government agencies were the US Air Force, the David Taylor Model Basin, and the National Bureau of Standards (now National Institute of Standards and Technology). The intermediate-range committee was formed but never became operational. In the end a sub-committee of the Short Range Committee developed the specifications of the COBOL language. This sub-committee was made up of six individuals:

This subcommittee completed the specifications for COBOL in December 1959. The specifications were to a great extent inspired by the FLOW-MATIC language invented by Grace Hopper - commonly referred to as "the mother of the COBOL language" - the IBM COMTRAN language invented by Bob Bemer, and the FACT language from Honeywell.

The decision to use the name "COBOL" was made at a meeting of the committee held on 18 September 1959.

The first compilers for COBOL were subsequently implemented during the year 1960 and on 6 and 7 December essentially the same COBOL program was run on two different makes of computers, an RCA computer and a Remington-Rand Univac computer, demonstrating that compatibility could be achieved.

ANS COBOL 1968

After 1959 COBOL underwent several modifications and improvements. In an attempt to overcome the problem of incompatibility between different versions of COBOL, the American National Standards Institute (ANSI) developed a standard form of the language in 1968. This version was known as American National Standard (ANS) COBOL.

COBOL 1974

In 1974, ANSI published a revised version of (ANS) COBOL, containing a number of features that were not in the 1968 version.

COBOL 1985

In 1985, ANSI published still another revised version that had new features not in the 1974 standard, most notably structured language constructs ("scope terminators"), including END-IF, END-PERFORM, END-READ, etc.

COBOL 2002 and object-oriented COBOL

The language continues to evolve today. In the early 1990s it was decided to add object-orientation in the next full revision of COBOL. The initial estimate was to have this revision completed by 1997 and an ISO CD (Committee Draft) was available by 1997. Some implementers (including Micro Focus, Fujitsu, Veryant, and IBM) introduced object-oriented syntax based on the 1997 or other drafts of the full revision. The final approved ISO Standard (adopted as an ANSI standard by INCITS) was approved and made available in 2002.

Like the C++ programming language, Java, object-oriented COBOL compilers are available even as the language moves toward standardization. Fujitsu and Micro Focus currently support object-oriented COBOL compilers targeting the .NET framework.[4]

The 2002 (4th revision) of COBOL included many other features beyond object-orientation. These included (but are not limited to):

  • National Language support (including but not limited to Unicode support)
  • Locale-based processing
  • User-defined functions
  • CALL (and function) prototypes (for compile-time parameter checking)
  • Pointers and syntax for getting and freeing storage
  • Calling conventions to and from non-COBOL languages such as C
  • Support for execution within framework environments such as Microsoft's .NET and Java (including COBOL instantiated as Enterprise JavaBeans)
  • Bit and Boolean support
  • “True” binary support (up until this enhancement, binary items were truncated based on the (base-10) specification within the Data Division)
  • Floating-point support
  • Standard (or portable) arithmetic results
  • XML generation and parsing

History of COBOL standards

The specifications approved by the full Short Range Committee were approved by the Executive Committee on January 3, 1960, and sent to the government printing office, which edited and printed these specifications as Cobol 60.

The American National Standards Institute (ANSI) produced several revisions of the COBOL standard, including:

  • COBOL-68
  • COBOL-74
  • COBOL-85
  • Intrinsic Functions Amendment - 1989
  • Corrections Amendment - 1991

After the Amendments to the 1985 ANSI Standard (which were adopted by ISO), primary development and ownership was taken over by ISO. The following editions and TRs (Technical Reports) have been issued by ISO (and adopted as ANSI) Standards:

  • COBOL 2002
  • Finalizer Technical Report - 2003
  • Native XML syntax Technical Report - 2006
  • Object Oriented Collection Class Libraries - pending final approval...

From 2002, the ISO standard is also available to the public coded as ISO/IEC 1989.

Work is progressing on the next full revision of the COBOL Standard. It is expected to be approved and available in the early 2010s. For information on this revision, to see the latest draft of this revision, or to see what other works is happening with the COBOL Standard, see the COBOL Standards Website.

Legacy

COBOL programs are in use globally in governmental and military agencies and in commercial enterprises, and are running on operating systems such as IBM's z/OS, the POSIX families (Unix/Linux etc.), and Microsoft's Windows as well as ICL's VME operating system and Unisys' OS 2200. In 1997, the Gartner Group reported that 80% of the world's business ran on COBOL with over 200 billion lines of code in existence and with an estimated 5 billion lines of new code annually.[5]

Near the end of the twentieth century the year 2000 problem was the focus of significant COBOL programming effort, sometimes by the same programmers who had designed the systems decades before. The particular level of effort required for COBOL code has been attributed both to the large amount of business-oriented COBOL, as COBOL is by design a business language and business applications use dates heavily, and to constructs of the COBOL language such as the PICTURE clause, which can be used to define fixed-length numeric fields, including two-digit fields for years.[citation needed]

Features

COBOL as defined in the original specification included a PICTURE clause for detailed field specification. It did not support local variables, recursion, dynamic memory allocation, or structured programming constructs. Support for some or all of these features has been added in later editions of the COBOL standard. COBOL has many reserved words (over 400), called keywords.

Self-modifying code

The original COBOL specification supported self-modifying code via the infamous "ALTER X TO PROCEED TO Y" statement. X and Y are paragraph labels, and any "GOTO X" statements executed after such an ALTER statement have the meaning "GOTO Y" instead. Most[citation needed] compilers still support it, but it should not be used in new programs.

Syntactic features

COBOL provides an update-in-place syntax, for example

      ADD YEARS TO AGE

The equivalent construct in many procedural languages would be

age = age + years

This syntax is similar to the compound assignment operator later adopted by C:

age += years

The abbreviated conditional expression

      IF SALARY > 9000 OR SUPERVISOR-SALARY OR = PREV-SALARY

is equivalent to

      IF SALARY > 9000
          OR SALARY > SUPERVISOR-SALARY
          OR SALARY = PREV-SALARY

COBOL provides "named conditions" (so-called 88-levels). These are declared as sub-items of another item (the conditional variable). The named condition can be used in an IF statement, and tests whether the conditional variable is equal to any of the values given in the named condition's VALUE clause. The SET statement can be used to make a named condition TRUE (by assigning the first of its values to the conditional variable).

COBOL allows identifiers to be up to 30 characters long. When COBOL was introduced, much shorter lengths (e.g., 6 characters for FORTRAN) were prevalent.

The concept of copybooks was introduced by COBOL; these are chunks of text which can be inserted into a program's code. This is done with the COPY statement, which also allows parts of the copybook's text to be replaced with other text (using the REPLACING ... BY ... clause).

Data types

Standard COBOL provides the following data types:

Data type Sample declaration Notes
Character PIC X(20)
PIC A(4)9(5)X(7)
Alphanumeric and alphabetic-only
Single-byte character set (SBCS)
Edited character PIC X99BAXX Formatted and inserted characters
Numeric fixed-point binary PIC S999V99
[USAGE] COMPUTATIONAL

or
BINARY
Binary 16, 32, or 64 bits (2, 4, or 8 bytes)
Signed or unsigned. Conforming compilers limit the maximum value of variables based on the picture clause and not the number of bits reserved for storage.
Numeric fixed-point packed decimal PIC S999V99
PACKED-DECIMAL
1 to 18 decimal digits (1 to 10 bytes)
Signed or unsigned
Numeric fixed-point zoned decimal PIC S999V99
[USAGE DISPLAY]
1 to 18 decimal digits (1 to 18 bytes)
Signed or unsigned
Leading or trailing sign, overpunch or separate
Numeric floating-point PIC S9V999ES99 Binary floating-point
Edited numeric PIC +Z,ZZ9.99
PIC $***,**9.99CR
Formatted characters and digits
Group (record) 01 CUST-NAME.
  05 CUST-LAST PIC X(20).
  05 CUST-FIRST PIC X(20).
Aggregated elements
Table (array) OCCURS 12 TIMES Fixed-size array, row-major order
Up to 7 dimensions
Variable-length table OCCURS 0 to 12 TIMES
DEPENDING ON CUST-COUNT
Variable-sized array, row-major order
Up to 7 dimensions
Renames (variant or union data) 66 RAW-RECORD
  RENAMES CUST-RECORD
Character data overlaying other variables
Condition name 88 IS-RETIRED-AGE
  VALUES 65 THRU 150
Boolean value
dependent upon another variable
Array index [USAGE] INDEX Array subscript

Most vendors provide additional types, such as:

Data type Sample declaration Notes
Numeric floating-point
single precision
PIC S9V999ES99
[USAGE] COMPUTATIONAL-1
Binary floating-point
(IBM extension)
Numeric floating-point
double precision
PIC S9V999ES99
[USAGE] COMPUTATIONAL-2
Binary floating-point
(IBM extension)
Numeric fixed-point packed decimal
PIC S9V999
[USAGE] COMPUTATIONAL-3
same as PACKED DECIMAL
(IBM extension)
Numeric fixed-point binary PIC S999V99
[USAGE] COMPUTATIONAL-4
same as COMPUTATIONAL or BINARY
(IBM extension)
Numeric fixed-point binary
(native binary)
PIC S999V99
[USAGE] COMPUTATIONAL-5
Binary 16, 32, or 64 bits (2, 4, or 8 bytes)
Signed or unsigned. The maximum value of variables based on the number of bits reserved for storage and not on the picture clause.
(IBM extension)
Numeric fixed-point binary
in native byte order
PIC S999V99
[USAGE] COMPUTATIONAL-4
Binary 16, 32, or 64 bits (2, 4, or 8 bytes)
Signed or unsigned
Numeric fixed-point binary
in big-endian byte order
PIC S999V99
[USAGE] COMPUTATIONAL-5
Binary 16, 32, or 64 bits (2, 4, or 8 bytes)
Signed or unsigned
Wide character PIC G(20) Alphanumeric
Double-byte character set (DBCS)
Edited wide character PIC G99BGGG Formatted and inserted wide characters
Edited floating-point PIC +9.9(6)E+99 Formatted characters and decimal digits
Data pointer [USAGE] POINTER Data memory address
Code pointer [USAGE] PROCEDURE-POINTER Code memory address
Bit field PIC 1(n) [USAGE] COMPUTATIONAL-5 n can be from 1 to 64, defining an n-bit integer
Signed or unsigned
Index [USAGE] INDEX Binary value corresponding to an occurrence of a table element
May be linked to a specific table using INDEXED BY

Hello, world

An example of the "Hello, world" program in COBOL:

      IDENTIFICATION DIVISION.
      PROGRAM-ID. HELLO-WORLD.
      PROCEDURE DIVISION.
          DISPLAY 'Hello, world'.
          STOP RUN.

Criticism and defense

Lack of structurability

In his letter to an editor in 1975 titled "How do we tell truths that might hurt?", which was critical of several programming languages contemporaneous with COBOL, computer scientist and Turing Award recipient Edsger Dijkstra remarked that "The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense."[6]

In his dissenting response to Dijkstra's article and the above "offensive statement", computer scientist Howard E. Tompkins defended structured COBOL: "COBOL programs with convoluted control flow indeed tend to 'cripple the mind'", but this was because "there are too many such business application programs written by programmers that have never had the benefit of structured COBOL taught well...".[7]

Additionally, the introduction of OO-COBOL has added support for object-oriented code as well as user-defined functions and user-defined data types to COBOL's repertoire.

Verbose syntax

COBOL 85 was not fully compatible with earlier versions, resulting in the "cesarean birth of COBOL 85". Joseph T. Brophy, CIO, Travelers Insurance, spearheaded an effort to inform users of COBOL of the heavy reprogramming costs of implementing the new standard. As a result the ANSI COBOL Committee received more than 3,200 letters from the public, mostly negative, requiring the committee to make changes. On the other hand, conversion to COBOL 85 was thought to increase productivity in future years, thus justifying the conversion costs.[8]

COBOL syntax has often been criticized for its verbosity. However, proponents are quick to note that this was an intentional part of the language design and considered by many to be one of the COBOL's strengths. One of the design goals of COBOL was for COBOL code to be readable and understandable to non-programmers such as managers, supervisors and users. This is why COBOL has a very English-like syntax and structural elements—including: nouns, verbs, clauses, sentences, sections, and divisions. Consequently, COBOL is considered by some to be "the most readable, understandable and self-documenting programming language in use today. [...] Not only does this readability generally assist the maintenance process but the older a program gets the more valuable this readability becomes."[9]

Other defenses

Additionally, traditional COBOL is a simple language with a limited scope of function (with no pointers, no user-defined types, and no user-defined functions), encouraging a straightforward coding style. This has made it well-suited to its primary domain of business computing—where the program complexity lies in the business rules that need to be encoded rather than sophisticated algorithms or data structures. And because the standard does not belong to any particular vendor, programs written in COBOL are highly portable. The language can be used on a wide variety of hardware platforms and operating systems. And the rigid hierarchical structure restricts the definition of external references to the Environment Division, which simplifies platform changes.[9]

See also

References

  1. ^ Oliveira, Rui (2006). The Power of Cobol. City: BookSurge Publishing. ISBN 0620346523. 
  2. ^ Garfunkel, Jerome (1987). The Cobol 85 Example Book. New York: Wiley. ISBN 0471804614. 
  3. ^ Wexelblat, Richard (1981). History of Programming Languages. Boston: Academic Press. ISBN 0127450408. 
  4. ^ NetCOBOL for .NET supports COBOL migration and software development in the .NET environment
  5. ^ "What Professionals think of the Future of COBOL?". Micro Focus. http://www.cobolportal.com/developer/future.asp?bhcp=1. Retrieved 2010-05-05. 
  6. ^ Dijkstra (2006). "E. W. Dijkstra Archive: How do we tell truths that might hurt? (EWD498)". University of Texas at Austin. http://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EWD498.html. Retrieved August 29, 2007. 
  7. ^ "In Defense of Teaching Structured COBOL as Computer Science", Howard E. Tompkins, ACM SIGPLAN Notices, Vol. 18, Issue 4, April 1983.
  8. ^ Garfunkel, Jerome (1987). The COBOL 85 example book. New York: Wiley. ISBN 0471804614. 
  9. ^ a b COBOL Tutorial - Introduction to COBOL

Sources

  • Ebbinkhuijsen, Wim B.C., COBOL Alphen aan den Rijn/Diegem: Samson Bedrijfsinformatie bv, 1990. ISBN 90-14-04560-3. (Dutch)

External links

Standards:

Reference manuals:

Compilers and other products:


Study guide

Up to date as of January 14, 2010

From Wikiversity

Crystal Clear app kaddressbook.png
Please help develop this page

This page was created, but so far, little content has been added. Everyone is invited to help expand and create educational content for Wikiversity. If you need help learning how to add content, see the editing tutorial and the MediaWiki syntax reference.

To help you get started with content, we have automatically added references below to other Wikimedia Foundation projects. This will help you find materials such as information, media and quotations on which to base the development of "COBOL" as an educational resource. However, please do not simply copy-and-paste large chunks from other projects. You can also use the links in the blue box to help you classify this page by subject, educational level and resource type.

Wikipedia-logo.png Run a search on COBOL at Wikipedia.
Commons-logo.svg Search Wikimedia Commons for images, sounds and other media related to: COBOL
Wikimedia-logo.svg Search for COBOL on the following projects:
Smiley green alien whatface.svg Lost on Wikiversity? Please help by choosing project boxes to classify this resource by:
  • subject
  • educational level
  • resource type

Welcome to COBOL at Wikiversity. This area will present information concerning one of the programming languages which, to this day, continues to provide business data processing to the world.

Please forgive the current limited information as the page is built.

Wikibooks


Wiktionary

Up to date as of January 15, 2010

Definition from Wiktionary, a free dictionary

See also Cobol

English

Etymology

Co(mmon) B(usiness-)O(riented) L(anguage)

Noun

Wikipedia-logo.png
Wikipedia has an article on:

Wikipedia

COBOL (or Cobol)

  1. (programming languages) A programming language developed in the late 1950s especially for business applications

Wikibooks

Up to date as of January 23, 2010

From Wikibooks, the open-content textbooks collection

< Software Engineers Handbook

Contents

COBOL


COBOL is widely used in the financial services industry typically for mainframe based applications. It has been used extensively since the 1960s. COBOL was designed for use in business applications and consequently it was implemented with fixed-point arithmetic support. This is one of the advantages of COBOL as it allows complete and accurate computation of financial values without the possibility of rounding errors.

Type

COBOL is a full procedural language.

Execution Entry Point

A COBOL program is split into four divisions, all four divisions must be present in every program in this sequence: Identification; Environment; Data and Procedure. Each division contains a number of mandatory and optional sections and paragraphs.

The Identification Division contains information about the program, including its name, author, date of compliation, etc. It must contain the PROGRAM-ID paragraph which uniquely names the program. All other paragraphs are optional.

The Environment Division describes the environment in which the program will execute. For example, it includes details of input and output files and the target execution platform. The division contains two sections: the Configuration Section and the Input-Output section.

The Data Division contains the File Section, which fully describes the record layout of each input and output file, and the Working-Storage Section where variables are declared. It also contains the Linkage Section which describes data that will be passed between programs that call each other.

The Procedure Division contains the executable program instructions. The execution entry point is the first statement in the division.

General Syntax

It would be very difficult to give an overview of COBOL's general syntax, since the language has over 500 reserved words, which is too large for some versions of LEX and YACC. Here are some sample assignment statements:

MOVE A TO B.
COMPUTE GROSS-PAY = HOURS-WORKED * HOURLY-RATE
SET MY-INDEX TO 1
SET ADDRESS OF MY-LINKAGE-SECTION-ITEM TO MY-POINTER
READ TRANSACTION-FILE INTO TRANSACTION-RECORD-WS

While many sites still use all uppercase characters, modern COBOL compilers are case-insensitive. The following two statements are absolutely equivalent:

MOVE MY-NUMBER TO YOUR-NUMBER.
Move my-number to Your-Number.

Character case is respected for quoted literals (character strings).

Comments

Normally the only way to specifiy a comment is by putting an asterisk in the indicator-area (column 7). The entire line is a comment. Block comments must have * in column 7 of every line. There is a 2002 standard that allows part of a line to be a comment:

MOVE A TO B.   *> THIS IS A COMMENT ON THE SAME LINE AS A STATEMENT

Variable Declarations

There are a few variables of a type know as special registers that do not need to be defined, but generally all variables must be defined in COBOL, unlike interpreted BASIC.

COBOL has a number of data types, but the most common are numeric (with specifiers for internal format), numeric edited data, alphanumeric data, and records (similar to struct in C):

01  TRANSACTION-RECORD.
   05  RECORD-NUMBER            PIC S9(7) COMP-3 VALUE ZERO.
   05  RECORD-DESCRIPTION       PIC X(30) VALUE SPACES.
   05  EDITED-AMOUNT            PIC $$$$,$$$,$$$.99-.
   05  FILLER                   PIC X(60) VALUE SPACES.

Your simple example, declaring an integer, might look something like this:

77  I    pic s9(4)  usage is binary.

COBOL also supports redefinition, which is somewhat similar to union in C

Method Declaration/Implementation

Object-oriented extensions are available to COBOL, but the vast majority of COBOL programmers don't know them, and see no need for them.

However if a COBOL programer wants to create a class it is quite easy. For example here is an HelloWorld class with a InstanceMethod!

      class-id. HelloWorld as "HelloWorld".
      environment division.
      configuration section.
      repository.
     
      object.
      data division.
      working-storage section.
      method-id. "InstanceMethod".
      local-storage section.
      linkage section.
      procedure division.
          display "Hello World"
          exit method.           
      end method "InstanceMethod".
     
      end object.
      end class HelloWorld

If the COBOL programmer wants to interact with external classes such as the .NET Framework it can do too. For example here is a example of obtaining the current date/time from .NET.

       repository.
          class sys-datetime as "System.DateTime"
       .
       01 now sys-datetime.
       procedure division.
          set now to sys-datetime::"Now"
          display now

Scope

All data contained working-storage section of the COBOL program is global. Some data items may be defined as external, and visible to other programs in a load module. The data items in a COBOL subprogram are global to the subprogram, but local since the caller cannot see them. Typically, data is "passed" from a COBOL main program to a subprogram by reference. There are alternatives of "by content" or "by value", but they are typically only used to call subprograms written in C or other languages that do not normally use call by reference.

Some vendors provide extensions, such as thread-local-storage section and local-storage section. These extensions allow data to scoped as either thread-local or temporary to the program.

Conditional Statements

There are a lot of them. Here are some examples:

If my-number is numeric
   continue
else
   display 'data field "my-number" is not numeric'
end-if
evaluate record-type
when 'a'
   perform process-record-type-a
when 'b'
   perform process-record-type-b
when 'c'
   continue
when 'd'
when 'e'
   perform process-record-type-d-or-e
when other
   perform process-invalid-record-type
end-evaluate
READ TRANSACTION-FILE INTO MY-TRAN-REC-WS
AT END
   SET ALL-RECORDS-PROCESSED TO TRUE
NOT AT END
   ADD +1 TO TRAN-REC-COUNT
   PERFORM PROCESS-1-TRANSACTION
END-READ

Looping Statements

There are several of those too:

Perform 6 times
   add +1 to loop-count
end-perform
Perform process-1-billing-record
   until all-records-processed
Perform clear-1-table-entry
   varying tbl-index from +1 by +1
   until tbl-index is greater than max-table-entries
Search table-entry varying tbl-index
at end
   set entry-not-found to true
when table-key equal customer-id
   move tbl-customer-name to print-customer-name
end-search

Output Statements

Here are several examples.

DISPLAY "Hello, World!" 
display 'hello, world!' with no advancing
Write billing-record from transaction-record-ws

For key-sequenced files, there is support for Start, Read, Write, Rewrite, and Delete.

Containers

Not applicable to COBOL.

Algorithms

Recursion is not generally supported, although it can be simulated by iteration.

Garbage collection

Memory allocated dynamically via system APIs such as malloc should be free'ed with the appriopiate call to "free".

COBOL programs that uses CLASS'es may need to invoke the "finalize" method to release the object. For example:

invoke myObject "finalize" returning myObject 

If the COBOL application is executing under a VM such as a Java VMs or Microsoft's CLR standard garbage collection rules apply.

Otherwise..

COBOL programmers do not normally know or care what garbage collection is. They rarely have to allocate memory or clean it up afterwards.

Physical Structure

A COBOL source file may have (but need not have) copybooks, somewhat similar to .h files in C. The compiled program generally makes use of a COBOL runtime library of service routines that are dynamically loaded. The COBOL source file itself consists of four divisions: IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, and PROCEDURE DIVISION.

Tips

<Please include tips that make it easier to switch to this language from another language.>

Web References

Books and Articles

<List additional books and articles that may be helpful. Please include for what level reader the references are appropriate. (beginner/intermediate/advanced)>

Back to the title page Not a book title page. Please remove {{alphabetical}} from this page.

Tools

  • Cobos Project The Open Source Cobol / Mainframe / CICS / DB2 Integrated Development Environment (within Eclipse)







Got something to say? Make a comment.
Your name
Your email address
Message