The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Thursday 14 February 2013

Working with Collections in CI



This blog is intended for readers who have basic knowledge of CI’s and like advanced actions like navigating through and updating collections.

What is a collection in CI? In simple words collection is same as a rowset in your component buffer. You can navigate through the collection and update/delete any row in the collection as you do with rowset in the component. Let’s see how this can be achieved by PeopleCode.

To assign the collection (rowset) to a variable you can use the below code.

&CI = %Session.GetCompIntfc(CompIntfc.MY_CI);
&CI.KEY =”Key”;
&CI.Get();
/* Get the collection(rowset) */
&Collection = &CI.MY_COLLECTION;

Your collection name may not always be same as the rowset.  So you should verify with the CI to get the correct collection name.

To get the number of rows in the rowset, similar to the ActiveRowCount property in the rowsets you can use the Count property.

/* To get the number of rows */
&nRows = &Collection.Count;

Now to insert a new row to the collection you can use InserItem method.  You need to specify the index (row number in rowset) while using the method.
&myItem = &Collection.InsertItem(1);

The above code will insert a new row at the first row. It is, the new row’s row count will be 2. This is similar to clicking the + button in the PIA page. If we click the + button on the first row, the new row will be inserted as the second row.

Now to update the value in this row, you can directly call the property (corresponding to Field in component) and assign.

&myItem.NAME = “My Name”;

Now if your component interface is in interactive mode and your grid in the component has some code to sort the grid at field change you should be very careful. Eg: when you change a date, the grid will sort based on the ascending value of date. In such case it can happen that when you enter the value, the rowset will get sorted and when you update the second field, you may be actually updating the second field in some other row as the index has changed due to sorting. In that case you need to loop back and get the original Item(row) and then proceed with updating.

Now to get the Nth row of the collection (rowset) you can use the below code.

&myItem = &Collection.Item(&RowNumber);


Now to delete the row from the component, you can deleteItem method. When using the method, you should specify the index of the row to be deleted.

&Collection.DeleteItem(2);

If your component is effective dated, to get the effective dated row you can use CurrentItem method.
&effDatedItem = &Collection.CurrentItem;

To fetch the row number of the effective dated row, you can directly use the CurrentItemNum property.

&CurrentRowNumber = &Collection.CurrentItemNum;


All these above logics can be clubbed to loop up to level 3. For example you can use the below code.

&CI  = %Session.GetCompIntfc(CompIntfc.MY_CI);

/* Pass the Key */
&CI.KEY = “Key”;
&CI.Get();

/* Get Level 1 Collection */
&Collection1 = &CI.COLLECTION_ONE;
&MyItem1 = &Collection1.Item(1);

/*Get Level 2 Collection */
&Collection2 = &MyItem1.COLLECTION_TWO;
&MyItem2 = &Collection2.Item(1);

/*Get Level3 Row */
&Collection3 = &MyItem2.COLLECTION_THREE;
&MyItem3 = &Collection3.Item(1);

/* Updating Level 3 row */
&MyItem3.FIELD_PROPERTY  = “My Value”;


With the set of commands mentioned in this blog you will be able achieve most the functions desired for the business logic with rowsets in component interface. For the full list of commands that can be used for a component interface in PeopleSoft, you can refer the corresponding chapter in PeopleBooks.


3 comments:

  1. Having read this I believed it was very informative. I appreciate you finding the time and energy to put this informative article together. I once again find myself spending a significant amount of time both reading and posting comments. But so what, it was still worth it! paypal login my account

    ReplyDelete

Note: only a member of this blog may post a comment.

Followers