The following standards govern the use of batches and procedures:
General
Manage runtime error handling using CATCH/THROW logic, not ER.
To update the database, use the RecordClass.bypassSave method followed by RecordClass.save and the Db.insert or Db.update method.
Cache
Use Cache objects for any "static" database references that may generate multiple "hits" on the cached records.
For batches only, control cache management within the thread executive (THREXEC) section. Use the following statement to delete the cache object for each block of records:
kill %CACHE
Store database records under %CACHE(TableName). Processes can store additional data within the cache but cannot conflict with database nodes or other processes.
If an end-of-day batch cannot be multi-threaded, set the Number of Threads to 1 (one).
List in the Thread Context those variables or arrays that need to be passed to the threads.
Subroutines/Functions
All subroutines within a batch should be either private or local, unless identified per an authorized specification.
Public functions used by a batch should generally be placed in a procedure or procedure library.
Variables
Minimize the use of Public scope variables. Document their use in the source code. Exit batches without any "garbage" variables left behind.
Explicitly type all variables.
When passing parameters, pass values instead of objects, if possible.
The #OPTIMIZE command instructs the compiler to identify objects that are very local in scope (i.e., not passed as parameters) and to optimize the run-time code. In general, the object can be managed within private local variables instead of an object array, which has a significant impact. Every newly modified procedure and batch should include the #OPTIMIZE command. Compare the generated code to the non-optimized version to validate the optimization effect.