October 22, 2010

Some PeopleCode sample for quick reference

Stand alone rowset

Stand alone rowset is used to create a record structure and traverse using that. We use the &rowset = CreateRowset(Recorc.record_name); to create a standalone rowset. When we create a stand alone rowset the data will not be filled in this. For filling the data we can use Fill property (as shown in below example).

Local rowset &rowset;
&rowset = CreateRowset(Recorc.record_name);
&rowset.Fill(“WHERE EMPLID = :1”, Record.Fieldname);


We can copy a rowset from one to another using the Copyto function

Local Rowset &MYRS1, MYRS2;
Local String &EMPLID;

&MYRS1 = CreateRowset(RECORD.SOMEREC);
&MYRS2 = CreateRowset(RECORD.SOMEREC);

&EMPLID = '8001';

&MYRS1.Fill("where EMPLID = :1", &EMPLID);
&MYRS1.CopyTo(&MYRS2);


To add a child rowset for a created rowset.
• RECORD1
• RECORD2
• RECORD3
To build rowsets with child rowsets, use code like the following:
Local Rowset &rsREC1, &rsREC2, &rsREC3;

&rsREC3 = CreateRowset(Record.RECORD3);
&rsREC2 = CreateRowset(Record.RECORD2, &rsREC3);
&rsREC1 = CreateRowset(Record.RECORD2, &rsREC2);


OR in a single line we can write like

&rsREC3 = CreateRowset(Record.RECORD1, CreateRowset(Record.RECORD2, CreateRowset(Record.RECORD3)));

Component buffer access using PeopleCode

Buffer access is used to access the value for the current active component. When a component is modeled and displayed in the page the records/fields/values are stored in the hierarchical structure in the memory. We can use the component buffer access classes to get these values.

There are four data buffer classes: Rowset, Row, Record, and Field.

These four classes are the foundation for accessing component buffer data.

A field object, which is instantiated from the Field class, is a single instance of data within a record and is based on a field definition.

A record object, which is instantiated from the Record class, is a single instance of a data within a row and is based on a record definition. A record object consists of one to n fields.

A row object, which is instantiated from the Row class, is a single row of data that consists of one to n records of data. A single row in a component scroll area is a row. A row may have one to n child rowsets. For example, a row in a level two scroll area may have n level three child rowsets.

A rowset object is a data structure used to describe hierarchical data. It is made up of a collection of rows. A component scroll area is a rowset. You can also have a level zero rowset.

Getlevel0 is used to access the level0 record or the primary record.

Local Rowset &ROWSET;
&ROWSET = GetLevel0()(1).GetRowset(SCROLL.LEVEL1_REC);
Example:
&Rowset0 = GetLevel0();
&Rowset1 = &Rowset0(1).GetRowset(Scroll.RECORD1);
&Rowset2 = &Rowset1(CurrentRowNumber(1)).GetRowset(Scroll.RECORD2);
&z_ats_sw = &Rowset2(1).RECORD2.FIELD.Value;


OR

GetLevel0()(1).GetRowset(Scroll.dept_tbl).GetRow(getcurrentactiverow(1)).GetRecord(Record.Z_HRS_JO_CMP_WK).GetField(Field.SS_HIST_GRPBOX_LBL)

To get the current active number for a record use

geteffectivenum(effdt)
geteffectiveitemnum(effdt,effseq)


To read data from a file layout

rem***********************************************************;
rem * PeopleCode to Import Data *;
rem **********************************************************;
Local File &FILE1;
Local Rowset &RS1, &RS2;
&FILE1 = GetFile("specify the path here", "r", "a", %FilePath_Absolute);
&FILE1.SetFileLayout(FileLayout.PMD_FILE1);
&RS1 = &FILE1.CreateRowset();
&RS1 = &FILE1.ReadRowset();
While &RS1 <> Null;
    rem code
End-While;



Call the CI using Peoplecode


Local ApiObject &oSession, &oPmdComp1;
&oSession = %session;
&oPmdComp1 = &oSession.GetCompIntfc(CompIntfc.PMD_COMP1);
If &oPmdComp1 = Null Then errorHandler(); throw CreateException(0, 0, "GetCompIntfc failed"); End-If;
rem ***** Set the Component Interface Mode *****; &oPmdComp1.InteractiveMode = False; &oPmdComp1.GetHistoryItems = True; &oPmdComp1.EditHistoryItems = False;
rem ***** Set Component Interface Get/Create Keys *****;
&oPmdComp1.EMPLID = [*];
&oPmdComp1.get();


To Schedule a job using PeopleCode

This sample code is used to submit a sqr to the scheduler.

REM Declare your Variables;
Local ProcessRequest &MYRQST;
Local String &MySQR;

&MySQR = "MYSQR"
REM Create My Process Request Object;
&MYRQST = CreateProcessRequest("SQR Process", &MySQR);

REM Set Properties of My Process Request Object;
&MYRQST.RunControlID = "MYRUNCNTRL_ID"

REM Set Properties of My Process Request Object;
&MYRQST.SetOutputOption("Web", "PDF", "", &MySQR);


The above example creates a ProcessRequest object for the MYSQR SQR named &MYRQST.

&MYRQST.Schedule();
If &MYRQST.Status = 0 then
/* Schedule succeeded. */
Else
/* Process (job) not scheduled, do error processing */
End-If;

1 comment:

  1. I tried to use CreateRowset above to create a child relationship but when I checked the level property for the rowset the value is always 0.

    I do not understand how to use CreateRowset to create a rowset at a level other than 0.

    If you can help me with this I'd appreciate it greatly.

    ReplyDelete

Page field configurator

Peoplesoft study   Page field configurator This is an enterprise component and not a tools feature ( https://docs.oracle.com/cd/F138...