|★ APPLICATIONS ★ PROGRAMMATION ★ NEVADA COBOL (c) HISOFT ★|
|Coding - Hisoft - Nevada Cobol||Applications Programmation|
Around 1966, Grace Hopper (who coined the phrase "bug", when she found that the reason for a program crash was a dead insect shorting out a relay) created a high level language for the American Department of Defence and called it Cobol; an acronym for Common Business Oriented Language. Its main advantage is that the program source code is very close to English, which makes it very easy to read and therefore de-bug. This, among other reasons is why Cobol is still widely used for writing business applications.
Unlike most implementations of Basic, which are interpreted, Cobol is compiled. The difference being, that interpreting a program means turning every instruction of the program into machine code as it is run, as opposed to turning the whole program into machine code before running it, as compiling does. The main difference between these two methods is speed. As no conversion work has to be done during the running of a compiled program, it executes much faster.
Cobol is available only for a few home micros, but due to the availability of CP/M on the Amstrad machines, it is now another language option, open to the serious Amstrad user. Although Cobol is faster than Basic, do not go and buy it thinking that you will be writing super fast, graphics and arcade games. Cobol is a business language and has little or no support for graphics.
The implementation of Cobol available on the Amstrad, is Nevada Cobol. It is one of the more popular versions of the language, if not the most complete. Other versions, such as CIS and Microsoft have larger and more powerful instruction sets, but do cost many times more.
Cobol is quite a verbose language and at first sight seems over complicated. To demonstrate, a program to input and then print a person's name would be.
(Please note. The line numbers are only for de-bugging and are not used like Basic line numbers within the program.)
As you can see, this is a bit more long winded than it would be in Basic, but do not be intimidated. The start of the program (The IDENTIFICATION DIVISION), contains data for anyone looking at the source code and shows what the program is, and who wrote it. This is followed by the ENVIRONMENT DIVISION that contains more data for the programmer about what computer the software was written on and what hardware is needed to run it. This division may also have an input-output section containing details about any files to be used in the program. The above example also contains "file-control" that tells the computer facts about files to be used. This information includes the type of file (usually disc or printer) and for disc files, the type of file to be used, be it Sequential or Relative, the access type, be it sequential or random, as well as relative file key, and file status variable assignments.
The first two lines are the file definition and give more information about the file including the name to be used when accessing the disc. The number at the start of each line is a level number. The higher the number is, the lower the level. Above, the level NAME-AND-ADDRESS, which is a level 01, contains all the other data, and by the same token, all the data from the FORENAME to the SURNAME is contained within NAME. Therefore, referring to NAME would include the forename and surname! together with a separating space). The X(number) on most of the lines refers to the data to be held in each data name. The X tells the compiler that the data is alphanumeric, and could be replaced by such characters as 9,Z or . to denote numeric data, leading zero supression and a decimal point respectively. Other options include holding numbers in packed decimal or in binary form.
The number in the brackets is just shorthand. Instead of a ten character data name being defined by PIC XXXXXXXXXX, you can put PIC X(10). The data name FILLER is commonly used in Cobol and is recognised by the compiler as memory that must be reserved (in this case for a space between the two names), but which does not have to be specifically referenced. There is also a VALUE verb that could be used to fill any data names with specific data at the start of the program. The variable FRED, is an 88 level, which is an exception to the rule of level numbers, and will be explained later.
After all the data has been defined, the actual program code is entered in the final program division, called the PROCEDURE DIVISION. Apart from the actual instructions, there are SECTION and PARAGRAPH headers. These are two levels of label used by Cobol. A section may contain many paragraphs and is shown as a label followed by the word SECTION. The compiler can differentiate between labels and program statements by their position.
The code can refer to labels by way of two statements. These are GO TO and PERFORM which act like GOTO and GOSUB in Basic. The GO TO statement transfers control of the program to the relevant part of the program as does the PERFORM statement, but with the latter, the following happens. If a SECTION was PERFORMed, then the program continues until either the end of that SECTION, or an EXIT statement is encountered. At this point, control of the program returns to the statement after the PERFORM. If a PARAGRAPH was PERFORMed, then control returns at the end of that PARAGRAPH.
Descisions may be made in Cobol using the IF verb. IF statements may be nested to form quite complicated structures.
IF statements can be made more readable by "88 levels" in the DATA DIVISION. For example, the above IF statement could be written as:-
Where the DATA DIVISION contains:-
"88 level's" are used a great deal in Cobol and as you can see they make programs more readable as there is less logic to wade through.
In Cobol, the answer to any mathematical function is held in the second data-name unless the GIVING verb is used to direct the answer elsewhere.
The Nevada Cobol package has one feature that I found annoying. Whereas other Cobol implementations produce a listing file when they are compiled that contains line numbers and a list of errors, Nevada source codes must be first passed through a program called "RENUMBER" to give it line numbers, as in the example program above, and then compiled. The compiler then tells you where the errors are and you must write them down and refer to the source code. If you have a printer then using control P to get an error listing is invaluable. Finally, although the manual shows an extensive list of error messages, most errors seem to be treated as "syntax errors" which makes de-bugging a slower business than it should be.
To sum up, if you want to write your own applications for your 464 (with disc) or 664, or just want a version of Cobol on your machine, then Nevada Cobol is very adequate and at only £39.95, compared with several hundred pounds for other versions, it constitutes very good value for money.