How to Call SQR program using peoplecode

How to Call SQR program using peoplecode

&Rec = CreateRecord(Record.process_table);
      &Rec.OPRID.Value = %UserId;
      &Rec.RUN_CNTL_ID.Value = &ProcessName;
      
      If (&Rec.SelectByKey()) Then
         &Rec.field1.Value = table1.field1;
         &Rec.field2.Value = table1.field2;
         &Rec.field3.Value = table1.field3;
         &Rec.field4.Value =table1.field4;
         &Rec.Update();
      Else
         &Rec.SetDefault();
         &Rec.OPRID.Value = %UserId;
         &Rec.RUN_CNTL_ID.Value = &ProcessName;
         &Rec.field1.Value = table1.field1;
         &Rec.field2.Value = table1.field2;
         &Rec.field3.Value = table1.field3;
         &Rec.field4.Value =table1.field4;
      End-If;
/*specify your desired output format and destination*/
&ProcessType = "SQR Report";
      &OutDestFormat = "PDF";
      &OutDestType = "Web";
&MYRQST = CreateProcessRequest();
      &MYRQST.RunControlID = &ProcessName;
      &MYRQST.ProcessName = &ProcessName;
      &MYRQST.ProcessType = &ProcessType;
      &MYRQST.OutDestFormat = &OutDestFormat;
      &MYRQST.OutDestType = &OutDestType;
      &MYRQST.RunDateTime = %Datetime;
      &RETURN = &MYRQST.Schedule();



People code Tutorial

People code Tutorial
People code is a language like other languages with  it’s own DataTypes , Statements.

Every People Code program is associated with an Application Designer component and with an event.

Peoplecode Locations: Record Fields ,  Menus ,  Components  Pages ,  Business Components , Application Messages ,  Application Engine.

Data Types    

NUMBER,STRING,DATE,TIME,DATETIME,ANY

Scope :

                Local Variables
                Global Variables
                Component Variables

Other Variables :

                System Variables

                Derived/Work Fields



Syntax for declaration:

   <scope> <type> &<variable_name>



Local Variables :


Temporary memory location that holds the value.

Global Variables :

 Exist for the complete session and are used to transfer values between panel groups.
Session means signin to signout is called session

Component Variables :

Exist for the duration of the current PS component.
Used to transfer values between programs on the same component


System Variables :

Internally maintained  and can be referred by the people code any time.
Begins with %.
     Ex : %Date ,%Time ,%Page ,%Menu,%Component,%DBName,%Mode etc...

Derived/Work Fields :

Used when we need to pass values from one program  to another  without the  field values being stored in the    database.
Existence limited to the current component.
They are usually display only fields on a page  or have them as invisible fields on the page



User Defined Variables:


Variables which are defined by developers starts with &.

Operators:

Mathematical  :  + ,- ,* ,/ ,** , |

Comparison : = ,!= ,<> ,>= ,<= ,< ,>

Logical       :  NOT ,AND ,OR



Functions:

User defined functions
Built-in Functions


User defined function:

Internal Peoplecode

Functions that are called directly from the same program where the function was defined without the declare function statement.

External PeopleCode

