The COMPUTE statement is efficient and easy to read. You can code one COMPUTE statement instead of individual arithmetic statements. Perform arithmetic computations with the COMPUTE statement, except when division produces a remainder (if you need to process the remainder). You use arithmetic operators in the COMPUTE statement. These operators are evaluated in the hierarchic order:
Operators at the same level are evaluated from left to right; however, you can use parentheses with these operators to change the order in which they are evaluated. Expressions within parentheses are evaluated before any of the individual operators are evaluated. In any case, parentheses, whether necessary or not, make your program easier to read. When using COMPUTE, you have to make sure the data is defined with the level of significance you need for an accurate answer. For large data items, intermediate results may be truncated.
Binary (BINARY) Items
A binary item (USAGE BINARY) is allocated storage ranging from 1 halfword to 2 fullwords, depending on the number of digits in the PICTURE clause. Table 56.2 shows three binary operations in which the result field is an item described as PIC S9 BINARY and the TRUNC(OPT) option is in effect. One halfword of storage has been allocated and no ON SIZE ERROR option is involved. (If the ON SIZE ERROR option had been specified, it would have been executed for cases B and C.)
Binary Data Alignment
On some processors, binary items aligned on halfword or fullword boundaries can improve performance. You can align data using the SYNCHRONIZED clause, or by providing slack bytes.
The SYNCHRONIZED clause is meaningless for PACKED-DECIMAL and DISPLAY items, and the compiler ignores it.
Floating-Point (C0MP-1, C0MP-2, and DISPLAY) Items
If any operation in an arithmetic expression will be computed in floating point, the entire expression is computed as though all operands were converted to floating point. Therefore, be aware of what values may be moved between fixed and floating-point items without losing digits. In all cases, the basic COBOL rules for moving data items are followed.
The following results occur when values are moved between fixed and floating-point items. (Because fixed-point and external floating-point items both have decimal characteristics, reference to fixed-point items in the following examples generally includes external floating-point items as well. When external-floating point is handled differently, it is specifically stated.)
Data Movement Support for Numeric Operands in VS COBOL II
IBM Mainframe Related Interview Questions
|IBM Lotus Notes Interview Questions||IBM-CICS Interview Questions|
|COBOL Interview Questions||Linux Interview Questions|
|IBM-JCL Interview Questions||IBM Mainframe Interview Questions|
|IBM AIX Interview Questions||IBM WAS Administration Interview Questions|
|IBM Lotus Domino Interview Questions||IBM Integration Bus Interview Questions|
|Mainframe DB2 Interview Questions||Unix Production Support Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.