CALC math function in generated JCL of Global changes

Document ID : KB000054827
Last Modified Date : 14/02/2018
Show Technical Document Details

Solution:

How can I apply arithmetic equations to numeric values like Primary and Secondary space quantities on Tablespaces and Indexes during analysis to make changes which would cater to normal increases and decreases in size?

When using RC/Migrator migration, alteration or comparison functions there is often a need to manipulate the values associated to the Tablespace and Indexspace Primary and Secondary quantity, to cater to the needs of the target environment. If a migration is occurring to a production environment then the size of Tablespaces and Indexes will normally be larger than on the development environment. Likewise, one might want to reduce the size for a similar reason. A task like this is very time intensive if there are hundreds of objects involved and, if it is done manually.

Description:

The Primary and Secondary Quantity is able to be manipulated with arithmetic operations via the CALC function in GLOBAL CHANGES.
The CALC function is placed into the "TO" field of the global change next to the Primary or Secondary Quantity of a Tablespace or Index.

The CALC function has four operators:
Subtraction(-), Division(/), Multiplication(*) and addition(+).

The use of the percentage (%) character is as a means of substitution for the FROM value into an equation. In the from field an "*" or "%" have the same function.

In the "TO" field of a Global Change.
Example: CALC(%/2%)

This expands to..........CALC(720/2720)

if the FROM value is "720". The first % substitutes to 720 divided by 2720(2 concatenated with 720). Some rules of the CALC function regarding the mechanics of the way the equations are resolved:

  1. The remainder on divide operations is truncated and not rounded.

  2. Calculations resulting in a negative number, lose the sign and become positive or the absolute value.

  3. Calculations resulting in a value larger than seven digits are truncated from the right most end. They are not rounded.

  4. In DB2 for any page size, if pri/sec qty is greater than 4194304, then it is set to 4194304 when it's executed. In the DDL generated it will still have the larger number

  5. If a calculation produces a zero (0) as a result then, that will be in the generated DDL. It produces an SQL error when executed.

Examples based on the above rules.

By reading across the page from the left, you can see the Original value, the calculation to be used, then the result of the CALC.
Next look closely at the Working to see how values are treated and lastly the Description.

One Step Calculations

This first group illustrates some examples of simple one step equations.

ValueCalcResultWorkingDescription
1000CALC(%*10)100001000 * 10 = 10000Multiply 1000 by 10
8000CALC(%/10)8008000 / 10 = 800Divide 8000 by 10
500CALC(%*2)1000500 * 2 = 1000Multiply 500 by 2
500CALC(%/2)250500 / 2 = 250Divide 500 by 2
1000CALC(%*10%)10100001000 * 101000 = 101000000 Result truncated to 1010000 Two digits lost!Multiply 1,000 by 101,000,000 Here the original value is concatenated with part of the equation.
8000CALC(%/10%)08000 / 108000 = 0.07 truncated to 0 A '0' is not valid for pri/sec qtyDivide 8000 by 108,000 Here the original value is concatenated with part of the equation.
500CALC(%*2%)1250000500 * 2500 = 1250000Multiply 500 by 2,500
500CALC(%/2%)0500 / 2500 = 0.2 Result truncated to 0 A '0' is not valid for pri/sec qtyDivide 500 by 2,500. Here the original value is concatenated with part of the equation.
1000CALC(%+300)13001000 + 300 = 1300Add 300 to value
8000CALC(%-300)77008000 - 300 = 7700Take 300 from value
500CALC(%+2%)3000500 + 2500 = 3000Add 2,500 to value Here the original value is concatenated with part of the equation.
500CALC(%-2%)2000500 - 2500 = -2000 absolute value = 2000 Sign is lost!Subtract 2,500 from 500 Here the original value is concatenated with part of the equation

Multi-step calculations

This group illustrates equations where there is an intermediate result to consider.

 CalcResultWorkingDescription
720CALC(%*10 /100)792720 * 110 = 79200 79200 / 100 = 792Increase value by 10%
720CALC(%*90/100)648720 * 90 = 64800 64800 / 100 = 648Reduce value by 10% This method is used so that precision is not lost due to the truncation of the remainder with a divide.
4252CALC(%/90*100)47004252 / 90 = 47.2444444 t runcated to 47 47 * 100 = 4700 remainder lost!Divide value by 90 and multiply truncated result by 100
720CALC(720/90*100)800720 / 90 = 8 8 * 100 = 800Divide value by 90 and multiply the result by 100
200CALC(%/20-%)190200/20 = 10 10 - 200 = -190 absolute value = 190 sign is lost!Divide 200 by 20 and subtract 200. Here the original value is used twice in the equation.
200CALC(%/20+%)210200/20 = 10 10 + 200 = 210Divide 200 by 20 and add 200 Here the original value is used twice in the equation.
200CALC(%/7+11111111)1111113200 / 7 = 28.57 Truncate to 28 28 + 11111111 = 11111139 Truncate to 1111113 Remainder is lost One digit is lost!Divide 200 by 7 and add 11,111,111
200CALC(%/7 *10000000)2800000200 / 7 = 28.57 Truncate to 28 28 *10000000 = 280000000 Truncate to 2800000 Two digits lost!Divide 200 by 7 and multiply 10,000,000
200CALC(%/7-10000)9972200 / 7 = 28.57 Truncate to 28 28 - 10000 = -9972 absolute value = 9972 Sign is lost!!Divide 200 by 7 and subtract 10,000

Unrelated value equations

This last group illustrates how an equation which does not rely on the existing value can be used to replace that value.

Orig. ValueCalcResultWorkingDescription
AnyCALC(90)90Old value changed to 90Replace all existing values with 90
AnyCALC((4+4)/2*1))44+4 = 8 8 / 2 = 4 4 * 1 = 4Replace all existing values with the result of this unrelated equation.

Documentation references.

See Syntax rules in the manual.
RC/Migrator User Guide:
SPACE CALCULATION SYNTAX RULES and UTILITY MODEL SERVICES ...the CALC symbolic.