In PeopleCode two types of rowsets exists:
1. One which is attached to the component and it maintained by the component processors. These rowsets are the scrolls, grids, scrollbars which are drawn on the pages included in the component.
2. Standalone rowsets which are not attached to the component and thus are not maintained by the component processor. Any changes to these are not migrated to the underlying tables and thus it is left to the developer to manually migrate the changes.
Lets have a closer look at the creation and population of a standalone rowset. For our example we will consider a simple rowset with one record. Let the record in the rowset be REC1 with fields EMPLID, FIRST_NAME,LAST_NAME.
Local Rowset &MyRowset;
&MyRowset = CreateRowset(Record.REC1);
Now to populate the data in this rowset object, Rowset class has listed Fill() method. The Fill method accepts a where string and bind parameter values and thus selects data in the rowset. The only issue is that the data is selected from the same record which is the rowset record. This means if I am creating my rowset from Record REC1, I can only select the data from record REC1. This is because the Fill() method does not give us the liberty to use another record for selecting data from [this is not the case with the Select() method which is used to select data in the standard component rowset].
So what if I want to have a standalone rowset created from Record REC1 but wanted to select the data into this from another record say REC2 using a custom SQL Select. This gives us the flexibility of using any number of records joined together for data selection into the rowset. A simple example can be:
SELECT A.EMPLID, B.FIRST_NAME,C.LAST_NAME FROM PS_REC2 A, PS_REC3 B, PS_REC4 C WHERE ......
Lets implement a simple app class to accomplish this.
We can directly extend the delivered Rowset class and create our own StandAloneRowset class with enhanced functionality.
Class StandAloneRowset extends Rowset
method StandAloneRowset(&StandAloneRec As String);
method FillUsingSQLObject(&SqlObj as SQL);
private
instance String &RsRec;
end-class;
method StandAloneRowset
&RsRec=&StandAloneRec;
%Super = CreateRowset(@("Record."|&RsRec));
end-method;
method FillUsingSQLObject
Local Record &Rec;
Local integer &Count;
&Rec = CreateRecord(@("Record."|&RsRec));
While &SqlObj.Fetch(&Rec)
if &Count > 0 then
%This.InsertRow(%This.ActiveRowCount);
end-if;
&Rec.CopyFieldsTo(%this.GetRow(%this.ActiveRowCount).GetRecord(@("Record."|&RsRec));
&Count = &Count + 1;
End-While;
end-method;
Lets use this simple class now. Since we have extended the rowset class, we do not have to write our own methods for insertrow(), deletrow etc...thus OOP's concepts comes handy in PeopleCode.
Local StandAloneRowset &MyRs;
Local SQL &MySql;
&MySql = CreateSQL("SELECT A.EMPLID, B.FIRST_NAME,C.LAST_NAME FROM A,B,C, WHERE ......",&Bind1,&Bind2....,&bindn);
&MyRs = create StandAloneRowset("REC1");
&MyRs.FillUsingSQLObject(&MySql);
So now your rowset contains the data returned by using SQL object. Remember all other Rowset operations on our StandAloneRowset remains the same [because we actually are having an instance of Rowset class].
We will explore more on the rowset in the days to come.

1. One which is attached to the component and it maintained by the component processors. These rowsets are the scrolls, grids, scrollbars which are drawn on the pages included in the component.
2. Standalone rowsets which are not attached to the component and thus are not maintained by the component processor. Any changes to these are not migrated to the underlying tables and thus it is left to the developer to manually migrate the changes.
Lets have a closer look at the creation and population of a standalone rowset. For our example we will consider a simple rowset with one record. Let the record in the rowset be REC1 with fields EMPLID, FIRST_NAME,LAST_NAME.
Local Rowset &MyRowset;
&MyRowset = CreateRowset(Record.REC1);
Now to populate the data in this rowset object, Rowset class has listed Fill() method. The Fill method accepts a where string and bind parameter values and thus selects data in the rowset. The only issue is that the data is selected from the same record which is the rowset record. This means if I am creating my rowset from Record REC1, I can only select the data from record REC1. This is because the Fill() method does not give us the liberty to use another record for selecting data from [this is not the case with the Select() method which is used to select data in the standard component rowset].
So what if I want to have a standalone rowset created from Record REC1 but wanted to select the data into this from another record say REC2 using a custom SQL Select. This gives us the flexibility of using any number of records joined together for data selection into the rowset. A simple example can be:
SELECT A.EMPLID, B.FIRST_NAME,C.LAST_NAME FROM PS_REC2 A, PS_REC3 B, PS_REC4 C WHERE ......
Lets implement a simple app class to accomplish this.
We can directly extend the delivered Rowset class and create our own StandAloneRowset class with enhanced functionality.
Class StandAloneRowset extends Rowset
method StandAloneRowset(&StandAloneRec As String);
method FillUsingSQLObject(&SqlObj as SQL);
private
instance String &RsRec;
end-class;
method StandAloneRowset
&RsRec=&StandAloneRec;
%Super = CreateRowset(@("Record."|&RsRec));
end-method;
method FillUsingSQLObject
Local Record &Rec;
Local integer &Count;
&Rec = CreateRecord(@("Record."|&RsRec));
While &SqlObj.Fetch(&Rec)
if &Count > 0 then
%This.InsertRow(%This.ActiveRowCount);
end-if;
&Rec.CopyFieldsTo(%this.GetRow(%this.ActiveRowCount).GetRecord(@("Record."|&RsRec));
&Count = &Count + 1;
End-While;
end-method;
Lets use this simple class now. Since we have extended the rowset class, we do not have to write our own methods for insertrow(), deletrow etc...thus OOP's concepts comes handy in PeopleCode.
Local StandAloneRowset &MyRs;
Local SQL &MySql;
&MySql = CreateSQL("SELECT A.EMPLID, B.FIRST_NAME,C.LAST_NAME FROM A,B,C, WHERE ......",&Bind1,&Bind2....,&bindn);
&MyRs = create StandAloneRowset("REC1");
&MyRs.FillUsingSQLObject(&MySql);
So now your rowset contains the data returned by using SQL object. Remember all other Rowset operations on our StandAloneRowset remains the same [because we actually are having an instance of Rowset class].
We will explore more on the rowset in the days to come.

Ashish,
ReplyDeleteI was trying your above example and getting error on %super =
It says "Inappropriate use of %Super. (2,83)"
Do you know why I would be getting the error?
I have a requirement to load the html area with the data from a SQL object.
Let me at a look at your code....Also %Super can only be used when you extend/implement a superclass. Send me the code for analysis.
ReplyDeleteRegards,
Ashish
Hi Ashish,
ReplyDeleteI'm new to Peoplecode and I would like to insert records from an SQL into a rowset, to create a chart. I was going through the codes that you wrote to extend a class. May I know where I should create these codes? Do I write these extension codes into records or?
Thanks!
Regards,
Michelle