Английская Википедия:COBOL
Шаблон:Short description Шаблон:Use dmy dates Шаблон:Good article Шаблон:Use American English Шаблон:Infobox programming language
COBOL (Шаблон:IPAc-en; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily used in business, finance, and administrative systems for companies and governments. COBOL is still widely used in applications deployed on mainframe computers, such as large-scale batch and transaction processing jobs. Many large financial institutions were developing new systems in the language as late as 2006,[1] but most programming in COBOL today is purely to maintain existing applications. Programs are being moved to new platforms, rewritten in modern languages or replaced with other software.[2]
COBOL was designed in 1959 by CODASYL and was partly based on the programming language FLOW-MATIC designed by Grace Hopper. It was created as part of a U.S. Department of Defense effort to create a portable programming language for data processing. It was originally seen as a stopgap, but the Defense Department promptly forced computer manufacturers to provide it, resulting in its widespread adoption.[3] It was standardized in 1968 and has been revised five times. Expansions include support for structured and object-oriented programming. The current standard is ISO/IEC 1989:2023.Шаблон:Sfn
COBOL statements have prose syntax such as Шаблон:Code, which was designed to be self-documenting and highly readable. However, it is verbose and uses over 300 reserved words. This contrasts with the succinct and mathematically inspired syntax of other languages (in this case, Шаблон:Code).
COBOL code is split into four divisions (identification, environment, data, and procedure) containing a rigid hierarchy of sections, paragraphs and sentences. Lacking a large standard library, the standard specifies 43 statements, 87 functions and just one class.
Academic computer scientists were generally uninterested in business applications when COBOL was created and were not involved in its design; it was (effectively) designed from the ground up as a computer language for business, with an emphasis on inputs and outputs, whose only data types were numbers and strings of text.[4]
COBOL has been criticized for its verbosity, design process, and poor support for structured programming. These weaknesses result in monolithic programs that are hard to comprehend as a whole, despite their local readability.
For years, COBOL has been assumed as a programming language for business operations in mainframes,[5] although in recent years, many COBOL operations have been moved to cloud computing.[6]
History and specification
Year | Informal name | ANSI INCITS Standard | ISO/IEC Standard |
---|---|---|---|
1960 | COBOL-60 | Шаблон:N/a | Шаблон:N/a |
1961 | COBOL-61 | Шаблон:N/a | Шаблон:N/a |
1963 | COBOL-61 Extended | Шаблон:N/a | Шаблон:N/a |
1965 | COBOL-65 | Шаблон:N/a | Шаблон:N/a |
1968 | COBOL-68 | X3.23-1968 | Шаблон:N/a |
1974 | COBOL-74 | X3.23-1974 | Шаблон:N/a |
1985 | COBOL-85 | X3.23-1985 | 1989:1985 |
2002 | COBOL-2002 | Шаблон:N/a | 1989:2002 |
2014 | COBOL-2014 | Шаблон:N/a | 1989:2014 |
2023 | COBOL-2023 | Шаблон:N/a | 1989:2023 |
Background
In the late 1950s, computer users and manufacturers were becoming concerned about the rising cost of programming. A 1959 survey had found that in any data processing installation, the programming cost US$800,000 on average and that translating programs to run on new hardware would cost $600,000. At a time when new programming languages were proliferating, the same survey suggested that if a common business-oriented language were used, conversion would be far cheaper and faster.Шаблон:Sfn
On 8 April 1959, Mary K. Hawes, a computer scientist at Burroughs Corporation, called a meeting of representatives from academia, computer users, and manufacturers at the University of Pennsylvania to organize a formal meeting on common business languages.[7] Representatives included Grace Hopper (inventor of the English-like data processing language FLOW-MATIC), Jean Sammet and Saul Gorn.Шаблон:SfnШаблон:Sfn
At the April meeting, the group asked the Department of Defense (DoD) to sponsor an effort to create a common business language. The delegation impressed Charles A. Phillips, director of the Data System Research Staff at the DoD,[8] who thought that they "thoroughly understood" the DoD's problems. The DoD operated 225 computers, had 175 more on order and had spent over $200 million on implementing programs to run on them. Portable programs would save time, reduce costs and ease modernization.Шаблон:Sfn
Charles Phillips agreed to sponsor the meeting and tasked the delegation with drafting the agenda.Шаблон:Sfn
COBOL 60
On 28 and 29 May 1959 (exactly one year after the Zürich ALGOL 58 meeting), a meeting was held at the Pentagon to discuss the creation of a common programming language for business. It was attended by 41 people and was chaired by Phillips.[9] The Department of Defense was concerned about whether it could run the same data processing programs on different computers. FORTRAN, the only mainstream language at the time, lacked the features needed to write such programs.Шаблон:Sfn
Representatives enthusiastically described a language that could work in a wide variety of environments, from banking and insurance to utilities and inventory control. They agreed unanimously that more people should be able to program and that the new language should not be restricted by the limitations of contemporary technology. A majority agreed that the language should make maximal use of English, be capable of change, be machine-independent and be easy to use, even at the expense of power.Шаблон:Sfn
The meeting resulted in the creation of a steering committee and short, intermediate and long-range committees. The short-range committee was given to September (three months) to produce specifications for an interim language, which would then be improved upon by the other committees.Шаблон:SfnШаблон:Sfn Their official mission, however, was to identify the strengths and weaknesses of existing programming languages and did not explicitly direct them to create a new language.Шаблон:Sfn
The deadline was met with disbelief by the short-range committee.Шаблон:Sfn One member, Betty Holberton, described the three-month deadline as "gross optimism" and doubted that the language really would be a stopgap.Шаблон:Sfn
The steering committee met on 4 June and agreed to name the entire activity as the Committee on Data Systems Languages, or CODASYL, and to form an executive committee.Шаблон:Sfn
The short-range committee members represented six computer manufacturers and three government agencies. The computer manufacturers were Burroughs Corporation, IBM, Minneapolis-Honeywell (Honeywell Labs), RCA, Sperry Rand, and Sylvania Electric Products. The government agencies were the U.S. Air Force, the Navy's David Taylor Model Basin, and the National Bureau of Standards (now the National Institute of Standards and Technology).Шаблон:Sfn The committee was chaired by Joseph Wegstein of the U.S. National Bureau of Standards. Work began by investigating data description, statements, existing applications and user experiences.Шаблон:Sfn
The committee mainly examined the FLOW-MATIC, AIMACO and COMTRAN programming languages.Шаблон:SfnШаблон:Sfn The FLOW-MATIC language was particularly influential because it had been implemented and because AIMACO was a derivative of it with only minor changes.Шаблон:Sfn[10] FLOW-MATIC's inventor, Grace Hopper, also served as a technical adviser to the committee.Шаблон:Sfn FLOW-MATIC's major contributions to COBOL were long variable names, English words for commands and the separation of data descriptions and instructions.Шаблон:Sfn
Hopper is sometimes called "the mother of COBOL" or "the grandmother of COBOL",[11][12][13] although Jean Sammet, a lead designer of COBOL, said Hopper "was not the mother, creator or developer of Cobol".[14][15]
IBM's COMTRAN language, invented by Bob Bemer, was regarded as a competitor to FLOW-MATICШаблон:SfnШаблон:Sfn by a short-range committee made up of colleagues of Grace Hopper.Шаблон:Sfn Some of its features were not incorporated into COBOL so that it would not look like IBM had dominated the design process,Шаблон:Sfn and Jean Sammet said in 1981 that there had been a "strong anti-IBM bias" from some committee members (herself included).Шаблон:Sfn In one case, after Roy Goldfinger, author of the COMTRAN manual and intermediate-range committee member, attended a subcommittee meeting to support his language and encourage the use of algebraic expressions, Grace Hopper sent a memo to the short-range committee reiterating Sperry Rand's efforts to create a language based on English.Шаблон:Sfn
In 1980, Grace Hopper commented that "COBOL 60 is 95% FLOW-MATIC" and that COMTRAN had had an "extremely small" influence. Furthermore, she said that she would claim that work was influenced by both FLOW-MATIC and COMTRAN only to "keep other people happy [so they] wouldn't try to knock us out".[16]
Features from COMTRAN incorporated into COBOL included formulas,Шаблон:Sfn the [[#PICTURE clause|Шаблон:Code clause]],Шаблон:Sfn an improved IF
statement, which obviated the need for GO TOs, and a more robust file management system.Шаблон:Sfn
The usefulness of the committee's work was subject of great debate. While some members thought the language had too many compromises and was the result of design by committee, others felt it was better than the three languages examined. Some felt the language was too complex; others, too simple.Шаблон:Sfn
Controversial features included those some considered useless or too advanced for data processing users. Such features included Boolean expressions, formulas and table Шаблон:Dfn (indices).Шаблон:SfnШаблон:Sfn Another point of controversy was whether to make keywords context-sensitive and the effect that would have on readability.Шаблон:Sfn Although context-sensitive keywords were rejected, the approach was later used in PL/I and partially in COBOL from 2002.Шаблон:Sfn Little consideration was given to interactivity, interaction with operating systems (few existed at that time) and functions (thought of as purely mathematical and of no use in data processing).Шаблон:SfnШаблон:Sfn
The specifications were presented to the executive committee on 4 September. They fell short of expectations: Joseph Wegstein noted that "it contains rough spots and requires some additions", and Bob Bemer later described them as a "hodgepodge". The subcommittee was given until December to improve it.Шаблон:Sfn
At a mid-September meeting, the committee discussed the new language's name. Suggestions included "BUSY" (Business System), "INFOSYL" (Information System Language) and "COCOSYL" (Common Computer Systems Language).Шаблон:Sfn It is unclear who coined the name "COBOL",Шаблон:SfnШаблон:Sfn although Bob Bemer later claimed it had been his suggestion.[17][18][19]
In October, the intermediate-range committee received copies of the FACT language specification created by Roy Nutt. Its features impressed the committee so much that they passed a resolution to base COBOL on it.Шаблон:Sfn
This was a blow to the short-range committee, who had made good progress on the specification. Despite being technically superior, FACT had not been created with portability in mind or through manufacturer and user consensus. It also lacked a demonstrable implementation,Шаблон:Sfn allowing supporters of a FLOW-MATIC-based COBOL to overturn the resolution. RCA representative Howard Bromberg also blocked FACT, so that RCA's work on a COBOL implementation would not go to waste.Шаблон:Sfn
It soon became apparent that the committee was too large for any further progress to be made quickly. A frustrated Howard Bromberg bought a $15 tombstone with "COBOL" engraved on it and sent it to Charles Phillips to demonstrate his displeasure.Шаблон:Efn[20]Шаблон:Sfn
A sub-committee was formed to analyze existing languages and was made up of six individuals:Шаблон:SfnШаблон:Sfn
- William Selden and Gertrude Tierney of IBM,
- Howard Bromberg and Howard Discount of RCA,
- Vernon Reeves and Jean E. Sammet of Sylvania Electric Products.
The sub-committee did most of the work creating the specification, leaving the short-range committee to review and modify their work before producing the finished specification.Шаблон:Sfn
The specifications were approved by the executive committee on 8 January 1960, and sent to the government printing office, which printed them as COBOL 60. The language's stated objectives were to allow efficient, portable programs to be easily written, to allow users to move to new systems with minimal effort and cost, and to be suitable for inexperienced programmers.Шаблон:Sfn
The CODASYL Executive Committee later created the COBOL Maintenance Committee to answer questions from users and vendors and to improve and expand the specifications.Шаблон:Sfn
During 1960, the list of manufacturers planning to build COBOL compilers grew. By September, five more manufacturers had joined CODASYL (Bendix, Control Data Corporation, General Electric (GE), National Cash Register and Philco), and all represented manufacturers had announced COBOL compilers. GE and IBM planned to integrate COBOL into their own languages, GECOM and COMTRAN, respectively. In contrast, International Computers and Tabulators planned to replace their language, CODEL, with COBOL.Шаблон:Sfn
Meanwhile, RCA and Sperry Rand worked on creating COBOL compilers. The first COBOL program ran on 17 August on an RCA 501.Шаблон:Sfn On 6 and 7 December, the same COBOL program (albeit with minor changes) ran on an RCA computer and a Remington-Rand Univac computer, demonstrating that compatibility could be achieved.[21]
The relative influences of which languages were used continues to this day in the recommended advisory printed in all COBOL reference manuals: Шаблон:Blockquote
COBOL-61 to COBOL-65
Many logical flaws were found in COBOL 60, leading General Electric's Charles Katz to warn that it could not be interpreted unambiguously. A reluctant short-term committee performed a total cleanup and, by March 1963, it was reported that COBOL's syntax was as definable as ALGOL's, although semantic ambiguities remained.Шаблон:Sfn
COBOL is a difficult language to write a compiler for, due to the large syntax and many optional elements within syntactic constructs as well as to the need to generate efficient code for a language with many possible data representations, implicit type conversions, and necessary set-ups for I/O operations.[22] Early COBOL compilers were primitive and slow. A 1962 US Navy evaluation found compilation speeds of 3–11 statements per minute. By mid-1964, they had increased to 11–1000 statements per minute. It was observed that increasing memory would drastically increase speed and that compilation costs varied wildly: costs per statement were between $0.23 and $18.91.Шаблон:Sfn
In late 1962, IBM announced that COBOL would be their primary development language and that development of COMTRAN would cease.Шаблон:Sfn
The COBOL specification was revised three times in the five years after its publication. COBOL-60 was replaced in 1961 by COBOL-61. This was then replaced by the COBOL-61 Extended specifications in 1963, which introduced the sort and report writer facilities.Шаблон:Sfn The added facilities corrected flaws identified by Honeywell in late 1959 in a letter to the short-range committee.Шаблон:Sfn COBOL Edition 1965 brought further clarifications to the specifications and introduced facilities for handling mass storage files and tables.Шаблон:Sfn
COBOL-68
Efforts began to standardize COBOL to overcome incompatibilities between versions. In late 1962, both ISO and the United States of America Standards Institute (now ANSI) formed groups to create standards. ANSI produced USA Standard COBOL X3.23 in August 1968, which became the cornerstone for later versions.Шаблон:Sfn This version was known as American National Standard (ANS) COBOL and was adopted by ISO in 1972.[23]
COBOL-74
By 1970, COBOL had become the most widely used programming language in the world.Шаблон:Sfn
Independently of the ANSI committee, the CODASYL Programming Language Committee was working on improving the language. They described new versions in 1968, 1969, 1970 and 1973, including changes such as new inter-program communication, debugging and file merging facilities as well as improved string-handling and library inclusion features.Шаблон:Sfn
Although CODASYL was independent of the ANSI committee, the CODASYL Journal of Development was used by ANSI to identify features that were popular enough to warrant implementing.Шаблон:Sfn The Programming Language Committee also liaised with ECMA and the Japanese COBOL Standard committee.Шаблон:Sfn
The Programming Language Committee was not well-known, however. The vice-president, William Rinehuls, complained that two-thirds of the COBOL community did not know of the committee's existence. It also lacked the funds to make public documents, such as minutes of meetings and change proposals, freely available.[24]
In 1974, ANSI published a revised version of (ANS) COBOL, containing new features such as file organizations, the Шаблон:Code statement[25] and the segmentation module.Шаблон:Sfn Deleted features included the Шаблон:Code statement, the Шаблон:Code statement (which was replaced by Шаблон:Code) and the implementer-defined random access module (which was superseded by the new sequential and relative I/O modules). These made up 44 changes, which rendered existing statements incompatible with the new standard.[26] The report writer was slated to be removed from COBOL, but was reinstated before the standard was published.[27][28] ISO later adopted the updated standard in 1978.[23]
COBOL-85
In June 1978, work began on revising COBOL-74. The proposed standard (commonly called COBOL-80) differed significantly from the previous one, causing concerns about incompatibility and conversion costs. In January 1981, Joseph T. Brophy, Senior Vice-president of Travelers Insurance, threatened to sue the standard committee because it was not upwards compatible with COBOL-74. Mr. Brophy described previous conversions of their 40-million-line code base as "non-productive" and a "complete waste of our programmer resources".[29] Later that year, the Data Processing Management Association (DPMA) said it was "strongly opposed" to the new standard, citing "prohibitive" conversion costs and enhancements that were "forced on the user".[30][31]
During the first public review period, the committee received 2,200 responses, of which 1,700 were negative form letters.[32] Other responses were detailed analyses of the effect COBOL-80 would have on their systems; conversion costs were predicted to be at least 50 cents per line of code. Fewer than a dozen of the responses were in favor of the proposed standard.[33]
ISO TC97-SC5 installed in 1979 the international COBOL Experts Group, on initiative of Wim Ebbinkhuijsen. The group consisted of COBOL experts from many countries, including the United States. Its goal was to achieve mutual understanding and respect between ANSI and the rest of the world with regard to the need of new COBOL features. After three years, ISO changed the status of the group to a formal Working Group: WG 4 COBOL. The group took primary ownership and development of the COBOL standard, where ANSI made most of the proposals.
In 1983, the DPMA withdrew its opposition to the standard, citing the responsiveness of the committee to public concerns. In the same year, a National Bureau of Standards study concluded that the proposed standard would present few problems.[31][34] A year later, DEC released a VAX/VMS COBOL-80, and noted that conversion of COBOL-74 programs posed few problems. The new EVALUATE
statement and inline PERFORM
were particularly well received and improved productivity, thanks to simplified control flow and debugging.[35]
The second public review drew another 1,000 (mainly negative) responses, while the last drew just 25, by which time many concerns had been addressed.[31]
In 1985, the ISO Working Group 4 accepted the then-version of the ANSI proposed standard, made several changes and set it as the new ISO standard COBOL 85. It was published in late 1985.
Sixty features were changed or deprecated and 115[36] were added, such as:Шаблон:Sfn[37]
- Scope terminators (
END-IF
,END-PERFORM
,END-READ
, etc.) - Nested subprograms
CONTINUE
, a no-operation statementEVALUATE
, a switch statementINITIALIZE
, a statement that can set groups of data to their default values- Inline
PERFORM
loop bodies – previously, loop bodies had to be specified in a separate procedure - Reference modification, which allows access to substrings
- I/O status codes.
The new standard was adopted by all national standard bodies, including ANSI.[23]
Two amendments followed in 1989 and 1993, the first introducing intrinsic functions and the other providing corrections.[23]
COBOL 2002 and object-oriented COBOL
In 1997, Gartner Group estimated that there were a total of 200 billion lines of COBOL in existence, which ran 80% of all business programs.Шаблон:Efn[38]
In the early 1990s, work began on adding object-orientation in the next full revision of COBOL. Object-oriented features were taken from C++ and Smalltalk.[39][40]
The initial estimate was to have this revision completed by 1997, and an ISO Committee Draft (CD) was available by 1997. Some vendors (including Micro Focus, Fujitsu, and IBM) introduced object-oriented syntax based on drafts of the full revision. The final approved ISO standard was approved and published in late 2002.[41]
Fujitsu/GTSoftware,[42] Micro Focus introduced object-oriented COBOL compilers targeting the .NET Framework.
There were many other new features, many of which had been in the CODASYL COBOL Journal of Development since 1978 and had missed the opportunity to be included in COBOL-85.[43] These other features included:Шаблон:SfnШаблон:Sfn
- Free-form code
- User-defined functions
- Recursion
- Locale-based processing
- Support for extended character sets such as Unicode
- Floating-point and binary data types (until then, binary items were truncated based on their declaration's base-10 specification)
- Portable arithmetic results
- Bit and Boolean data types
- Pointers and syntax for getting and freeing storage
- The Шаблон:Code for text-based user interfaces
- The Шаблон:Code facility
- Improved interoperability with other programming languages and framework environments such as .NET and Java.
Three corrigenda were published for the standard: two in 2006 and one in 2009.[44]
COBOL 2014
Between 2003 and 2009, three technical reports were produced describing object finalization, XML processing and collection classes for COBOL.[44]
COBOL 2002 suffered from poor support: no compilers completely supported the standard. Micro Focus found that it was due to a lack of user demand for the new features and due to the abolition of the NIST test suite, which had been used to test compiler conformance. The standardization process was also found to be slow and under-resourced.[45]
COBOL 2014 includes the following changes:Шаблон:Sfn
- Portable arithmetic results have been replaced by IEEE 754 data types
- Major features have been made optional, such as the
VALIDATE
facility, the report writer and the screen-handling facility - Method overloading
- Dynamic capacity tables (a feature dropped from the draft of COBOL 2002)[46]
COBOL 2023
The COBOL 2023 standard added a few new features:
- Asynchronous messaging syntax using the
SEND
andRECEIVE
statementsШаблон:Sfn - A transaction processing facility with
COMMIT
andROLLBACK
Шаблон:Sfn XOR
logical operatorШаблон:Sfn- The
CONTINUE
statement can be extended as to pause the program for a specified durationШаблон:Sfn - A
DELETE FILE
statementШаблон:Sfn LINE SEQUENTIAL
file organizationШаблон:Sfn- Defined infinite looping with
PERFORM UNTIL EXIT
Шаблон:Sfn SUBSTITUTE
intrinsic function allowing for substring substitution of different lengthШаблон:SfnCONVERT
function for base-conversionШаблон:Sfn- Boolean shifting operatorsШаблон:Sfn
There is as yet no known complete implementation of this standard.Шаблон:Citation needed
Legacy
COBOL programs are used globally in governments and businesses and are running on diverse operating systems such as z/OS, z/VSE, VME, Unix, NonStop OS, OpenVMS and Windows. In 1997, the Gartner Group reported that 80% of the world's business ran on COBOL with over 200 billion lines of codeШаблон:Efn and 5 billion lines more being written annually.[47]
Near the end of the 20th century, the year 2000 problem (Y2K) 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 to correct COBOL code has been attributed to the large amount of business-oriented COBOL, as business applications use dates heavily, and to fixed-length data fields.[48] Some studies attribute as much as "24% of Y2K software repair costs to Cobol".[49] After the clean-up effort put into these programs for Y2K, a 2003 survey found that many remained in use.Шаблон:Sfn The authors said that the survey data suggest "a gradual decline in the importance of COBOL in application development over the [following] 10 years unless ... integration with other languages and technologies can be adopted".Шаблон:Sfn
In 2006 and 2012, Computerworld surveys (of 352 readers) found that over 60% of organizations used COBOL (more than C++ and Visual Basic .NET) and that for half of those, COBOL was used for the majority of their internal software.[1][50] 36% of managers said they planned to migrate from COBOL, and 25% said that they would do so if not for the expense of rewriting legacy code. Alternatively, some businesses have migrated their COBOL programs from mainframes to cheaper, faster hardware.[1]
Testimony before the House of Representatives in 2016 indicated that COBOL is still in use by many federal agencies.[51] Reuters reported in 2017 that 43% of banking systems still used COBOL with over 220 billion lines of COBOL code in use.[52]
By 2019, the number of COBOL programmers was shrinking fast due to retirements, leading to an impending skills gap in business and government organizations which still use mainframe systems for high-volume transaction processing. Efforts to rewrite systems in newer languages have proven expensive and problematic, as has the outsourcing of code maintenance, thus proposals to train more people in COBOL are advocated.[53]
During the COVID-19 pandemic and the ensuing surge of unemployment, several US states reported a shortage of skilled COBOL programmers to support the legacy systems used for unemployment benefit management. Many of these systems had been in the process of conversion to more modern programming languages prior to the pandemic, but the process was put on hold.[54] Similarly, the US Internal Revenue Service rushed to patch its COBOL-based Individual Master File in order to disburse the tens of millions of payments mandated by the Coronavirus Aid, Relief, and Economic Security Act.[55]
Features
Syntax
COBOL has an English-like syntax, which is used to describe nearly everything in a program. For example, a condition can be expressed as Шаблон:Code or more concisely as Шаблон:Code or Шаблон:Code. More complex conditions can be "abbreviated" by removing repeated conditions and variables. For example, Шаблон:Code can be shortened to Шаблон:Code. To support this syntax, COBOL has over 300 keywords.Шаблон:SfnШаблон:Efn Some of the keywords are simple alternative or pluralized spellings of the same word, which provides for more grammatically appropriate statements and clauses; e.g., the Шаблон:Code and Шаблон:Code keywords can be used interchangeably, as can Шаблон:Code and Шаблон:Code, and Шаблон:Code and Шаблон:Code.
Each COBOL program is made up of four basic lexical items: words, literals, picture character-strings (see Шаблон:Slink) and separators. Words include reserved words and user-defined identifiers. They are up to 31 characters long and may include letters, digits, hyphens and underscores. Literals include numerals (e.g. Шаблон:Code) and strings (e.g. Шаблон:Code).Шаблон:Sfn Separators include the space character and commas and semi-colons followed by a space.Шаблон:Sfn
A COBOL program is split into four divisions: the identification division, the environment division, the data division and the procedure division. The identification division specifies the name and type of the source element and is where classes and interfaces are specified. The environment division specifies any program features that depend on the system running it, such as files and character sets. The data division is used to declare variables and parameters. The procedure division contains the program's statements. Each division is sub-divided into sections, which are made up of paragraphs.
Metalanguage
COBOL's syntax is usually described with a unique metalanguage using braces, brackets, bars and underlining. The metalanguage was developed for the original COBOL specifications. Although Backus–Naur form did exist at the time, the committee had not heard of it.Шаблон:Sfn
Element | Appearance | Function |
---|---|---|
All capitals | EXAMPLE | Reserved word |
Underlining | Шаблон:Underline | The reserved word is compulsory |
Braces | { } | Only one option may be selected |
Brackets | [] | Zero or one options may be selected |
Ellipsis | ... | The preceding element may be repeated |
Bars | {Шаблон:Pipe Шаблон:Pipe} | One or more options may be selected. Any option may only be selected once. |
[[[:Шаблон:Pipe]] Шаблон:Pipe] | Zero or more options may be selected. Any option may only be selected once. |
As an example, consider the following description of an ADD
statement:
<math> \begin{array}{l} \underline{\text{ADD}}\, \begin{Bmatrix} \text{identifier-1} \\ \text{literal-1} \end{Bmatrix}\dots \;\underline{\text{TO}}\,\left\{\text{identifier-2}\,\left[\,\underline{\text{ROUNDED}}\,\right]\right\}\dots \\[1em] \quad \left[\left|\begin{array}{l} \text{ON}\,\underline{\text{SIZE}}\,\underline{\text{ERROR}}\,\text{imperative-statement-1} \\ \underline{\text{NOT}}\,\text{ON}\,\underline{\text{SIZE}}\,\underline{\text{ERROR}}\,\text{imperative-statement-2} \end{array}\right|\right] \\[1em] \quad \left[\,\underline{\text{END-ADD}}\,\right] \end{array} </math>
This description permits the following variants:
ADD 1 TO x
ADD 1, a, b TO x ROUNDED, y, z ROUNDED
ADD a, b TO c
ON SIZE ERROR
DISPLAY "Error"
END-ADD
ADD a TO b
NOT SIZE ERROR
DISPLAY "No error"
ON SIZE ERROR
DISPLAY "Error"
Code format
The height of COBOL's popularity coincided with the era of keypunch machines and punched cards. The program itself was written onto punched cards, then read in and compiled, and the data fed into the program was sometimes on cards as well.Шаблон:Sfn
COBOL can be written in two formats: fixed (the default) or free. In fixed-format, code must be aligned to fit in certain areas (a hold-over from using punched cards). Until COBOL 2002, these were:
Name | Column(s) | Usage |
---|---|---|
Sequence number area | 1–6 | Originally used for card/line numbers (facilitating mechanical punched card sorting to assure intended program code sequence after manual editing/handling), this area is ignored by the compiler |
Indicator area | 7 | The following characters are allowed here:
|
Area A | 8–11 | This contains: DIVISION , SECTION and procedure headers; 01 and 77 level numbers and file/report descriptors
|
Area B | 12–72 | Any other code not allowed in Area A |
Program name area | 73– | Historically up to column 80 for punched cards, it is used to identify the program or sequence the card belongs to |
In COBOL 2002, Areas A and B were merged to form the program-text area, which now ends at an implementor-defined column.Шаблон:Sfn
COBOL 2002 also introduced free-format code. Free-format code can be placed in any column of the file, as in newer programming languages. Comments are specified using *>
, which can be placed anywhere and can also be used in fixed-format source code. Continuation lines are not present, and the >>PAGE
directive replaces the /
indicator.Шаблон:Sfn
Identification division
The identification division identifies the following code entity and contains the definition of a class or interface.
Object-oriented programming
Classes and interfaces have been in COBOL since 2002. Classes have factory objects, containing class methods and variables, and instance objects, containing instance methods and variables.Шаблон:Sfn Inheritance and interfaces provide polymorphism. Support for generic programming is provided through parameterized classes, which can be instantiated to use any class or interface. Objects are stored as references which may be restricted to a certain type. There are two ways of calling a method: the Шаблон:Code statement, which acts similarly to Шаблон:Code, or through inline method invocation, which is analogous to using functions.Шаблон:Sfn
*> These are equivalent.
INVOKE my-class "foo" RETURNING var
MOVE my-class::"foo" TO var *> Inline method invocation
COBOL does not provide a way to hide methods. Class data can be hidden, however, by declaring it without a [[property (programming)|Шаблон:Code]] clause, which leaves external code no way to access it.Шаблон:Sfn Method overloading was added in COBOL 2014.Шаблон:Sfn
Environment division
The environment division contains the configuration section and the input-output section. The configuration section is used to specify variable features such as currency signs, locales and character sets. The input-output section contains file-related information.
Files
COBOL supports three file formats, or Шаблон:Dfn: sequential, indexed and relative. In sequential files, records are contiguous and must be traversed sequentially, similarly to a linked list. Indexed files have one or more indexes which allow records to be randomly accessed and which can be sorted on them. Each record must have a unique key, but other, Шаблон:Dfn, record keys need not be unique. Implementations of indexed files vary between vendors, although common implementations, such as C-ISAM and VSAM, are based on IBM's ISAM. other implementations are Record Management Services on OpenVMS and Enscribe on HPE NonStop (Tandem). Relative files, like indexed files, have a unique record key, but they do not have alternate keys. A relative record's key is its ordinal position; for example, the 10th record has a key of 10. This means that creating a record with a key of 5 may require the creation of (empty) preceding records. Relative files also allow for both sequential and random access.Шаблон:Sfn
A common non-standard extension is the Шаблон:Dfn organization, used to process text files. Records in a file are terminated by a newline and may be of varying length.[56]
Data division
The data division is split into six sections which declare different items: the file section, for file records; the working-storage section, for static variables; the local-storage section, for automatic variables; the linkage section, for parameters and the return value; the report section and the screen section, for text-based user interfaces.
Aggregated data
Data items in COBOL are declared hierarchically through the use of level-numbers which indicate if a data item is part of another. An item with a higher level-number is subordinate to an item with a lower one. Top-level data items, with a level-number of 1, are called Шаблон:Dfn. Items that have subordinate aggregate data are called Шаблон:Dfn; those that do not are called Шаблон:Dfn. Level-numbers used to describe standard data items are between 1 and 49.Шаблон:SfnШаблон:Sfn
01 some-record. *> Aggregate group record item
05 num PIC 9(10). *> Elementary item
05 the-date. *> Aggregate (sub)group record item
10 the-year PIC 9(4). *> Elementary item
10 the-month PIC 99. *> Elementary item
10 the-day PIC 99. *> Elementary item
In the above example, elementary item Шаблон:Code and group item Шаблон:Code are subordinate to the record Шаблон:Code, while elementary items Шаблон:Code, Шаблон:Code, and Шаблон:Code are part of the group item Шаблон:Code.
Subordinate items can be disambiguated with the Шаблон:Code (or Шаблон:Code) keyword. For example, consider the example code above along with the following example:
01 sale-date.
05 the-year PIC 9(4).
05 the-month PIC 99.
05 the-day PIC 99.
The names Шаблон:Code, Шаблон:Code, and Шаблон:Code are ambiguous by themselves, since more than one data item is defined with those names. To specify a particular data item, for instance one of the items contained within the Шаблон:Code group, the programmer would use Шаблон:Code (or the equivalent Шаблон:Code). This syntax is similar to the "dot notation" supported by most contemporary languages.
Other data levels
A level-number of 66 is used to declare a re-grouping of previously defined items, irrespective of how those items are structured. This data level, also referred to by the associated Шаблон:Dfn, is rarely used[57] and, circa 1988, was usually found in old programs. Its ability to ignore the hierarchical and logical structure data meant its use was not recommended and many installations forbade its use.Шаблон:Sfn
01 customer-record.
05 cust-key PIC X(10).
05 cust-name.
10 cust-first-name PIC X(30).
10 cust-last-name PIC X(30).
05 cust-dob PIC 9(8).
05 cust-balance PIC 9(7)V99.
66 cust-personal-details RENAMES cust-name THRU cust-dob.
66 cust-all-details RENAMES cust-name THRU cust-balance.
A 77 level-number indicates the item is stand-alone, and in such situations is equivalent to the level-number 01. For example, the following code declares two 77-level data items, Шаблон:Code and Шаблон:Code, which are non-group data items that are independent of (not subordinate to) any other data items:
77 property-name PIC X(80).
77 sales-region PIC 9(5).
An 88 level-number declares a Шаблон:Dfn (a so-called 88-level) which is true when its parent data item contains one of the values specified in its Шаблон:Code clause.Шаблон:Sfn For example, the following code defines two 88-level condition-name items that are true or false depending on the current character data value of the Шаблон:Code data item. When the data item contains a value of Шаблон:Code, the condition-name Шаблон:Code is true, whereas when it contains a value of Шаблон:Code or Шаблон:Code, the condition-name Шаблон:Code is true. If the data item contains some other value, both of the condition-names are false.
01 wage-type PIC X.
88 wage-is-hourly VALUE "H".
88 wage-is-yearly VALUE "S", "Y".
Data types
Standard COBOL provides the following data types:Шаблон:Sfn
Data type | Sample declaration | Notes |
---|---|---|
Alphabetic | Шаблон:Code | May contain only letters or spaces. |
Alphanumeric | Шаблон:Code | May contain any characters. |
Boolean | Шаблон:Code | Data stored in the form of 0s and 1s, as a binary number. |
Index | Шаблон:Code | Used to reference table elements. |
National | Шаблон:Code | Similar to alphanumeric, but using an extended character set, e.g. UTF-8. |
Numeric | Шаблон:Code | Contains exactly 7 digits (7=5+2). 'V' locates the implicit decimal in a fixed point number. |
Object | Шаблон:Code | May reference either an object or NULL .
|
Pointer | Шаблон:Code |
Type safety is variable in COBOL. Numeric data is converted between different representations and sizes silently and alphanumeric data can be placed in any data item that can be stored as a string, including numeric and group data.Шаблон:Sfn In contrast, object references and pointers may only be assigned from items of the same type and their values may be restricted to a certain type.Шаблон:Sfn
PICTURE clause
A Шаблон:Code (or Шаблон:Code) clause is a string of characters, each of which represents a portion of the data item and what it may contain. Some picture characters specify the type of the item and how many characters or digits it occupies in memory. For example, a Шаблон:Code indicates a decimal digit, and an Шаблон:Code indicates that the item is signed. Other picture characters (called Шаблон:Dfn and Шаблон:Dfn characters) specify how an item should be formatted. For example, a series of Шаблон:Code characters define character positions as well as how a leading sign character is to be positioned within the final character data; the rightmost non-numeric character will contain the item's sign, while other character positions corresponding to a Шаблон:Code to the left of this position will contain a space. Repeated characters can be specified more concisely by specifying a number in parentheses after a picture character; for example, Шаблон:Code is equivalent to Шаблон:Code. Picture specifications containing only digit (Шаблон:Code) and sign (Шаблон:Code) characters define purely Шаблон:Dfn data items, while picture specifications containing alphabetic (Шаблон:Code) or alphanumeric (Шаблон:Code) characters define Шаблон:Dfn data items. The presence of other formatting characters define Шаблон:Dfn or Шаблон:Dfn data items.Шаблон:Sfn
Шаблон:Code clause | Value in | Value out |
---|---|---|
Шаблон:Code | Шаблон:Code | Шаблон:Code |
Шаблон:Code | Шаблон:Code (this is legal, but results in undefined behavior)Шаблон:Sfn | |
Шаблон:Code | Шаблон:Code | " -10" (note leading spaces)
|
Шаблон:Code | Шаблон:Code | Шаблон:Code |
Шаблон:Code | Шаблон:Code | Шаблон:Code |
0
|
Шаблон:Code | |
Шаблон:Code | Шаблон:Code | Шаблон:Code |
USAGE clause
Шаблон:Missing information The Шаблон:Code clause declares the format in which data is stored. Depending on the data type, it can either complement or be used instead of a Шаблон:Code clause. While it can be used to declare pointers and object references, it is mostly geared towards specifying numeric types. These numeric formats are:Шаблон:Sfn
- Binary, where a minimum size is either specified by the
PICTURE
clause or by aUSAGE
clause such asBINARY-LONG
- Шаблон:Code, where data may be stored in whatever format the implementation provides; often equivalent to Шаблон:Code
- Шаблон:Code, the default format, where data is stored as a string
- Floating-point, in either an implementation-dependent format or according to IEEE 754
- Шаблон:Code, where data is stored as a string using an extended character set
- Шаблон:Code, where data is stored in the smallest possible decimal format (typically packed binary-coded decimal)
Report writer
The report writer is a declarative facility for creating reports. The programmer need only specify the report layout and the data required to produce it, freeing them from having to write code to handle things like page breaks, data formatting, and headings and footings.Шаблон:Sfn
Reports are associated with report files, which are files which may only be written to through report writer statements.
FD report-out REPORT sales-report.
Each report is defined in the report section of the data division. A report is split into report groups which define the report's headings, footings and details. Reports work around hierarchical Шаблон:Dfn. Control breaks occur when a key variable changes it value; for example, when creating a report detailing customers' orders, a control break could occur when the program reaches a different customer's orders. Here is an example report description for a report which gives a salesperson's sales and which warns of any invalid records:
RD sales-report
PAGE LIMITS 60 LINES
FIRST DETAIL 3
CONTROLS seller-name.
01 TYPE PAGE HEADING.
03 COL 1 VALUE "Sales Report".
03 COL 74 VALUE "Page".
03 COL 79 PIC Z9 SOURCE PAGE-COUNTER.
01 sales-on-day TYPE DETAIL, LINE + 1.
03 COL 3 VALUE "Sales on".
03 COL 12 PIC 99/99/9999 SOURCE sales-date.
03 COL 21 VALUE "were".
03 COL 26 PIC $$$$9.99 SOURCE sales-amount.
01 invalid-sales TYPE DETAIL, LINE + 1.
03 COL 3 VALUE "INVALID RECORD:".
03 COL 19 PIC X(34) SOURCE sales-record.
01 TYPE CONTROL HEADING seller-name, LINE + 2.
03 COL 1 VALUE "Seller:".
03 COL 9 PIC X(30) SOURCE seller-name.
The above report description describes the following layout:
Sales Report Page 1 Seller: Howard Bromberg Sales on 10/12/2008 were $1000.00 Sales on 12/12/2008 were $0.00 Sales on 13/12/2008 were $31.47 INVALID RECORD: Howard Bromberg XXXXYY Seller: Howard Discount ... Sales Report Page 12 Sales on 08/05/2014 were $543.98 INVALID RECORD: William Selden 12O52014FOOFOO Sales on 30/05/2014 were $0.00
Four statements control the report writer: Шаблон:Code, which prepares the report writer for printing; Шаблон:Code, which prints a report group; Шаблон:Code, which suppresses the printing of a report group; and Шаблон:Code, which terminates report processing. For the above sales report example, the procedure division might look like this:
OPEN INPUT sales, OUTPUT report-out
INITIATE sales-report
PERFORM UNTIL 1 <> 1
READ sales
AT END
EXIT PERFORM
END-READ
VALIDATE sales-record
IF valid-record
GENERATE sales-on-day
ELSE
GENERATE invalid-sales
END-IF
END-PERFORM
TERMINATE sales-report
CLOSE sales, report-out
.
Use of the Report Writer facility tends to vary considerably; some organizations use it extensively and some not at all.Шаблон:Sfn In addition, implementations of Report Writer ranged in quality, with those at the lower end sometimes using excessive amounts of memory at runtime.Шаблон:Sfn
Procedure division
Procedures
The sections and paragraphs in the procedure division (collectively called procedures) can be used as labels and as simple subroutines. Unlike in other divisions, paragraphs do not need to be in sections.Шаблон:Sfn
Execution goes down through the procedures of a program until it is terminated.Шаблон:Sfn To use procedures as subroutines, the Шаблон:Code verb is used.
A Шаблон:Code statement somewhat resembles a procedure call in a newer languages in the sense that execution returns to the code following the Шаблон:Code statement at the end of the called code; however, it does not provide a mechanism for parameter passing or for returning a result value. If a subroutine is invoked using a simple statement like Шаблон:Code, then control returns at the end of the called procedure. However, Шаблон:Code is unusual in that it may be used to call a range spanning a sequence of several adjacent procedures. This is done with the Шаблон:Code construct:
PROCEDURE so-and-so.
PERFORM ALPHA
PERFORM ALPHA THRU GAMMA
STOP RUN.
ALPHA.
DISPLAY 'A'.
BETA.
DISPLAY 'B'.
GAMMA.
DISPLAY 'C'.
The output of this program will be: "A A B C".
Шаблон:Code also differs from conventional procedure calls in that there is, at least traditionally, no notion of a call stack. As a consequence, nested invocations are possible (a sequence of code being Шаблон:Code'ed may execute a Шаблон:Code statement itself), but require extra care if parts of the same code are executed by both invocations. The problem arises when the code in the inner invocation reaches the exit point of the outer invocation. More formally, if control passes through the exit point of a Шаблон:Code invocation that was called earlier but has not yet completed, the COBOL 2002 standard stipulates that the behavior is undefined.
The reason is that COBOL, rather than a "return address", operates with what may be called a continuation address. When control flow reaches the end of any procedure, the continuation address is looked up and control is transferred to that address. Before the program runs, the continuation address for every procedure is initialized to the start address of the procedure that comes next in the program text so that, if no Шаблон:Code statements happen, control flows from top to bottom through the program. But when a Шаблон:Code statement executes, it modifies the continuation address of the called procedure (or the last procedure of the called range, if Шаблон:Code was used), so that control will return to the call site at the end. The original value is saved and is restored afterwards, but there is only one storage position. If two nested invocations operate on overlapping code, they may interfere which each other's management of the continuation address in several ways.[58][59]
The following example (taken from Шаблон:Harvnb) illustrates the problem:
LABEL1.
DISPLAY '1'
PERFORM LABEL2 THRU LABEL3
STOP RUN.
LABEL2.
DISPLAY '2'
PERFORM LABEL3 THRU LABEL4.
LABEL3.
DISPLAY '3'.
LABEL4.
DISPLAY '4'.
One might expect that the output of this program would be "1 2 3 4 3": After displaying "2", the second Шаблон:Code causes "3" and "4" to be displayed, and then the first invocation continues on with "3". In traditional COBOL implementations, this is not the case. Rather, the first Шаблон:Code statement sets the continuation address at the end of Шаблон:Code so that it will jump back to the call site inside Шаблон:Code. The second Шаблон:Code statement sets the return at the end of Шаблон:Code but does not modify the continuation address of Шаблон:Code, expecting it to be the default continuation. Thus, when the inner invocation arrives at the end of Шаблон:Code, it jumps back to the outer Шаблон:Code statement, and the program stops having printed just "1 2 3". On the other hand, in some COBOL implementations like the open-source TinyCOBOL compiler, the two Шаблон:Code statements do not interfere with each other and the output is indeed "1 2 3 4 3". Therefore, the behavior in such cases is not only (perhaps) surprising, it is also not portable.[59]
A special consequence of this limitation is that Шаблон:Code cannot be used to write recursive code. Another simple example to illustrate this (slightly simplified from Шаблон:Harvnb):
MOVE 1 TO A
PERFORM LABEL
STOP RUN.
LABEL.
DISPLAY A
IF A < 3
ADD 1 TO A
PERFORM LABEL
END-IF
DISPLAY 'END'.
One might expect that the output is "1 2 3 END END END", and in fact that is what some COBOL compilers will produce. But other compilers, like IBM COBOL, will produce code that prints "1 2 3 END END END END ..." and so on, printing "END" over and over in an endless loop. Since there is limited space to store backup continuation addresses, the backups get overwritten in the course of recursive invocations, and all that can be restored is the jump back to Шаблон:Code.[59]
Statements
COBOL 2014 has 47 statements (also called Шаблон:Dfn),Шаблон:Sfn which can be grouped into the following broad categories: control flow, I/O, data manipulation and the report writer. The report writer statements are covered in the report writer section.
Control flow
COBOL's conditional statements are Шаблон:Code and Шаблон:Code. Шаблон:Code is a switch-like statement with the added capability of evaluating multiple values and conditions. This can be used to implement decision tables. For example, the following might be used to control a CNC lathe:
EVALUATE TRUE ALSO desired-speed ALSO current-speed
WHEN lid-closed ALSO min-speed THRU max-speed ALSO LESS THAN desired-speed
PERFORM speed-up-machine
WHEN lid-closed ALSO min-speed THRU max-speed ALSO GREATER THAN desired-speed
PERFORM slow-down-machine
WHEN lid-open ALSO ANY ALSO NOT ZERO
PERFORM emergency-stop
WHEN OTHER
CONTINUE
END-EVALUATE
The Шаблон:Code statement is used to define loops which are executed Шаблон:Em a condition is true (not Шаблон:Em true, which is more common in other languages). It is also used to call procedures or ranges of procedures (see the procedures section for more details). Шаблон:Code and Шаблон:Code call subprograms and methods, respectively. The name of the subprogram/method is contained in a string which may be a literal or a data item.Шаблон:Sfn Parameters can be passed by reference, by content (where a copy is passed by reference) or by value (but only if a prototype is available).Шаблон:Sfn Шаблон:Code unloads subprograms from memory. Шаблон:Code causes the program to jump to a specified procedure.
The Шаблон:Code statement is a return statement and the Шаблон:Code statement stops the program. The Шаблон:Code statement has six different formats: it can be used as a return statement, a break statement, a continue statement, an end marker or to leave a procedure.Шаблон:Sfn
Exceptions are raised by a Шаблон:Code statement and caught with a handler, or Шаблон:Dfn, defined in the Шаблон:Code portion of the procedure division. Declaratives are sections beginning with a Шаблон:Code statement which specify the errors to handle. Exceptions can be names or objects. Шаблон:Code is used in a declarative to jump to the statement after the one that raised the exception or to a procedure outside the Шаблон:Code. Unlike other languages, uncaught exceptions may not terminate the program and the program can proceed unaffected.
I/O
File I/O is handled by the self-describing Шаблон:Code, Шаблон:Code, Шаблон:Code, and Шаблон:Code statements along with a further three: Шаблон:Code, which updates a record; Шаблон:Code, which selects subsequent records to access by finding a record with a certain key; and Шаблон:Code, which releases a lock on the last record accessed.
User interaction is done using Шаблон:Code and Шаблон:Code.
Data manipulation
The following verbs manipulate data:
- Шаблон:Code, which sets data items to their default values.
- Шаблон:Code, which assigns values to data items ; MOVE CORRESPONDING assigns corresponding like-named fields.
- Шаблон:Code, which has 15 formats: it can modify indices, assign object references and alter table capacities, among other functions.Шаблон:Sfn
- Шаблон:Code, Шаблон:Code, Шаблон:Code, Шаблон:Code, and Шаблон:Code, which handle arithmetic (with Шаблон:Code assigning the result of a formula to a variable).
- Шаблон:Code and Шаблон:Code, which handle dynamic memory.
- Шаблон:Code, which validates and distributes data as specified in an item's description in the data division.
- Шаблон:Code and Шаблон:Code, which concatenate and split strings, respectively.
- Шаблон:Code, which tallies or replaces instances of specified substrings within a string.
- Шаблон:Code, which searches a table for the first entry satisfying a condition.
Files and tables are sorted using Шаблон:Code and the Шаблон:Code verb merges and sorts files. The Шаблон:Code verb provides records to sort and Шаблон:Code retrieves sorted records in order.
Scope termination
Some statements, such as Шаблон:Code and Шаблон:Code, may themselves contain statements. Such statements may be terminated in two ways: by a period (Шаблон:Dfn), which terminates all unterminated statements contained, or by a scope terminator, which terminates the nearest matching open statement.
*> Terminator period ("implicit termination")
IF invalid-record
IF no-more-records
NEXT SENTENCE
ELSE
READ record-file
AT END SET no-more-records TO TRUE.
*> Scope terminators ("explicit termination")
IF invalid-record
IF no-more-records
CONTINUE
ELSE
READ record-file
AT END SET no-more-records TO TRUE
END-READ
END-IF
END-IF
Nested statements terminated with a period are a common source of bugs.Шаблон:SfnШаблон:Sfn For example, examine the following code:
IF x
DISPLAY y.
DISPLAY z.
Here, the intent is to display y
and z
if condition x
is true. However, z
will be displayed whatever the value of x
because the IF
statement is terminated by an erroneous period after Шаблон:Code.
Another bug is a result of the dangling else problem, when two IF
statements can associate with an ELSE
.
IF x
IF y
DISPLAY a
ELSE
DISPLAY b.
In the above fragment, the ELSE
associates with the Шаблон:Code statement instead of the Шаблон:Code statement, causing a bug. Prior to the introduction of explicit scope terminators, preventing it would require Шаблон:Code to be placed after the inner IF
.Шаблон:Sfn
Self-modifying code
The original (1959) COBOL specification supported the infamous Шаблон:Code statement, for which many compilers generated self-modifying code. X
and Y
are procedure labels, and the single Шаблон:Code statement in procedure X
executed after such an Шаблон:Code statement means Шаблон:Code instead. Many compilers still support it,[60] but it was deemed obsolete in the COBOL 1985 standard and deleted in 2002.Шаблон:Sfn
The Шаблон:Code statement was poorly regarded because it undermined "locality of context" and made a program's overall logic difficult to comprehend.Шаблон:Sfn As textbook author Daniel D. McCracken wrote in 1976, when "someone who has never seen the program before must become familiar with it as quickly as possible, sometimes under critical time pressure because the program has failed ... the sight of a GO TO statement in a paragraph by itself, signaling as it does the existence of an unknown number of ALTER statements at unknown locations throughout the program, strikes fear in the heart of the bravest programmer."Шаблон:Sfn
Hello, world
A "Hello, world" program in COBOL:
IDENTIFICATION DIVISION.
PROGRAM-ID. hello-world.
PROCEDURE DIVISION.
DISPLAY "Hello, world!"
.
When the now famous "Hello, World!" program example in The C Programming Language was first published in 1978 a similar mainframe COBOL program sample would have been submitted through JCL, very likely using a punch card reader, and 80 column punch cards. The listing below, with an empty DATA DIVISION, was tested using Linux and the System/370 Hercules emulator running MVS 3.8J. The JCL, written in July 2015, is derived from the Hercules tutorials and samples hosted by Jay Moseley.[61] In keeping with COBOL programming of that era, HELLO, WORLD is displayed in all capital letters.
//COBUCLG JOB (001),'COBOL BASE TEST', 00010000
// CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1) 00020000
//BASETEST EXEC COBUCLG 00030000
//COB.SYSIN DD * 00040000
00000* VALIDATION OF BASE COBOL INSTALL 00050000
01000 IDENTIFICATION DIVISION. 00060000
01100 PROGRAM-ID. 'HELLO'. 00070000
02000 ENVIRONMENT DIVISION. 00080000
02100 CONFIGURATION SECTION. 00090000
02110 SOURCE-COMPUTER. GNULINUX. 00100000
02120 OBJECT-COMPUTER. HERCULES. 00110000
02200 SPECIAL-NAMES. 00120000
02210 CONSOLE IS CONSL. 00130000
03000 DATA DIVISION. 00140000
04000 PROCEDURE DIVISION. 00150000
04100 00-MAIN. 00160000
04110 DISPLAY 'HELLO, WORLD' UPON CONSL. 00170000
04900 STOP RUN. 00180000
//LKED.SYSLIB DD DSNAME=SYS1.COBLIB,DISP=SHR 00190000
// DD DSNAME=SYS1.LINKLIB,DISP=SHR 00200000
//GO.SYSPRINT DD SYSOUT=A 00210000
// 00220000
After submitting the JCL, the MVS console displayed:
19.52.48 JOB 3 $HASP100 COBUCLG ON READER1 COBOL BASE TEST
19.52.48 JOB 3 IEF677I WARNING MESSAGE(S) FOR JOB COBUCLG ISSUED
19.52.48 JOB 3 $HASP373 COBUCLG STARTED - INIT 1 - CLASS A - SYS BSP1
19.52.48 JOB 3 IEC130I SYSPUNCH DD STATEMENT MISSING
19.52.48 JOB 3 IEC130I SYSLIB DD STATEMENT MISSING
19.52.48 JOB 3 IEC130I SYSPUNCH DD STATEMENT MISSING
19.52.48 JOB 3 IEFACTRT - Stepname Procstep Program Retcode
19.52.48 JOB 3 COBUCLG BASETEST COB IKFCBL00 RC= 0000
19.52.48 JOB 3 COBUCLG BASETEST LKED IEWL RC= 0000
19.52.48 JOB 3 +HELLO, WORLD
19.52.48 JOB 3 COBUCLG BASETEST GO PGM=*.DD RC= 0000
19.52.48 JOB 3 $HASP395 COBUCLG ENDED
Line 10 of the console listing above is highlighted for effect, the highlighting is not part of the actual console output.
The associated compiler listing generated over four pages of technical detail and job run information, for the single line of output from the 14 lines of COBOL.
Reception
Lack of structure
In the 1970s, adoption of the structured programming paradigm was becoming increasingly widespread. Edsger Dijkstra, a preeminent computer scientist, wrote a letter to the editor of Communications of the ACM, published in 1975 entitled "How do we tell truths that might hurt?", in which he was critical of COBOL and several other contemporary languages; remarking that "the use of COBOL cripples the mind".[62]
In a published dissent to Dijkstra's remarks, the computer scientist Howard E. Tompkins claimed that unstructured COBOL tended to be "written by programmers that have never had the benefit of structured COBOL taught well", arguing that the issue was primarily one of training.[63]
One cause of spaghetti code was the Шаблон:Code statement. Attempts to remove Шаблон:Codes from COBOL code, however, resulted in convoluted programs and reduced code quality.Шаблон:Sfn Шаблон:Codes were largely replaced by the Шаблон:Code statement and procedures, which promoted modular programmingШаблон:Sfn and gave easy access to powerful looping facilities. However, Шаблон:Code could be used only with procedures so loop bodies were not located where they were used, making programs harder to understand.Шаблон:Sfn
COBOL programs were infamous for being monolithic and lacking modularization.[64] COBOL code could be modularized only through procedures, which were found to be inadequate for large systems. It was impossible to restrict access to data, meaning a procedure could access and modify Шаблон:Em data item. Furthermore, there was no way to pass parameters to a procedure, an omission Jean Sammet regarded as the committee's biggest mistake.Шаблон:Sfn
Another complication stemmed from the ability to Шаблон:Code a specified sequence of procedures. This meant that control could jump to and return from any procedure, creating convoluted control flow and permitting a programmer to break the single-entry single-exit rule.Шаблон:Sfn
This situation improved as COBOL adopted more features. COBOL-74 added subprograms, giving programmers the ability to control the data each part of the program could access. COBOL-85 then added nested subprograms, allowing programmers to hide subprograms.Шаблон:Sfn Further control over data and code came in 2002 when object-oriented programming, user-defined functions and user-defined data types were included.
Nevertheless, much important legacy COBOL software uses unstructured code, which has become practically unmaintainable. It can be too risky and costly to modify even a simple section of code, since it may be used from unknown places in unknown ways.[65]
Compatibility issues
COBOL was intended to be a highly portable, "common" language. However, by 2001, around 300 dialects had been created.[66] One source of dialects was the standard itself: the 1974 standard was composed of one mandatory nucleus and eleven functional modules, each containing two or three levels of support. This permitted 104,976 possible variants.[67]
COBOL-85 was not fully compatible with earlier versions, and its development was controversial. Joseph T. Brophy, the CIO of Travelers Insurance, spearheaded an effort to inform COBOL users of the heavy reprogramming costs of implementing the new standard.Шаблон:Sfn As a result, the ANSI COBOL Committee received more than 2,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.Шаблон:Sfn
Verbose syntax
COBOL syntax has often been criticized for its verbosity. Proponents say that this was intended to make the code self-documenting, easing program maintenance.Шаблон:Sfn COBOL was also intended to be easy for programmers to learn and use,Шаблон:Sfn while still being readable to non-technical staff such as managers.Шаблон:SfnШаблон:SfnШаблон:SfnШаблон:Sfn
The desire for readability led to the use of English-like syntax and structural elements, such as nouns, verbs, clauses, sentences, sections, and divisions. Yet by 1984, maintainers of COBOL programs were struggling to deal with "incomprehensible" codeШаблон:Sfn and the main changes in COBOL-85 were there to help ease maintenance.[32]
Jean Sammet, a short-range committee member, noted that "little attempt was made to cater to the professional programmer, in fact people whose main interest is programming tend to be very unhappy with COBOL" which she attributed to COBOL's verbose syntax.Шаблон:Sfn
Isolation from the computer science community
The COBOL community has always been isolated from the computer science community. No academic computer scientists participated in the design of COBOL: all of those on the committee came from commerce or government. Computer scientists at the time were more interested in fields like numerical analysis, physics and system programming than the commercial file-processing problems which COBOL development tackled.Шаблон:Sfn Jean Sammet attributed COBOL's unpopularity to an initial "snob reaction" due to its inelegance, the lack of influential computer scientists participating in the design process and a disdain for business data processing.Шаблон:Sfn The COBOL specification used a unique "notation", or metalanguage, to define its syntax rather than the new Backus–Naur form which the committee did not know of. This resulted in "severe" criticism.Шаблон:SfnШаблон:SfnШаблон:Sfn
Later, COBOL suffered from a shortage of material covering it; it took until 1963 for introductory books to appear (with Richard D. Irwin publishing a college textbook on COBOL in 1966).[68] By 1985, there were twice as many books on FORTRAN and four times as many on BASIC as on COBOL in the Library of Congress.Шаблон:Sfn University professors taught more modern, state-of-the-art languages and techniques instead of COBOL which was said to have a "trade school" nature.Шаблон:Sfn Donald Nelson, chair of the CODASYL COBOL committee, said in 1984 that "academics ... hate COBOL" and that computer science graduates "had 'hate COBOL' drilled into them".[69]
By the mid-1980s, there was also significant condescension towards COBOL in the business community from users of other languages, for example FORTRAN or assembler, implying that COBOL could be used only for non-challenging problems.[70]
In 2003, COBOL featured in 80% of information systems curricula in the United States, the same proportion as C++ and Java.Шаблон:Sfn Ten years later, a poll by Micro Focus found that 20% of university academics thought COBOL was outdated or dead and that 55% believed their students thought COBOL was outdated or dead. The same poll also found that only 25% of academics had COBOL programming on their curriculum even though 60% thought they should teach it.[71]
Concerns about the design process
Doubts have been raised about the competence of the standards committee. Short-term committee member Howard Bromberg said that there was "little control" over the development process and that it was "plagued by discontinuity of personnel and ... a lack of talent."Шаблон:Sfn Jean Sammet and Jerome Garfunkel also noted that changes introduced in one revision of the standard would be reverted in the next, due as much to changes in who was in the standard committee as to objective evidence.[72]
COBOL standards have repeatedly suffered from delays: COBOL-85 arrived five years later than hoped,[73] COBOL 2002 was five years late,[39] and COBOL 2014 was six years late.[41][74] To combat delays, the standard committee allowed the creation of optional addenda which would add features more quickly than by waiting for the next standard revision. However, some committee members raised concerns about incompatibilities between implementations and frequent modifications of the standard.[75]
Influences on other languages
COBOL's data structures influenced subsequent programming languages. Its record and file structure influenced PL/I and Pascal, and the REDEFINES
clause was a predecessor to Pascal's variant records. Explicit file structure definitions preceded the development of database management systems and aggregated data was a significant advance over Fortran's arrays.Шаблон:Sfn
PICTURE
data declarations were incorporated into PL/I, with minor changes.
COBOL's Шаблон:Code facility, although considered "primitive",Шаблон:Sfn influenced the development of include directives.Шаблон:Sfn
The focus on portability and standardization meant programs written in COBOL could be portable and facilitated the spread of the language to a wide variety of hardware platforms and operating systems.[76] Additionally, the well-defined division structure restricts the definition of external references to the Environment Division, which simplifies platform changes in particular.[77]
See also
- Alphabetical list of programming languages
- BLIS/COBOL
- CODASYL
- Comparison of programming languages
- Шаблон:Slink
- Шаблон:Slink
Notes
References
Citations
Sources
- Шаблон:Cite journal
- Шаблон:Cite book
- Шаблон:Cite journal
- Шаблон:Cite book
- Шаблон:Cite book
- Шаблон:Cite web (Link goes to draft N 0147)
- Шаблон:Cite book
- Шаблон:Cite book
- Шаблон:Cite web
- Шаблон:Cite conference
- Шаблон:Cite conference
- Шаблон:Cite book
- Шаблон:Cite book
- Шаблон:Cite journal
- Шаблон:Cite conference
- Шаблон:Cite conference
- Шаблон:Cite conference
- Шаблон:Cite book
- Шаблон:Cite journal
External links
- Шаблон:Webarchive
- Шаблон:Webarchive
- Шаблон:Curlie
- COBOL Language Standard (1991; COBOL-85 with Amendment 1), from The Open Group
Шаблон:Major programming languages Шаблон:ISO standards Шаблон:List of IEC standards Шаблон:Authority control
- ↑ 1,0 1,1 1,2 Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite magazine
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite magazine
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite news
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite news
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite book
- ↑ 23,0 23,1 23,2 23,3 Шаблон:Cite encyclopedia
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite report
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ 31,0 31,1 31,2 Шаблон:Cite journal
- ↑ 32,0 32,1 Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite web
- ↑ 39,0 39,1 Шаблон:Cite web
- ↑ Шаблон:Cite book
- ↑ 41,0 41,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ 44,0 44,1 Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite magazine
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite news
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite conference
- ↑ 59,0 59,1 59,2 Шаблон:Cite journal
- ↑ Examples of compiler support for Шаблон:Code can be seen in the following:
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite book
- ↑ Шаблон:Cite press release
- ↑ Шаблон:Cite journal
- ↑ Шаблон:Cite conference
- ↑ Шаблон:Cite web
- ↑ Шаблон:Cite journal
- ↑ This can be seen in:
- ↑ Шаблон:Cite web
- Английская Википедия
- Страницы с неработающими файловыми ссылками
- COBOL
- .NET programming languages
- 1959 software
- Class-based programming languages
- Computer-related introductions in 1959
- Cross-platform software
- Object-oriented programming languages
- Procedural programming languages
- Programming languages created by women
- Programming languages created in 1959
- Programming languages with an ISO standard
- Statically typed programming languages
- Structured programming languages
- Страницы, где используется шаблон "Навигационная таблица/Телепорт"
- Страницы с телепортом
- Википедия
- Статья из Википедии
- Статья из Английской Википедии