You can change the levels at which the generated code is optimized to run on the system. When the compiler optimizes the code, it looks for processing shortcuts that reduce the amount of system resources necessary to produce the same output. It then translates the shortcuts into machine code.
For example:
a = (x + y) + (x + y) + 10
In solving for a, the compiler recognizes the equivalence between the two expressions (x + y) and uses the already computed value to supply the value of the second expression.
Greater optimization increases the efficiency with which the program object runs on the system. However, with greater optimization, you will encounter increased compile time and also you may not be able to view variables that have been optimized. You can change the optimization level of a module object to display variables accurately as you debug a program object and then change the optimization level when the program object is ready for production.
ILE compilers support a range of optimization levels. There are currently four optimization levels, three of which are available to ILE COBOL users, these are:
The effect of optimization on runtime performance varies depending on the type of application. For example, for an application that is compute intensive, optimization may improve runtime performance significantly whereas for an application that is I/O intensive, optimization may improve runtime performance only minimally.
To change the optimization level of a module object in a program object, use the Work with Modules (WRKMOD) command. Type WRKMOD on the command line and the Work with Modules display is shown. Select option 5 (Display) from the Work with Modules display to view the attribute values that need to be changed. The Display Module Information display is shown in Figure 26.
Figure 26. First screen of Display Module Information display
+--------------------------------------------------------------------------------+ | Display Module Information | | Display 1 of 1 | | Module . . . . . . . . . . . . : COPYPROC | | Library . . . . . . . . . . : TESTLIB | | Detail . . . . . . . . . . . . : *BASIC | | Module attribute . . . . . . . : CBLLE | | Module information: | | Module creation date/time . . . . . . . . . . . . . . : 98/08/25 12:57:17 | | Source file . . . . . . . . . . . . . . . . . . . . . : QCBLLESRC | | Library . . . . . . . . . . . . . . . . . . . . . . : TESTLIB | | Source member . . . . . . . . . . . . . . . . . . . . : COPYPROC | | Source file change date/time . . . . . . . . . . . . : 98/08/19 12:04:57 | | Owner . . . . . . . . . . . . . . . . . . . . . . . . : TESTLIB | | Coded character set identifier . . . . . . . . . . . : 37 | | Text description . . . . . . . . . . . . . . . . . . : PG - COPY within PR| |OCESS Statement Example | | Creation data . . . . . . . . . . . . . . . . . . . . : *YES | | Intermediate language data . . . . . . . . . . . . . : *NO | | More... | | Press Enter to continue. | |F3=Exit F12=Cancel | +--------------------------------------------------------------------------------+
First, check that the Creation data value is *YES. This means that the module object can be translated again once the Optimization level value is changed. If the value is *NO, you must create the module object again and include the machine instruction template to change the optimization level.
Next, press the Roll Down key to see more information about the module object.
Figure 27. Second screen of Display Module Information display
+--------------------------------------------------------------------------------+ | Display Module Information | | Display 1 of 1 | | Module . . . . . . . . . . . . : COPYPROC | | Library . . . . . . . . . . : TESTLIB | | Detail . . . . . . . . . . . . : *BASIC | | Module attribute . . . . . . . : CBLLE | | Sort sequence table . . . . . . . . . . . . . . . . . : *HEX | | Language identifier . . . . . . . . . . . . . . . . . : *JOBRUN | | Optimization level . . . . . . . . . . . . . . . . . : *NONE | | Maximum optimization level . . . . . . . . . . . . . : *FULL | | Debug data . . . . . . . . . . . . . . . . . . . . . : *YES | | Compressed . . . . . . . . . . . . . . . . . . . . . : *NO | | Program entry procedure name . . . . . . . . . . . . : _Qln_pep | | Number of parameters . . . . . . . . . . . . . . . . : 0 | | Module state . . . . . . . . . . . . . . . . . . . . : *USER | | Module domain . . . . . . . . . . . . . . . . . . . . : *SYSTEM | | Number of exported defined symbols . . . . . . . . . : 2 | | Number of imported (unresolved) symbols . . . . . . . : 14 | | More... | | Press Enter to continue. | | F3=Exit F12=Cancel | +--------------------------------------------------------------------------------+
Check the Optimization level value. It may already be at the level you desire.
If the module has the machine instruction template and you want to change the optimization level, press F12 (Cancel). The Work with Modules display is shown. Select option 2 (Change) for the module object whose optimization level you want to change. the CHGMOD command prompt is shown as in Figure 29. Type over the value specified for the Optimize module prompt.
Next, press the Roll Down key to see the final set of information about the module object.
Figure 28. Third screen of Display Module Information display
+--------------------------------------------------------------------------------+ | Display Module Information | | Display 1 of 7 | | Module . . . . . . . . . . . . : COPYPROC | | Library . . . . . . . . . . : TESTLIB | | Detail . . . . . . . . . . . . : *BASIC | | Module attribute . . . . . . . : CBLLE | | Profiling data . . . . . . . . . . . . . . . . . . . : *NOCOL | | Enable performance collection . . . . . . . . . . . . : *PEP | | | | Teraspace storage enabled . . . . . . . . . . . . . . : *YES | | | | Module compatibility: | | Module created on . . . . . . . . . . . . . . . . . . : V4R4M0 | | Module created for . . . . . . . . . . . . . . . . . : V4R4M0 | | Earliest release module can be restored to . . . . . : V4R4M0 | | Conversion required . . . . . . . . . . . . . . . . . : *NO | | | | | | | | Bottom | | Press Enter to continue. | | | | F3=Exit F12=Cancel | | | +--------------------------------------------------------------------------------+
The Enable performance collection prompt shows that the module has been created with performance measurement code for the entry into and exit from program entry point only. The module compatibility prompts show the release and version of the operating system that the module is compatible with.
Figure 29. Prompt of the CHGMOD Command
+--------------------------------------------------------------------------------+ | Change Module (CHGMOD) | | Type choices, press Enter. | | Module . . . . . . . . . . . . . COPYPROC Name, generic*, *ALL | | Library . . . . . . . . . . . TESTLIB_ Name, *USRLIBL, *LIBL | | Optimize module . . . . . . . . *NONE_ *SAME, *FULL, *BASIC... | | Remove observable info . . . . . *DBGDTA *SAME, *NONE, *ALL... | | + for more values | | Enable performance collection: | | Collection level . . . . . . . *PEP *SAME, *NONE, *PEP, *FULL... | | Procedures . . . . . . . . . . *ALLPRC, *NONLEAF | | Profiling data . . . . . . . . . *COL *SAME, *NOCOL, *COL | | Force module recreation . . . . *NO *NO, *YES | | Text 'description' . . . . . . . 'PG - COPY within Process Statement Example | | '____________________________ | | | | | | Bottom | | F3=Exit F4=Prompt F5=Refresh F12=Cancel F13=How to use this display | | F24=More keys | | | +--------------------------------------------------------------------------------+
Changing the module object to a lower level of optimization allows you to display and possibly change the value of variables while debugging.
Repeat the process for any additional module objects whose optimization you may want to change. Whether you are changing one module object or several in the same program object, the program creation time is the same because all imports are resolved when the system encounters them.
When you are finished changing the optimization level for the module objects in a program object, create the program object again using the CRTPGM command, or update the existing program object with the new module objects using the UPDPGM command.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.