Schedule Application Engine through Peoplecode
The following sample code can be used to Schedule App Engine through PeopleCode.
Code to Schedule App Engine thru PeopleCode:
Local ProcessRequest &MYRQST;
&MyAppName = "MY_APP";
&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;
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 */
&POSTED = 4 Then
&LOOP = 2
End-If;
If &STATUS = "No Success" Or
&STATUS = "Error" Then
&LOOP = 3;
End-If;
End-While;
If &LOOP = 1 Then
MessageBox(0, "", 27333, 594, ""); /* Success Msg */
Else
If &LOOP = 2 Or
&LOOP = 3 Then
MessageBox(0, "", 27333, 595, ""); /* Failed Error Msg */
End-If;
End-If; /* If &LOOP = 1 Then */
End-If;
The below function can also be used for schedule application engine: (Alternative Function)
Function ScheduleSetupAEProcess(&RESULT_SET_COMP)
&RUN_SETUP_AE_REQST = CreateProcessRequest("Application Engine", "PTLT_SETUP");
&REC_IMPL_RUN = CreateRecord(Record.PTLT_PROJ_RUN);
/* Run Control ID = Configuration Set Name */
&RUN_CNTL_ID = &RESULT_SET_COMP;
&RUN_SETUP_AE_REQST.RunControlID = &RUN_CNTL_ID;
&RUN_SETUP_AE_REQST.Schedule();
If &RUN_SETUP_AE_REQST.Status = 0 Then
&PROCESS_INSTANCE = &RUN_SETUP_AE_REQST.ProcessInstance;
/* Insert into Setup Manager Run Control Record */
&REC_IMPL_RUN.OPRID.Value = %OperatorId;
&REC_IMPL_RUN.RUN_CNTL_ID.Value = &RUN_CNTL_ID;
&REC_IMPL_RUN.PTLT_PROJ_NAME.Value = &RESULT_SET_COMP;
&REC_IMPL_RUN.PROCESSINSTANCE.Value = &PROCESS_INSTANCE;
If Not &REC_IMPL_RUN.Update() Then
&REC_IMPL_RUN.Insert();
End-If;
Else
Error MsgGet(218, 154, "Process cannot be scheduled");
End-If;
End-Function;