Stored as Function Libraries( derived/work records named
with prefix “FUNCLIB_”
convention is define these functions in the FieldFormula Event.


Syntax for defining or writing a function
Function <function_name> (<param1,<param2>....)
           stmt1;
           stmt2;
           return <expression>;
End-Function;


Syntax for Declaring a Function
Declare Function <function_name> PeopleCode   <Record_name.FieldName>.FieldFormula.


Built-in Functions:

Component Buffer
Used to modify,update,hide fields in the buffer area.

ActiveRowCount,AddKeyListItem,CompareLikeFields,ClearKeyList,
ComponentChanged,CopyFields,CopyRow,CurrentLevelNumber.


Conversion
Char,Code,Codeb,ConvertChar,String,Value


Current Date and Time
%CurrentDateIn,%CurrentDateOut,%CurrentDateTimeIn,
%CurrentDateTimeOut,%CurrentTimeIn,%CurrentTimeOut



Database and platform
%DbName,%DbType

Data Buffer Access
CreateRecord,CreateRowset,FlushBulkInserts ,GetField,GetLevel0 ,
GetRecord ,GetRow,GetRowset

Date and Time


Used to calculate and manipulate dates

AddToDate,AddToDateTime,AddToTime, Date,DateValue
Day,Days,Days360,Days365


String  Functions

Used to manipulate character Strings.

Number Functions

Used to manipulate numeric values

Security Functions

Used for security purpose.



Data Buffer access Classes


Field ,Record ,Row ,Rowset

Field Class

       Attributes             : Name,Enabled,Type
       Methods              :  GetLongLabel,SearchClear,SetCursorPos
       Built-In Functions: GetField.


Record Class
       Attributes            : Name ,IsChanged ,FieldCount                                          
       Methods             :  CompareFields,CopyChangedFieldsTo,CopyFieldsTo
       Built-In Functions: GetRecord
Row Class
       Attributes               : Visible ,IsChanged
       Methods                : CopyTo ,GetNexteffRow.
       Built-in Functions  : GetRow
RowSet Class
       Attributes               : ActiveRowCount
       Methods                : CopyTo ,DeleteRow ,Fill
       Built-in Functions  : CreateRowSet,GetLevel0,GetRowSet



Statements in PeopleCode


Branching Statements
if Statement:  

   syntax:  if <condition>
                        stmt1;                                                        
                             else 
                       stmt2;
                            end-if;  


Evaluate Statement


Evaluate <field or variable>
when = <value1>
                stmt1; break;
when = <value2>
                stmt2; break;
when-other
                stmt3;break;
End-Evaluate;

For Loop


  For <&variable> = <start-value> to <end-value>                            
                        [Step stepvalue>]
                                   stmt1;  stmt2;
                            End-for;


                                                                                            
                                                                              

How to Skip a Search Record Prompt When You Know the keys

How to Skip a Search Record Prompt When You Know the keys

You have two settings to choose from: skip if possible (0) and force display (1).

If you use the skip if possible setting, then you need to have the keys. Assume your
keys are EMPLID, EMPL_RCD, and EFFDT. Here is what the SearchInit PeopleCode
would look like:

SetSearchDialogBehavior(0);
EMPLID = %EmployeeID;
EMPL_RCD = 0;
EFFDT = &DateVariable;

How to Access a field in level 2 grid in a page using people code

How to Access a field in level 2 grid in a page using people code
If you have a page which has level 0 record and a level 1 scroll area .The level 1 scroll area has level 1 and level 2 grids in it, to access a field in the level 2 grid, you need to access the level 1 grid first and then only the level 2 grid field can be accessed, since the level 2 grid cannot be accessed directly . It cannot be accessed even through the scroll area since the whole scroll act as a row and for a level 0 parent row, there can be any number of scroll level data.
/*level 1 scroll : SCROLL_1 (Page field name)

level 1 record : REC_LEVEL1

level 2 record : REC_LEVEL2
*/

local rowset &Rs1, &Rs2;

&Rs1 = GetLevel0()(1).GetRowset(Scroll.REC_LEVEL1);

For &i = 1 To &Rs1.ActiveRowCount
   &Rs2 = &Rs1.GetRow(&i).GetRowset(Scroll.REC_LEVEL2);
   For &j = 1 To &Rs2.ActiveRowCount
    
         &Rs2(&j).ANY_RECORD_IN_LEVEL2.CORRESPONDING_FIELD.Value = *****

****************************
/*DO THE REQUIRED PROCESSING */
****************************

    End-For;
End-For;

How Sheduling SQR using Peoplecode

How Sheduling SQR using Peoplecode
Description
Structured Query Report (SQR) can be executed with the help of peoplecode without taking the user to Process request page. The best way to do it is to create a process request and schedule it.
The Steps Include 1)Declare a ProcessRequest object 2)Declare name of the sqr to be processed 3)Create a Process Request Object; 4)Set Properties of the Process Request Object 5)Schedule the SQR 6)If the Process (job) not scheduled, do error processing Problem this asset addresses In order to execute a Structured Query Report (SQR) , one has to go to the corresponding Process Request Page and run the SQR manually.This manual work is cumbersome and the user has to wait to execute the SQR at predefined time intervals
 
/* Declare a ProcessRequest object */
Local ProcessRequest &PRCSRQST; 

/* Declare name of the sqr FEB_PRCS to be processed */
Local String &SQR_TO_PROCESS; 

&SQR_TO_PROCESS = "FEB_PRCS"
/* Create a Process Request Object; */
&PRCSRQST = CreateProcessRequest("SQR Process", &SQR_TO_PROCESS);

/* Set Properties of the Process Request Object; */
REM CreateProccessRequest function takes these 2 arguments - Process Type and the Process Name;

&PRCSRQST.RunControlID = "FEB07";
&PRCSRQST.SetOutputOption("Web", "PDF", "", &SQR_TO_PROCESS); 

/* Schedule the SQR */
&PRCSRQST.Schedule();
If &PRCSRQST.Status = 0 then
/* Schedule successful. */
Else
/* Process (job) not scheduled, do error processing */

End-If;