Call Component Interface from AE

Local File &Source, &fileLog;
Local string &strLine, &FilePath, &EmplStatus;
Local array of string &Item;
Local number &Line, &SucCNT, &FailCNT;

Local ApiObject &oSession, &oCiJobDataChange;
Local ApiObject &oCollNameTypeVwCollection, &oCollNameTypeVw;
Local ApiObject &oCollNamesCollection, &oCollNames;
Local ApiObject &oCollAddressTypeVwCollection, &oCollAddressTypeVw;
Local ApiObject &oCollAddressesCollection, &oCollAddresses;
Local ApiObject &oCollPersonalPhoneCollection, &oCollPersonalPhone;
Local ApiObject &oCollEmailAddressesCollection, &oCollEmailAddresses;
Local ApiObject &oCollPersDataEffdtCollection, &oCollPersDataEffdt;
Local ApiObject &oCollPersNidCollection, &oCollPersNid;
Local ApiObject &oCollJobCollection, &oCollJob;
Local ApiObject &oCollJobJrCollection, &oCollJobJr;
Local ApiObject &oCollCompensationCollection, &oCollCompensation;
Local ApiObject &oCollJobEarnsDistCollection, &oCollJobEarnsDist;
Local ApiObject &oCollBenProgParticCollection, &oCollBenProgPartic;

Function errorHandler()
   Local ApiObject &oPSMessageCollection, &oPSMessage;
   Local number &i;
   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;


rem ***** Set the Log File *****;
&fileLog = GetFile("CI_JOB_DATA_CHANGE.log", "w", "a", %FilePath_Relative);
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 *****;
&oCiJobDataChange = &oSession.GetCompIntfc(CompIntfc.TSC_SALARY_INCREASE_CI);
If &oCiJobDataChange = Null Then
   &fileLog.WriteLine("Error in Get ComponentInterface - TSC_SALARY_INCREASE_CI.");
   errorHandler();
   throw CreateException(0, 0, "GetCompIntfc failed");
Else
   &fileLog.WriteLine("Success! Get ComponentInterface - TSC_SALARY_INCREASE_CI.");
End-If;

rem ***** Set the Component Interface Mode *****;
&oCiJobDataChange.InteractiveMode = False;
&oCiJobDataChange.GetHistoryItems = True;
&oCiJobDataChange.EditHistoryItems = False;

rem &FilePath = "E:\interface\" | %DbName | "\salary\z_load_salary.csv";
&FilePath = "E:\test.csv";
&Source = GetFile(&FilePath, "R", %FilePath_Absolute);

&Line = 0;
&SucCNT = 0;
&FailCNT = 0;

&fileLog.WriteLine("------------------------------------------------------------------------------------------------------------------------------");

While &Source.ReadLine(&strLine)
  
   &Line = &Line + 1;
   &Item = Split(&strLine, ",");
  
  
   SQLExec("SELECT A.EMPL_STATUS FROM PS_JOB A WHERE A.EMPLID = :1 AND A.EMPL_RCD = 0 AND A.EFFDT = (SELECT MAX(B.EFFDT) FROM PS_JOB B WHERE B.EMPLID = A.EMPLID AND B.EMPL_RCD = 0) ", &Item [1], &EmplStatus);
  
   If &EmplStatus = "A" Then
     
      rem ***** Set Component Interface Get/Create Keys *****;
      If All(&Item [1]) Then
         &oCiJobDataChange.KEYPROP_EMPLID = &Item [1];
      End-If;
      &oCiJobDataChange.KEYPROP_EMPL_RCD = 0;
     
      rem ***** Execute Create ******;
      If Not &oCiJobDataChange.Get() Then;
         rem ***** Unable to Create Component Interface for the Add keys provided. *****;
         &fileLog.WriteLine("Error! Can Not Get Employee When Processing " | &Line | ", Employee " | &Item [1] | ".");
         errorHandler();
      Else
        
         rem ***** Set/Get COLL_JOB Collection Field Properties -- Parent: PS_ROOT Collection *****;
         &oCollJobCollection = &oCiJobDataChange.COLL_JOB;
         &oCollJob = &oCollJobCollection.InsertItem(&oCollJobCollection.CurrentItemNum());
         &oCollJob.KEYPROP_EFFDT = Date(&Item [2]);
        
         SQLExec("SELECT COUNT(*) FROM PS_JOB WHERE EMPLID=:1 AND EMPL_RCD=:2 AND EFFDT=%DateIn(:3)", &Item [1], 0, &Item [2], &CNT);
        
         &oCollJob.KEYPROP_EFFSEQ = &CNT;
         &oCollJob.PROP_ACTION = &Item [3];
        
         If Not None(&Item [4]) Then
            &oCollJob.PROP_ACTION_REASON = &Item [4];
         End-If;
        
         rem ***** Set COLL_COMPENSATION Collection Field Properties -- Parent: COLL_JOB Collection *****;
         If &Item.Len >= 5 Then
            If Not None(&Item [5]) Then
               &oCollCompensationCollection = &oCollJob.COLL_COMPENSATION;
               &oCollCompensation = &oCollCompensationCollection.Item(1);
               REM &oCollCompensation.KEYPROP_COMP_RATECD = "MONPAY";
               &oCollCompensation.PROP_COMPRATE = &Item [5];
              
               &oCollJob.PROP_CALC_COMP_BTN = "!";
            End-If;
         End-If;
        
         rem ***** Execute Save *****;
         If Not &oCiJobDataChange.Save() Then;
           
            REM Count as Fail;
            &FailCNT = &FailCNT + 1;
            &fileLog.WriteLine("Error! Can Not Save Employee When Process Line " | &Line | ", Employee " | &Item [1] | ".");
            errorHandler();
         Else
           
            REM Count as Success;
            &FailCNT = &FailCNT + 1;
            &fileLog.WriteLine("Success! Finish Process Line " | &Line | ", Employee " | &Item [1] | ".");
            errorHandler();
         End-If;
        
         rem ***** Execute Cancel *****;
         If Not &oCiJobDataChange.Cancel() Then;
            &fileLog.WriteLine("Error! Can Not Cancel Employee When Process Line " | &Line | ", Employee " | &Item [1] | ".");
            errorHandler();
         End-If;
        
      End-If;
     
   Else
      REM When Employee Status Is Not Active;
      &fileLog.WriteLine("Error! Can Process Inactive Employee When Process Line " | &Line | ", Employee " | &Item [1] | ".");
     
      REM Count as Fail;
      &FailCNT = &FailCNT + 1;
   End-If;
  
   CommitWork();
   CollectGarbage();
  
End-While;


&fileLog.WriteLine("End");
&fileLog.Close();

转载于:https://www.cnblogs.com/GoDevil/archive/2009/07/10/1520567.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值