COMTRAN Reconstruction

F28-8043 · June 1960

Page 17

PDF page 23 of 124. Download the scanned PDF

The page as scanned

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

The text read off it

[page 17]

Constants

It has been emphasized that data-names used in the Commercial Translator system generally refer to kinds of data, not to specific values. The actual values represented by most data-names are assumed to be variable, and they will either be entered into the system as parts of input files when the object program is run or they will be computed at some point in the program.

However, the programmer will often find it useful to be able to place a specific fixed value into the program instead of having to read it in as data. For example, if a firm allows a discount on its bills, the discount will usually be figured as a fixed percentage. The routine for computing the discount, therefore, does not require any provisions for inserting varying percentage rates. Thus, it would be convenient to be able to write this rate directly into the program.

Any value—or any group of symbols—which is to be used in the program without alteration is called a constant. The programmer will find many uses for numeric constants, such as the discount rate mentioned, for alphabetic constants, such as names and titles to be printed out on final reports, and for alphameric constants, which may serve any number of purposes.

In some circumstances, it will be convenient to write the constant directly in a procedure statement. In this case it will be called a literal. In other cases, it will be more convenient to give the constant a name and store it within the system so that it can be called for by name when required. In this case it will be called a named constant.

As an aid to the programmer, certain standard constants, such as the value 0 and the blank, have been "pre-named." These values are defined in the processor itself, and they have already been given names. Thus, the programmer can write these names in the procedure statements without having to define them in the data description. These special constants, called figurative constants, will be discussed later in this section.

Literals and named constants may be used in procedure statements for the same purposes for which data-names are used—that is, as "operands" (i.e., "objects") of Commercial Translator verbs. The essential difference between them is that a literal expresses an actual value—a value to be read "literally" at the point where it is written—whereas a named constant is the name of such a value, and it cannot be used, or interpreted, in a procedure statement until it has been defined in the data description.

The following example will show the difference between literals and named constants:

Assume that a discount is to be computed by multiplying the amount of an order by a discount percentage of two per cent. The programmer might write such a statement as

SET DISCOUNT = ORDER.AMOUNT * .02.

This command would instruct the system to take whatever value was in the field called ORDER.AMOUNT, multiply it by the value .02, and place the result in the field called DISCOUNT.

On the other hand, the programmer could place the value .02 in storage, giving it a name such as DISCOUNT.PERCENTAGE, and then write such a statement as