

Performing Calculations › Optimizing Arithmetic in CA Ideal
Optimizing Arithmetic in CA Ideal
By far, the largest proportion of a typical business application is spent in database retrieval and formatting data for screens and reports. However, if you are doing a great deal of computation in an application, you want to make sure that it is done in the most efficient way possible.
Here are some things you can do to optimize arithmetic in CA Ideal:
- Use packed decimal format. This is the CA Ideal default and, as the test results show, the most efficient for CA Ideal computations.
- Where possible, make sure operands in complex and frequently used arithmetic expressions have the same decimal alignment (the same number of decimal positions). Adding two numbers with Char/Digits of 5.2 is faster than adding a number with 5.1 to a number with 5.2.
- When you use dataview fields (columns) repeatedly in calculations, move them to working data first and do the computations from there. This is because CA Ideal continually checks the dataview fields to ensure that they are actually numeric (since the values are not guaranteed correct), whereas CA Ideal knows that working data fields are always valid and does not keep checking. When you move the dataview fields to working data, the validity check is done just once, so it really does not save anything if you only reference a given dataview field once per record.
You can use the COPY DATAVIEW clause in working data to define a structure that matches the dataview. Then use a MOVE...BY NAME statement to move the dataview fields.
- If you use a subscripted field repeatedly in a calculation, move it to a separate non-occurring work field in working data and use it in the computation. This is a standard source optimization technique. It applies to any language, not just to CA Ideal.
- Ensure that computations are not done superfluously in a loop. If a computation is in a loop, make sure that it really needs to be there. Otherwise, move it outside the loop. Again, this is a standard optimization technique.
- If a parameter field is defined as dynamic and is used repeatedly in a computation, move it to working data first.
- If a field is redefined or is itself a redefinition and is used repeatedly in a computation, move it to a separate working data field first. This is because REDEFINES means that the contents of either field-the REDEFINES subject or object-can be made invalid by an operation on the other, so CA Ideal always validates REDEFINES subjects and objects before computations.
- In general, CA Ideal arithmetic is most efficient when the fields are in working data, unsubscripted, not part of a redefinition, are packed decimal format, and have identical decimal alignment. If a given field that is used more than once in a computation fails one of these criteria, then moving it to a separate work field that does comply probably improves efficiency. However, if the field is only used once, it is probably better to let CA Ideal handle the conversion internally.
- To the extent that you have the choice, external data (dataview fields) benefit from following these guidelines too-but not at the expense of good database design.
For example, if you have a field that is a database key and you have to choose between the best format for database retrieval or for internal computation, choose the best database retrieval format (although this might depend on the specific case).
- In certain cases, where you have a really heavy-duty computation (for example, you are generating a mortgage rate book and calculating monthly payment amount for each combination of sale price, interest rate, and number of payments), you might consider calling a COBOL or Assembler subroutine to do the calculation. Carefully evaluate the overhead since you must weigh the overhead of calling the subroutine against whatever arithmetic overhead you would save.
A word, finally, about some additional features of arithmetic processing in CA Ideal.
- CA Ideal ensures that abends do not occur. For example, a SOC7 abend cannot occur.
- CA Ideal checks for overflow and subscript range automatically.
- Programming arithmetic computations using CA Ideal saves debugging and dump reading time and the time spent in programming and maintenance.
Copyright © 2015 CA Technologies.
All rights reserved.
 
|
|