Information Technology Reference
In-Depth Information
10. Assigning values
In the last chapter we saw the keyword
value
as well as the use of the assign statement, which is accomplished by the equal sign.
Before proceeding, let us look at some examples of both these concepts since there are
two different ways of accomplishing the same result. The
value
keyword allows us to give a variable some initial value. Thus
define x integer( 5) value 7
results in the field
x
being equal to 7 , while
define y decimal (2.2) value 3.1
results in the field
y
being 03.10. In the first case
x
consists of five positions with the last being 7, preceded by four leading zeroes. The
values 7 and 00007 are equal. The computer will store that number with the leading
zeroes. In a similar manner, 3.1 = 03.10, but the computer will actually have 0310 for this
field without the decimal point, and it is understood to be there. In our programs we don't
need to specify leading zeroes if fields are defined integer or decimal. For character fields
we have to supply leading zeroes, if they exist. Consider the following:
define soc-sec-no character (9) value “45169123”
This will result in that variable being the eight characters above followed by a space
which is in the ninth position. As of today, that is not a valid social security number. If we
really wanted the first position to be a leading zero as in some social security numbers,
our value clause would have to be
value “045169123”
rather than
value “45169123” .
Note that this would not be the case if we had defined the variable as an integer since the
leading zero would have been assumed.
As we have already seen
define z character (5) value “Page”
results in
z
being Page where the rightmost position is a space. This means that fields that are
defined as numeric, whether
integer
or
decimal
will fill the field with leading zeroes where necessary while those defined as
Search WWH ::




Custom Search