You create a coroutine as a standard Report; that is, you use the Painter and Editor to create Report frames and logic that is included in the coroutine.
The name of your coroutine must conform to the naming convention used for Reports. To indicate that the Report is a coroutine, Set to True the Generate as Coroutine configuration property under the Environment category for the Report. If you have chosen to build your Report as a coroutine, you cannot run the Report as a normal Report.
Structure
You structure a coroutine in the same manner as a Report; that is, the Main method contains the Main logic of your coroutine, and all other frames might contain logic, a painted print image, or a mixture of both. Frames within your coroutine are invoked by using the Print command.
Example Code for a Coroutine
The following example is a sample of logic from a coroutine, which performs a lookup of a database record. The coroutine expects two parameters, S-FUNC and S-NAME, passed using the built-in attribute Glb.Param, and returns a status value in S-STATUS.
Prerequisites:
An attribute PARAM_GROUP is created with the stereotype 'Group'.
A String attribute S_FUNC with length 5 is added as a member of PARAM_GROUP.
A String attribute S_NAME length 20 is added as a member of PARAM_GROUP.
A String attribute S_STATUS length 5 is added as a member of PARAM_GROUP.
In the coroutine Main logic the following code is written:
Move GLB.PARAM PARAM_GROUP Move "*****" S_STATUS DoWhen S_FUNC = "READ" LookUp FROM S_NAME NAMEDB Break End DoWhen S_NAME = NAMEDB.SURNAME && GLB.STATUS = GLB.SPACES Move GLB.SPACES S_STATUS End End Move PARAM_GROUP GLB.PARAM
Ensure that a Group attribute defines local storage for copying the parameters to and from the coroutine. The first executable instruction in your coroutine should be moving the value of Glb.Param to this local attribute. The last executable instruction should move any data to be returned to the caller into Glb.Param.