PeopleCode

Code to get the record and count from the data base

Step:1 PeopleCode:
Local File &MYFILE;
Local string &str_cnt;
Local string &FPath;

&str_cnt = "Record Name" | Char(9) | "Count";
&FPath = "\\psapsftt\TTEF\OneSource\PC-Inbound\Record.xls";
&MYFILE = GetFile(&FPath, "W", %FilePath_Absolute);
&MYFILE.WriteLine(&str_cnt);

Step2:Doselect

%SelectInit(RECNAME)
SELECT RECNAME
FROM %Table(PSRECDEFN)
WHERE RECNAME NOT IN (Record Names)
AND RECTYPE NOT IN (2,3,5) /*2 - Derived/Work 3- Sub-Record 5- Dynamic View */

Step:3:SQl
%SelectInit(COUNTER1)
SELECT COUNT(*)
FROM %Table(%bind(RECNAME))

Step:4:PeopleCode:

Code would useful to create a .txt file thru App Engine

Write the code in PeopleCode Action:
Local File &MYFILE;
&PS_SERVDIR = (GetEnv("PS_SERVDIR")) | "/";
&FPath = &PS_SERVDIR | "file.txt";
&MYFILE = GetFile(&FPath, "W", %FilePath_Absolute);
&MYFILE.WriteLine(&Input);

&MYFILE.Close();

Code useful to view a file

SQLExec(SQL.CSGC_DB_NAME, &NAME);
SQLExec("SELECT URL FROM %Table(:2) WHERE DISTNODENAME=:1", &NAME, Record.CDM_DIST_NODE, &URL);
&PRCSOUTPUTDIR = &URL | "/CSGC_CSHEET1.pdf";
ViewContentURL(&PRCSOUTPUTDIR);
ViewContentURL(“www.gmail.com”);

Code useful to open a file

Write the code in PeopleCode Action:
&FileName = ;
&ret = GetAttachment("RECORD://CSGC_CSHT_ATACH", &FileName, "/" | &FileName, "PS_SERVDIR", True);
&PS_SERVDIR = (GetEnv("PS_SERVDIR")) | "/";
&FilePath = &PS_SERVDIR | &FileName;

If &ret = %Attachment_Success And
FileExists(&FilePath, %FilePath_Absolute) Then

&TxtFile = (GetFile(&FilePath, "R", %FilePath_Absolute));

While &TxtFile.ReadLine(&Input)
&Input = LTrim(RTrim(&Input, " "), " ");
;
End-While;
End-If;

&TxtFile.Close();

Code to hide translate values dynamically

Write the code in RowInit:
Local Rowset &Xlat;

&FLD = GetRecord(Record.PY_IC_WRK1).GetField(Field.ACCOUNT_TYPE_DD);
&FLD.ClearDropDownList();

&Xlat = CreateRowset(Record.PSXLATITEM);
&Xlat.Fill("WHERE FILL.FIELDNAME = 'ACCOUNT_TYPE_DD' AND FILL.FIELDVALUE IN ('C','S')");

&Xlat_cnt = &Xlat.ActiveRowCount;
For &I = 1 To &Xlat_cnt
&CodeIn = &Xlat.GetRow(&I).GetRecord(1).FIELDVALUE.Value;
&DescIn = &Xlat.GetRow(&I).GetRecord(1).XLATLONGNAME.Value;

&FLD.AddDropDownItem(&CodeIn, &DescIn);
End-For;

PeopleCode Check Number and Check Letter Functions

Couple PeopleCode functions I came across. One insures a string consists of numbers and one insures a string consists of letters.

Function Check_Number(&STR) Returns boolean;
   &LEN = Len(&STR);
   If &LEN = 0 Then
      Return False;
   End-If;
   For &I = 1 To &LEN;
      &CODE = Code(Substring(&STR, &I, 1));
      If (&CODE < 48 Or
            &CODE > 57) Then
         Return False;
      End-If;
   End-For;
   Return True;
End-Function;

Function Check_Letter(&STR) Returns boolean;
   &LEN = Len(&STR);
   If &LEN = 0 Then
      Return False;
   End-If;

Running an SQR from within your PeopleCode program

Therefore, the best and safest way to launch an SQR program is to use the People Code functions CreateProcessRequest() and Schedule(). The CreateProcessRequest function allows you to create a Process Request object. Remember, you should be coding your People Code programs using the Object Oriented methods. Once you’ve created your object, you can assign values to its properties and use the Schedule method to submit the process request for scheduling. The CreateProcessRequest function takes 2 arguments. The Process Type and the Process Name.

REM Declare your Variables;

Code to insert any data from file to Record using Appengine

we need to create an AET record and Base Record (if it is anew record or else we can use the existing Record). Then create a RunControl Page with the fields File Path Name, Record Name.

SQL Code:
%SelectInit (FILE_PATH_NAME, RECNAME)
 SELECT FILE_PATH_NAME
 , RECNAME
  FROM %Table (XX_XXXXX_RUN1)
 WHERE OPRID=%OperatorId
   AND RUN_CNTL_ID=%RunControl

People Code:

Local File &MYFILE, &MYFILE1;
Local string &PATH_READ, &PATH_WRITE, &REC, &rec_value;
Local array of string &values;
Local Record &rec1;
&DATE = %Datetime;

Code to know whether the Scheduled App Engine ran to success or not

  If &MYRQST.Status = 0 Then /* if Schedule status is success */

      &LOOP = 0;
      While &LOOP = 0
         SQLExec("SELECT A.DISTSTATUS, A.RUNSTATUSDESCR FROM PS_PMN_PRCSLIST A WHERE A.PRCSNAME = :1 AND A.PRCSINSTANCE = (SELECT MAX(B.PRCSINSTANCE) FROM PS_PMN_PRCSLIST B WHERE B.PRCSNAME = A.PRCSNAME)", &MyAppName, &POSTED, &STATUS);
         
         If &STATUS = "Success" And
               &POSTED = 5 Then /* Posted */
            &LOOP = 1
         End-If;
         
         If &STATUS = "Success" And /* Not Posted */

Code to Schedule App Engine thru PeopleCode

Local ProcessRequest &MYRQST;
   
   &MyAppName = "CSGC_OL_RVW";
   &MYRQST = CreateProcessRequest("Application Engine", &MyAppName);
   &MYRQST.RunControlID = "TEST";
   &MYRQST.RunLocation = "PSUNX";      
   &MYRQST.Schedule();
   
   If &MYRQST.Status = 0 Then /* if Schedule status is success */
 
  End-If;