z/OS DFSORT: Getting Started
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Performing arithmetic with numeric fields and constants

z/OS DFSORT: Getting Started
SC23-6880-00

Suppose you want to display the results of subtracting the second PD field in Table 1 from the first PD field in Table 1. As discussed previously, the PD fields are stored as integers, but we know that:
  • The first PD field is 6 bytes and represents a signed number with 11 digits including two decimal places.
  • The second PD field is 7 bytes and represents a signed number with 13 digits including three decimal places.
In order to do arithmetic on these fields, you must ensure that the integer and decimal parts of the numbers match up correctly. For example, in the first record, the first PD value is +1524900810 representing +15249008.10 and the second PD value is +20000 representing +20.000. In order to subtract the second PD value from the first PD value, you need to put them in the following forms:
+15249008.100
+00000020.000
You could use the following OUTREC statement to handle the subtraction correctly:
  OUTREC FIELDS=(1,8,
     5X,
     ((11,6,PD,MUL,+10),SUB,31,7,PD),
       EDIT=(SI,III,III,IIT.TTT),SIGNS=(,-))

11,6,PD,MUL,+10 multiples the first PD field by 10 to match up the decimal places. SUB,31,7,PD subtracts the second PD field from the results of the 11,6,PD,MUL,+10 operation.

EDIT and SIGNS are used to make the results more meaningful.

The results produced for this OUTREC statement are:
WEST             15,248,988.100
EAST         -3,722,158,342.536
NORTH               982,630.735
SOUTH             3,826,219.379
You can do arithmetic with numeric fields and decimal constants (+n and -n) using the operators MIN (minimum), MAX (maximum), DIV (division), MUL (multiplication), MOD (modulus), ADD (addition) and SUB (subtraction). The order of evaluation precedence for the operators is as follows, but can be changed by using parentheses:
  1. MIN and MAX
  2. MUL, DIV and MOD
  3. ADD and SUB

You can use p,m,f, MIN, MAX, MUL, DIV, MOD, ADD, SUB, +n, -n and parentheses to do a wide variety of arithmetic operations for various numeric formats. The result of an arithmetic operation is a 15-digit ZD value that can be converted to a different numeric format, or edited using pre-defined edit masks (M0-M26) or user-defined edit masks, as discussed earlier.

For complete details on arithmetic operations, see z/OS DFSORT Application Programming Guide.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014