|
3.4 The PROCEDURE DIVISION
The procedure division is where the logic of the program actually found. Here is where the various commands are
written (see Commands and logic section).
COBOL is a modular language, in that a program is usually broken up into units described as paragraphs.
Sub-programs A program may also refer to a different program, called a sub-program. A sub-program is an entirely different program from the calling program, with its own divisions etc... with the exception that it does not end with STOP RUN (which would return you to the operating system), but with EXIT PROGRAM. The sub-program is a module, rather than a subroutine which is what a paragraph could be described as. The verb CALL is used to activate the sub-program:
In order to use data from the calling program in the sub-program the calling program uses a section in the data division called the LINKAGE SECTION. The item W-DATE-IN in the calling program occupies the same memory address as the sub-program's item L-DATE-IN, so the number placed in W-DATE-IN item using the VALUE clause is also in L-DATE-IN. Note: you cannot use VALUE in the linkage section. The procedure division of the sub-program requiring the use of linkage section defined data must say so by: PROCEDURE DIVISION USING ...[linkage section items to be used] also refered to by the CALL ... USING. See lines 000930 and 3500 above. In the above example, what is being called ("VALIDATE-DATE") is a literal. This means that you could use an identifier
instead, allowing you a choice between sub-programs depending on what the literal had been previously defined as.
For example, if a record was of type "A" then you may want to process that record using sub-program PROCESS-A-REC,
but if a type "B" record the use PROCESS-B-REC.
|