This article goes through a basic example of how to populate data in an application state record. State records are used in Application Engine programs to keep track of useful information through the life of a program. PeopleSoft uses the concept of a record (table) to store this information. The scope of data in a state record is global to an application engine program (and other programs that share the state record).
The naming convention of state records is to end with the suffix
They can either be a derived/work record or a SQL table. The difference is one of persistence. A derived/work state record will lose its value when the application engine is restarted or after database commits, while a table will not as state data is committed to the database. So if you are developing a restartable application engine program, the state record should be a table (and built in the database). Since Derived/work state records can also lose information between commits in your application engine, its safest to use a SQL table as the default type for your state records.
Creating the State Record
All state records must have at least one field
PROCESS_INSTANCE as their first field. This is also the only key field. Other commonly used fields are
RUN_CNTL_ID. This lets you track who is running the application engine program and what run control ID they are using.
Additional state record fields that are common to include are
AE_SECTION. These are required on Application Engine Programs which have a dynamic Call Section Actions, as the values in these fields will control what Application Engine Step is called next — either in the current program or something outside.
All other fields are a matter of your requirements; what information do you need to track through the execution of your program?
Assigning the State Record to your App Engine
Once you've created the state record, you need to assign it to your application engine program. You do this through the application engine properties in the state records tab.
Use the search to find your state record and then add it.
If you have more than one, you should nominate one as the default. You can supposedly have up to 200 state records associated with one application engine program, but I'm not sure I would like to see a program that does!
Adding a SQL action to populate the State Record
I generally have an
INIT step at the start of an application engine program that populates state records. This includes a SQL action that populates the state record.
Here's a basic example assuming a state record with the fields:
%Select(OPRID, RUN_CNTL_ID) SELECT OPRID , RUN_CNTL_ID FROM PS_AE_REQUEST WHERE PROCESS_INSTANCE = %Bind(PROCESS_INSTANCE)
Notice that you don't need to select in the
PROCESS_INSTANCE field. It is automatically populated and available for use as a bind, which is how we get the operator ID and run control ID.