|
4.2 Moving and Editing Data
Care must be taken when moving (using the MOVE verb) data to an item. In other languages, such as
Pascal, when to assign a value to XYZ (defined at the beginning of the program as an integer for example), then that's it.
In COBOL, you have to be sure that the value you are moving to XYZ item is not bigger than the defined size. If you moved
1234 to a PIC 999 defined item, then if you were to examine XYZ it would contain 234. For numeric data, the digits are truncated
from the left. If item ABC were defined as PIC XXX and you moved "abcd" into it, on examination you would find it
contained "abc". For alpha-numeric data characters are truncated from the right.
Conversely, moving data that is smaller than the PIC definition has certain effects. If 2 was moved to item XYZ above, then
the number 2 is written to the right-most position and the leading positions are zero-filled (see figure below). Likewise,
moving "A" to ABC above, the letter "A" would be written to the left-most position with the trialing positions being space-filled.
![]()
So what about data with decimal places?
If you were to display COST-OF-ITEM it would appear as 123456 since the decimal point is assumed, not actual.
For the purposes of printing or displaying a number you would need to actually show where decimal point is.
You may also wish to avoid having a long string of zeros in front of a
number and have spaces used instead. So the number would first have to be moved into an outputing item...well
have a look at the small program below (don't worry too much about any of the commands used in the procedure division,
although they're pretty self explanatory):
You'll notice that there is a gap (of 2 spaces) between the '£' sign and the actual number in the displayed output.
To avoid this when using '£' or '$' signs (well COBOL is a business language), you can zero-suppress as follows:
the VDU will then display: If you want nothing in a field when printing a value that is zero then use BLANK WHEN ZERO:
000140 01 PRINT-VALUE PIC Z(5)9V99 BLANK WHEN ZERO.
the VDU will then display:
...er nothing...        More Data Editing Signed data needs to be able to indicate whether it is a positive or negative number. An item may have a definition: For output, the sign can be maniputed to show signs and zero-suppress using a 'floating sign'. Look at the following examples:
The last two examples in the table show how the sign can be moved to the other end of the number when SIGN LEADING/TRAILING SEPARATE is used. Some characters can be inserted into numbers, these being SPACE, SOLIDUS, ZERO
(using 'B' '/' and '0' respectively):
Adding a solidus can be useful for printing the date (which can be obtained directly from the computer in the form of yymmdd [you have to switch the order around first]). I can only assume that adding zeros to a number is for fraudulent purposes.   Redefining Data It is sometimes useful to be able to have data that can be defined as either numeric or
alphanumeric. This is done by redefining the data. One way is implicit redefinition:
Although DATA-ITEM-X and DATA-ITEM-1 refer to the same area of memory storage, the level 03
item is numeric. However, group items are always alphanumeric and as a result, if you
moved the number 25 into DATA-ITEM-1, you could use DATA-ITEM-X as an alphanumeric item
containing the literal "25".
Explicit redefinition uses the verb REDEFINES so that you could do this:
REDEFINES cannot be used for level 01 items and can only redefine items on the same level.
Another use for REDEFINES is to offer an alternative PIC desciption for the same data group:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||