Application Engine | Specifying the Section Name dynamically
A. CallSection
An App Engine program is divided into ‘Sections’, which are blocks of statements consisting of any number of ‘Steps’ and ‘Actions’. Unless you’re dealing with a ‘library’ App Engine, the program will contain one section called ‘MAIN’, with any number of remaining sections named by the developer. At any point throughout the App Engine code, you can transfer control from one section to another via the use of the ‘Call Section’ command:
The name of the target section is usually specified in the AE definition. However, in some cases, you may want to use ‘CallSection’ in a more dynamic way. You’d rather not specify the name of the section in advance, but would instead prefer to set the Section name at run-time. Fortunately, this is relatively easy to do.
B. Creating a Dynamic Call
Firstly, insert the field ‘AE_SECTION’ into your AE state record. Then prior to the ‘Call Section’ step, add the following code to a PeopleCode Step, setting the AE_SECTION field to the actual section that needs to be called.
If &condition1 Then STATE_REC_AET.AE_SECTION.Value = "SECTION1"; Else STATE_REC_AET.AE_SECTION.Value = "SECTION2"; End-If;
The ‘Call Section’ command itself should then be defined with no value entered in the section name, but with the ‘Dynamic’ flag ticked. The system will know that dynamic naming is in operation and will check for the AE_SECTION field on the state record. The program will error if the AE_SECTION field does not exist, or it points to an invalid section name.
Dynamic sections could be used, for instance, when the App Engine is intended to run as both a batch process and as an online process. In this case, you may want to call different sections as the data requirements will differ depending on whether a run control record has been created in advance. Refer to Tip 015 for more details of the ‘CallAppEngine’ function.
See Also:
Tip 015: Calling an App Engine from within PeopleCode
Tip 039: Using Population Selection