COMTRAN Reconstruction

F28-8043 · June 1960

Page 52

PDF page 58 of 124. Download the scanned PDF

The page as scanned

The scan of PDF page 58 of F28-8043
Select the scan to open it at full size.

The text read off it

[page 52]

The DO Command with Data Substitution

Frequently, a procedure which has been written for a particular purpose can be used at some other point in a program only if provision is made to substitute different items of data to be operated on by the procedure. Such substitution could be specified by writing appropriate MOVE commands in conjunction with the second DO command. For example, if a procedure operates on three pieces of data called A, B, and C and produces two results, D and E, the programmer could use the procedure with other items of data by writing:

MOVE V TO A.
MOVE W TO B.
MOVE X TO C.
DO PROCEDURE.
MOVE D TO Y.
MOVE E TO Z.

Since this method is somewhat laborious, the Commercial Translator language provides a facility for writing procedures in a generalized form in order to accomplish the same result. Procedures which are to be used with data substitution are always defined by the two processor commands "BEGIN SECTION USING . . . GIVING . . ." and "END" (see page 56).

Data substitution can be specified in each of the several forms of the DO command. When this feature is utilized, the general form of the simplest DO becomes:

DO procedure.name USING data.name.1, data.name.2, ...
     data.name.n GIVING result.name.1, result.name.2 ...
     result.name.n

Similarly, if data substitution is desired in the other forms of the DO command, the "USING . . . GIVING . . ." option is simply appended to the command.

The "data.names" in the command specify the variable data, constants or literals which, at object time, are substituted for the data represented by the corresponding names (parameters) that appear in the "procedure.name" routine. Likewise, the "result.names" are the names which become associated with the outputs of the subroutine.

The data substitution feature of the language being discussed here should not be confused with name substitution, which is another feature of Commercial Translator. Name substitution is effected by the INCLUDE command and occurs at processing time; it involves the replacement of names in library procedures that are being incorporated in a program (see page 58).

To illustrate data substitution using a more complete example, suppose that the following procedure has already been written into a program. This procedure is designed to determine a minimum value:

MIN.ROUT.  BEGIN SECTION USING A, B, C GIVING MIN.
     IF A IS LESS THAN B THEN MOVE A TO MIN OTHERWISE MOVE
          B TO MIN.
     IF C IS LESS THAN MIN THEN MOVE C TO MIN.
END MIN.ROUT.

In one portion of his program the programmer might have used this MIN.ROUT procedure to determine the lowest of three rates called R.RATE, E.RATE, and M.RATE using the command: