Retrieving a List of Instance of Data Example
The following is an example of how to retrieve a list of instances of data.
To retrieve a list of instances of data:
In this example, you are getting a list of existing instances of data for the EMPL_CHKLST_CI Component Interface, which is based on the EMPLOYEE_CHECKLIST component. The following is the complete code sample: the steps break it up and explain each line.
Local ApiObject &MYSESSION;
Local ApiObject &MYCI;
Local ApiObject &MYNEWCI;
&MYSESSION = %Session;
&MYCI = &MYSESSION.GetCompIntfc(COMPINTFC.EMPL_CHKLST_CI);
&MYCI.EMPLID= "8";
&MYCI.LAST_NAME_SRCH = "S";
&MYLIST = &MYCI.Find();
For &I = 1 to &MYLIST.Count;
/* note: do not reuse the CI used to create the list, or the list will be⇒
destroyed */
&MYNEWCI = &MYLIST.Item(&I);
/* CI from list still must be instantiated to use it */
&MYNEWCI.Get();
/* do some processing */
End-For;-
Get a session object.
Before you can get a Component Interface, you have to get a session object. The session controls access to the Component Interface, provides error tracing, enables you to set the runtime environment, and so on.
&MYSESSION = %Session; -
Get a Component Interface.
Use the GetCompIntfc method with a session object to get the Component Interface. You must specify a Component Interface definition that has already been created. You receive a runtime error if you specify a Component Interface that doesn’t exist.
&MYCI = &MYSESSION.GetCompIntfc(COMPINTFC.EMPL_CHKLST_CI);After you execute the GetCompIntfc method, you have only the structure of the Component Interface. You haven’t populated the Component Interface with data yet.
-
Set the FINDKEYS values.
These can be alternate key values or partial key values. If no instance of the data matching the key values is found, you receive a runtime error.
&MYCI.EMPLID = "8"; &MYCI.LAST_NAME_SRCH = "S"; -
Get a list of data instances for the Component Interface.
After you set the alternate or partial key values, use the Find method to return a list of data instances for the Component Interface.
&MYLIST = &MYCI.Find();Note:
The Find method can be executed only at level zero in a Component Interface.
-
Select an instance of the data.
To select an instance of the data, you can use any of the following standard data collection methods:
-
First
-
Item
-
Next
-
For example, you could loop through every instance of the data to do some processing:
For &I = 1 to &MYLIST.Count;
/* note: do not reuse the Component Interface used to */
/* create the list here, or the list will be destroyed */
&MYNEWCI = &MYLIST.Item(&I);
/* CI from list must still be instantiated to use it */
&MYNEWCI.Get();
/* do some processing */
End-For;After you have a specific instance of the data, you can get values, set values, and so on.