1. Declaring Local Variables
- When writing PeopleCode, declare ALL local variables that will be used. Declaring the specific type of variable needed improves performance.
- When variables are declared, the PeopleCode editor can check the compatibility of variables used in an operation, or passed as function arguments during compile time.
- For programming languages that allow dynamic allocation of variables, it is a common programming error to misspell variable names. However, on the PeopleCode editor, when all variables are consciously declared, it is easy to check for misspelled variable names.
2. Usage of the %Table() meta-SQL When Writing SQL Statements
- When writing SQLExec statements, the common practice is to hard-code table/view names. For example:
SQLExec("Select FIELD1, FIELD2 From PS_RECORD_TBL Where CRITER1 = :1 AND CRITER2 > :2", &IN1, &IN2, &OUT1, &OUT2);
A problem with the above code is that information in the PeopleCode string literals cannot be classified by the compiler and saved into the PeopleTools reference tables.
Use the meta-SQL %Table() in SQL statements to refer to SQL tables or views. With a little effort, the above code can be transformed into the following:
SQLExec("Select FIELD1, FIELD2 From %Table(:1) Where CRITER1 = :2 AND CRITER2 > :3", Record.RECORD_TBL, &IN1, &IN2, &OUT1, &OUT2);
- When writing PeopleCode, declare ALL local variables that will be used. Declaring the specific type of variable needed improves performance.
- When variables are declared, the PeopleCode editor can check the compatibility of variables used in an operation, or passed as function arguments during compile time.
- For programming languages that allow dynamic allocation of variables, it is a common programming error to misspell variable names. However, on the PeopleCode editor, when all variables are consciously declared, it is easy to check for misspelled variable names.
2. Usage of the %Table() meta-SQL When Writing SQL Statements
- When writing SQLExec statements, the common practice is to hard-code table/view names. For example:
SQLExec("Select FIELD1, FIELD2 From PS_RECORD_TBL Where CRITER1 = :1 AND CRITER2 > :2", &IN1, &IN2, &OUT1, &OUT2);
A problem with the above code is that information in the PeopleCode string literals cannot be classified by the compiler and saved into the PeopleTools reference tables.
Use the meta-SQL %Table() in SQL statements to refer to SQL tables or views. With a little effort, the above code can be transformed into the following:
SQLExec("Select FIELD1, FIELD2 From %Table(:1) Where CRITER1 = :2 AND CRITER2 > :3", Record.RECORD_TBL, &IN1, &IN2, &OUT1, &OUT2);
No comments:
Post a Comment