The COBOL-85 Tutorial, Chapter 11
COBOL and design.
Copyright © 1998-2017 Kim Kjærsulf.
Relationship between module diagrams and COBOL.
Relationship between objects and COBOL.
COBOL and relational databases.
E-SQL.
ISAM files as a "database".
Exercises
[This chapter]
[TOC]
[Tutorial]
There are two ways in which a module diagram can be implemented in COBOL:
- The standard method, using many global variables and thereby ignoring data parameters on the module diagram.
- Using local subprograms to implement a module diagram in the same way as in Pascal or C.
External modules can be either copied in using COPY or, if the module is an independent COBOL program, called with CALL.
[This chapter]
[TOC]
[Tutorial]
To talk about object-oriented design and COBOL would sound almost comical in some ears. However, even though COBOL does not support inheritance and polymorphism, its subprograms do make it possible to work with reasonable data encapsulation.
Using GO TO ... DEPENDING it is possible to implement polymorphism by controlling the object type in a local variable.
Inheritance is more difficult to cope with, but there there's a will … all inherited attributes are copied to the derived classes.
Multiple instances of object types - the actual objects - cannot be created dynamically because of the lack of pointers in COBOL. My suggestion is to estimate the needed number and then define a table. If the number is very large an isam-file can be applied.
There is one major drawback - which is certainly not unique to COBOL - and that is that the language syntax does not support the object-oriented concepts. This means that introducing changes at a later stage is difficult and involve the programmer checking many potential errors. The alternative is letting the compiler find them.
[This chapter]
[TOC]
[Tutorial]
No matter which language a design is implemented in, it is relevant that data modelling is carried out respecting relational principles. This chapter looks at the possibilities of using just such a design with COBOL.
[This chapter]
[TOC]
[Tutorial]
Using an embedded SQL in COBOL is possible, but of course only if there is access to such a product. As COBOL is not set-oriented as SQL, it is necessary to process the result of a query as a sequential file.
E-SQL products usually function in such a way that special statements are written between the normal COBOL instructions. These statements are then converted during compilation to CALL and MOVE instructions. I will also refer you to some product manuals.
[This chapter]
[TOC]
[Tutorial]
A relational design can easily be implemented using COBOL index-sequential files, but these lack some important facilities related to introducing changes to the structure of the model, and for queries.
Each relation (table) is implemented as a file. Keys are to be specified in the description of the file, where necessary with unique values.
Queries based on keys are dealt with easily - even within intervals.
Queries on other than keys require a sequential scan of the file.
Joins between tables can be made either via keys or by using a sequential merge.
Changes to the size or data type of fields, and the addition or removal of fields requires two things:
- That the file is converted (requires a special program)
- A change to and recompilation of the source.
The change procedure is made much easier by using COBOL's COPY statement, which is in fact a compiler directive. COPY is comparable to "include" in C and Pascal. File and record descriptions are made as independent source files, which are copied in during compilation. When adding a COPY element of this type it is possible to use COBOL's REPLACE to carry out a textual substitution, for example, of field names.
[This chapter]
[TOC]
[Tutorial]
The purpose of this exercise is to train the following points:
- COBOL's facilities for handling index-sequential files in dynamic mode.
- Further training in working with index-sequential files, and examples of "JOIN" between "tables".
Create an index-sequential file with the customer names. The customer number is to be the key to this file.
Extend the customer header in the report from exercise 1 of chapter 10 to also include customer name.
Model answer for this exercise.
Model answer for this exercise.
This chapter
Copyright © 1998-2017 Kim Kjærsulf
Last Updated october 3, 2003
For more information contact: Kim Kjærsulf