Peoplecode automatic code formatting - Peoplecode, Behind the Scenes

Why Peoplecode automatically formats itself? - Peoplecode, Behind the Scenes

Just as with any other PeopleSoft object, a Peoplecode program is stored in the database. Table PSPCMPROG contains the actual code. Do a SELECT on this table and you will see that each program has a key that designates its event (Field Change, etc.) and the object (record or component, for example) to which it belongs.

The code itself is stored in a long character field called PROGTXT. Look at that and you will see "garbage". Is this compiled code? Not really--it's an intermediate form of the source code. Peoplecode is an interpreted language and is never actually compiled. When you change and save a PeopleCode program, it is immediately scanned and condensed. Variables are identified and flagged with a special character; extra whitespace is removed; numeric constants are found and translated to a consistent internal format; keywords are replaced with special one-byte codes; and so on. The result is no longer readable to us, but it is more efficient. Some of this code can be run dozens of times during one transaction. We don't want to have to wait as the program is interpreted each time.

We can now answer the question about automatic code formatting. Enter a statement and then either save the program or click on the syntax check (checkmark) button. At that time, the program is reformatted with appropriate indenting, the extra whitespace is removed, and standard capitalization of keywords is applied. This is not just a handy service provided by App Designer. Since the code has been compressed into a more efficient form, it's about the only way the code could be displayed. For example, if a keyword is replaced with a single one-byte code, then the way we entered it initially (all caps, all lower case, or mixed) is lost and it must be displayed using the standard capitalization. Occasionally we may want to format the code in a certain way, but in general, this automatic reformatting is a good thing.

You may occasionally have Peoplecode programs "go bad". An error message may report that the program is invalid. Even before clearing your cache, you might want to try this. Open the program in App Designer, make a small change (such as adding a space at the end of a line), and save. The program is then re-scanned. That often fixes the problem.

One last tip... You might see some custom code and wonder who wrote it and when. The record or component to which the code belongs has its own user ID and date, and that is what is displayed on the properties panel. I don't know of a way to find the user ID and date for a particular PeopleCode program through App Designer, but you can see it by doing a SELECT on PSPCMPROG. The ID and datestamp fields are stored right there with the program.

-Ganesh A.M