HP OpenVMS Systems Documentation
The sign test compares a numeric quantity to zero and determines if it is greater than (positive), less than (negative), or equal to zero. Both the relation test and the sign test can perform this function. For example, consider the following relation test:
IF FIELD1 > 0 ...
Now consider the following sign test:
IF FIELD1 POSITIVE ...
Both of these tests accomplish the same thing and always arrive at the same result. The sign test, however, shortens the statement and makes it more obvious that the sign is being tested.
Table 2-2 shows the sign tests and their equivalent relation tests.
|Sign Test||Equivalent Relation Test|
|IF FIELD1 POSITIVE ...||IF FIELD1 > 0 ...|
|IF FIELD1 NOT POSITIVE ...||IF FIELD1 NOT > 0 ...|
|IF FIELD1 NEGATIVE ...||IF FIELD1 < 0 ...|
|IF FIELD1 NOT NEGATIVE ...||IF FIELD1 NOT < 0 ...|
|IF FIELD1 ZERO ...||IF FIELD1 = 0 ...|
|IF FIELD1 NOT ZERO ...||IF FIELD1 NOT = 0 ...|
Sign tests do not execute faster or slower than relation tests because
the compiler substitutes the equivalent relation test for every
correctly written sign test.
2.5.3 Numeric Class Tests
IF FIELD1 IS NUMERIC ...
If the item is numeric, the test condition is true, and program control takes the true path of the statement.
Both relation and sign tests determine only if an item's contents are within a certain range. Therefore, certain items in newly prepared data can pass both the relation and sign tests and still contain data preparation errors.
The NUMERIC class test checks alphanumeric or numeric DISPLAY or COMP-3 usage items for valid numeric digits. If the item being tested contains a sign (whether carried as an overpunched character or as a separate character), the test checks it for a valid sign value. If the character position carrying the sign contains an invalid sign value, the NUMERIC class test rejects the item, and program control takes the false path of the IF statement.
The ALPHABETIC class test check is not valid for an operand described
2.5.4 Success/Failure Tests
You can use the SET statement to initialize or alter the status of status-code-id (which must be a word or longword COMP integer represented by PIC 9(1 to 9) COMP or PIC S9(1 to 9) COMP), as follows:
The SET statement is typically in the called program, but the calling program may also SET the status of status-code-id. The SUCCESS class condition is true if status-code-id has been set to SUCCESS, otherwise it is false. The FAILURE class condition is true if status-code-id has been set to FAILURE, otherwise it is false. The results are unspecified if status-code is not set.
Example 2-1 shows the significant COBOL code relevant to a success/failure test.
|Example 2-1 Success/Failure Test|
... PROGRAM-ID. MAIN-PROG. ... O1 RETURN-STATUS PIC S9(9) COMP. ... CALL "PROG-1" GIVING RETURN-STATUS. IF RETURN-STATUS IS FAILURE PERFORM FAILURE-ROUTINE. ... PROGRAM-ID. PROG-1. .... WORKING-STORAGE SECTION. 01 RETURN-STATUS PIC S9(9) COMP. PROCEDURE DIVISION GIVING RETURN-STATUS. ... IF NUM-1 = NUM-2 SET RETURN-STATUS TO SUCCESS ELSE SET RETURN-STATUS TO FAILURE. ... EXIT PROGRAM. END PROGRAM PROG-1. END PROGRAM MAIN-PROG.
MOVE FIELD1 TO FIELD2.
This section considers MOVE statements as applied to numeric and
numeric edited data items.
2.6.1 Elementary Numeric Moves
If both items of a MOVE statement are elementary items and the receiving item is numeric, it is an elementary numeric move. The sending item can be numeric, alphanumeric, or numeric-edited. The elementary numeric move converts the data format of the sending item to the data format of the receiving item.
An alphanumeric sending item can be either of the following:
The elementary numeric move accepts the figurative constant ZERO and considers it to be equivalent to the numeric literal 0. It treats alphanumeric sending items as unsigned integers of DISPLAY usage.
When the sending item is numeric-edited, de-editing is applied to establish the unedited numeric value, which may be signed; then the unedited numeric value is moved to the receiving field.
If necessary, the numeric move operation converts the sending item to the data format of the receiving item and aligns the sending item's decimal point on that of the receiving item. Then it moves the sending item's digits to the corresponding receiving item's digits.
If the sending item has more digit positions than the receiving item, the decimal point alignment operation truncates the value of the sending item, with resulting loss of digits.
The end truncated (high-order or low-order) depends upon the number of sending item digit positions that find matches on each side of the receiving item's decimal point. If the receiving item has fewer digit positions on both sides of the decimal point, the operation truncates both ends of the sending item. Thus, if an item described as PIC 999V999 is moved to an item described as PIC 99V99, it loses one digit from the left end and one from the right end.
In the execution part of the following examples, the caret (^) indicates the assumed stored decimal point position:
01 AMOUNT1 PIC 99V99 VALUE ZEROS. . . . MOVE 123.321 TO AMOUNT1. Before execution: 00^00 After execution: 23^32
If the sending item has fewer digit positions than the receiving item, the move operation supplies zeros for all unfilled digit positions.
01 TOTAL-AMT PIC 999V99 VALUE ZEROS. . . . MOVE 1 TO TOTAL-AMT. Before execution: 000^00 After execution: 001^00
The following statements produce the same results:
MOVE 001.00 TO TOTAL-AMT. MOVE "1" TO TOTAL-AMT.
Consider the following two MOVE statements and their truncating and zero-filling effects:
Statement TOTAL-AMT After Execution MOVE 00100 TO TOTAL-AMT 100^00 MOVE "00100" TO TOTAL-AMT 100^00
Literals with leading or trailing zeros have no advantage in space or execution speed in HP COBOL, and the zeros are often lost by decimal point alignment.
The MOVE statement's receiving item dictates how the sign will be moved. When the receiving item is a signed numeric item, the sign from the sending item is placed in it. If the sending item is unsigned, and the receiving item is signed, a positive sign is placed in the receiving item. If the sending item is signed and the receiving item is unsigned, the absolute value of the sending item is moved to the receiving item.