OutBound PeopleCode using CI & AE

/* ===>
This is a dynamically generated PeopleCode template to be used only as a helper
to the application developer.
You need to replace all references to '[*]' OR default values with  references to
PeopleCode variables and/or a Rec.Fields. */

Local File &fileLog;
Local ApiObject &oSession, &oIsEmpdeptCi;
Local ApiObject &oIsEmpTblCollection, &oIsEmpTbl;

Function errorHandler()
   Local ApiObject &oPSMessageCollection, &oPSMessage;
   Local number &i, &cnt;
   Local string &sErrMsgSetNum, &sErrMsgNum, &sErrMsgText, &sErrType;
  
   &oPSMessageCollection = &oSession.PSMessages;
   For &i = 1 To &oPSMessageCollection.Count
      &oPSMessage = &oPSMessageCollection.Item(&i);
      &sErrMsgSetNum = &oPSMessage.MessageSetNumber;
      &sErrMsgNum = &oPSMessage.MessageNumber;
      &sErrMsgText = &oPSMessage.Text;
      &fileLog.WriteLine(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText);
   End-For;
   rem ***** Delete the Messages from the collection *****;
   &oPSMessageCollection.DeleteAll();
End-Function;

try
   rem ***** Set the Log File *****;
   &fileLog = GetFile("C:\Ismail\IS_EMPDEPT_CI.log", "w", "a", %FilePath_Absolute);
   &fileLog.WriteLine("Begin");
   rem ***** Get current PeopleSoft Session *****;
   &oSession = %Session;
  
   rem ***** Set the PeopleSoft Session Error Message Mode *****;
   rem ***** 0 - None *****;
   rem ***** 1 - PSMessage Collection only (default) *****;
   rem ***** 2 - Message Box only *****;
   rem ***** 3 - Both collection and message box *****;
   &oSession.PSMessagesMode = 1;
  
   rem ***** Get the Component Interface *****;
   &oIsEmpdeptCi = &oSession.GetCompIntfc(CompIntfc.IS_EMPDEPT_CI);
   If &oIsEmpdeptCi = Null Then
      errorHandler();
      throw CreateException(0, 0, "GetCompIntfc failed");
   End-If;
   &cnt = 1;
   rem ***** Set the Component Interface Mode *****;
   &oIsEmpdeptCi.InteractiveMode = False;
   &oIsEmpdeptCi.GetHistoryItems = True;
   &oIsEmpdeptCi.EditHistoryItems = True;
   Local Record &rec, &rec1;
   Local SQL &Sql1, &Sq2;
   &myfile = GetFile("c:/Ismail/Outbnd_ci.txt", "W", %FilePath_Absolute);
   If &myfile.IsOpen Then
      &rec1 = CreateRecord(Record.IS_DEPT_TBL);
      &rec = CreateRecord(Record.IS_EMP_TBL);
      &Sql1 = CreateSQL("SELECT * FROM PS_IS_DEPT_TBL");
      While &Sql1.Fetch(&rec1)
         &dno = &rec1.IS_DEPTNO.Value;
         &dname = &rec1.IS_DESC.Value;
         &dloc = &rec1.IS_LOC.Value;
         &Sql = CreateSQL("SELECT * FROM PS_IS_EMP_TBL where IS_DEPTNO = :1", &dno);
         While &Sql.Fetch(&rec)
            &eno = &rec.IS_EMPID.Value;
            &name = &rec.IS_EMPNAME.Value;
            &sex = &rec.IS_SEX.Value;
            &sal = &rec.IS_SAL.Value;
            &hdt = &rec.IS_HIRE_DT.Value;
            &chk = &rec.IS_CHECK.Value;
            &desc = &rec.IS_DESC.Value;
            &mbl = &rec.IS_MOBILE.Value;
            &hno = &rec.IS_HOUSENO.Value;
            &state = &rec.IS_STATE.Value;
            &st = &rec.IS_SPECIFICATION.Value;
            &city = &rec.CITY.Value;
            &myfile.writeline(&dno | "," | &dname | "," | &dloc | "," | &eno | "," |

                             &name | "," | &sex | "," | &sal | "," | &hdt | "," |

                              &chk | "," | &desc | "," | &mbl | "," | &hno | " , " |

                            &state | "," | &st | " , " | &city);
         End-While;
         &oIsEmpdeptCi.IS_DEPTNO = &dno;
         If &cnt = 1 Then
            Rem Avoid multiple creation of CI object
            rem ***** Set Component Interface Get/Create Keys *****;
            rem ***** Execute Get *****;
           
            If Not &oIsEmpdeptCi.Get() Then
               rem ***** No rows exist for the specified keys.*****;
               errorHandler();
               throw CreateException(0, 0, "Get failed");
            End-If;
         End-If;
         &cnt = &cnt + 1;
         Rem Avoid multiple creation of CI object
        
        
         rem ***** Execute Create ******;
         rem If Not &oIsEmpdeptCi.Create() Then;
         rem ***** Unable to Create Component Interface for the Add keys provided. *****;
         rem     errorHandler();
         rem     throw CreateException(0, 0, "Create failed");
         rem End-If;
        
        
         rem ***** Begin: Get/Set Component Interface Properties *****;
         rem ***** Get/Set Level 0 Field Properties *****;
        
         &fileLog.WriteLine("&oIsEmpdeptCi.IS_DEPTNO = " | &oIsEmpdeptCi.IS_DEPTNO);
         &oIsEmpdeptCi.IS_DESC = &dname;
         &fileLog.WriteLine("&oIsEmpdeptCi.IS_DESC = " | &oIsEmpdeptCi.IS_DESC);
         &oIsEmpdeptCi.IS_LOC = &dloc;
         &fileLog.WriteLine("&oIsEmpdeptCi.IS_LOC = " | &oIsEmpdeptCi.IS_LOC);
        
        
         rem ***** Set/Get IS_EMP_TBL Collection Field Properties -- Parent: PS_ROOT Collection *****;
         /*           &oIsEmpTblCollection = &oIsEmpdeptCi.IS_EMP_TBL;
            Local integer &i16;
           For &i16 = 1 To &oIsEmpTblCollection.Count;
               &oIsEmpTbl = &oIsEmpTblCollection.Item(&i16);
               &oIsEmpTbl.IS_EMPID = &eno;
               &fileLog.WriteLine("&oIsEmpTbl.IS_EMPID = " | &oIsEmpTbl.IS_EMPID);
               &oIsEmpTbl.IS_EMPNAME = &name;
               &fileLog.WriteLine("&oIsEmpTbl.IS_EMPNAME = " | &oIsEmpTbl.IS_EMPNAME);
               &oIsEmpTbl.IS_SEX = &sex;
               &fileLog.WriteLine("&oIsEmpTbl.IS_SEX = " | &oIsEmpTbl.IS_SEX);
               &oIsEmpTbl.IS_SAL = &sal;
               &fileLog.WriteLine("&oIsEmpTbl.IS_SAL = " | &oIsEmpTbl.IS_SAL);
               &oIsEmpTbl.IS_HIRE_DT = &hdt;
               &fileLog.WriteLine("&oIsEmpTbl.IS_HIRE_DT = " | &oIsEmpTbl.IS_HIRE_DT);
               &oIsEmpTbl.IS_DESC_1 = &desc;
               &fileLog.WriteLine("&oIsEmpTbl.IS_DESC_1 = " | &oIsEmpTbl.IS_DESC_1);
               &oIsEmpTbl.IS_CHECK = &chk;
               &fileLog.WriteLine("&oIsEmpTbl.IS_CHECK = " | &oIsEmpTbl.IS_CHECK);
               &oIsEmpTbl.IS_MOBILE = &mbl;
               &fileLog.WriteLine("&oIsEmpTbl.IS_MOBILE = " | &oIsEmpTbl.IS_MOBILE);
               &oIsEmpTbl.IS_HOUSENO = &hno;
               &fileLog.WriteLine("&oIsEmpTbl.IS_HOUSENO = " | &oIsEmpTbl.IS_HOUSENO);
               &oIsEmpTbl.IS_STATE = &state;
               &fileLog.WriteLine("&oIsEmpTbl.IS_STATE = " | &oIsEmpTbl.IS_STATE);
               &oIsEmpTbl.CITY = &city;
               &fileLog.WriteLine("&oIsEmpTbl.CITY = " | &oIsEmpTbl.CITY);
              
            End-For;  */
        
         rem ***** End: Get/Set Component Interface Properties *****;
        
        
      End-While;
   End-If;
   rem ***** Execute Save *****;
   /*  If Not &oIsEmpdeptCi.Save() Then;
      errorHandler();
      throw CreateException(0, 0, "Save failed");
   End-If;  */
  
   rem ***** Execute Cancel *****;
   rem If Not &oIsEmpdeptCi.Cancel() Then;
   rem     errorHandler();
   rem     throw CreateException(0, 0, "Cancel failed");
   rem End-If;
  
catch Exception &ex
   rem Handle the exception;
   &fileLog.WriteLine(&ex.ToString());
end-try;
&fileLog.WriteLine("End");
&fileLog.Close();
&myfile.Close();

No comments:

Post a Comment