Health Benefit Component Interface Peoplecode

How to write a Health Benefit Component Interface Peoplesoft Peoplecode.

The Following is the typical health benefit component interface peoplecode.
Local File &fileLog;
Local ApiObject &oSession, &oKzlHealthBenefits;
Local ApiObject &oBenefitParticCollection, &oBenefitPartic;
Local ApiObject &oHealthBenefitCollection, &oHealthBenefit;
Local ApiObject &oHealthDependntCollection, &oHealthDependnt;

Function errorHandler()
Local ApiObject &oPSMessageCollection, &oPSMessage;
Local number &i;
Local string &sErrMsgSetNum, &sErrMsgNum, &sErrMsgText, &sErrType;

&oPSMessageCollection = &oSession.PSMessages;
&Proc_Error = &Proc_Error + 1;
For &i = 1 To &oPSMessageCollection.Count
&oPSMessage = &oPSMessageCollection.Item(&i);
&sErrMsgSetNum = &oPSMessage.MessageSetNumber;
&sErrMsgNum = &oPSMessage.MessageNumber;
&sErrMsgText = &oPSMessage.Text;
SQLExec("SELECT KZL_ABN FROM PS_KZL_ABN_TBL WHERE EMPLID =:1", &Emplid, &Kzl_Abn);
&fileLog.WriteLine("*******************************************************************");
&fileLog.WriteLine("Address Book Number :" | &Kzl_Abn);
&fileLog.WriteLine("Emplid :" | &Emplid);
&fileLog.WriteLine(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText);
&fileLog.WriteLine("*******************************************************************");
End-For;
rem ***** Delete the Messages from the collection *****;
&oPSMessageCollection.DeleteAll();
End-Function;

&fileLog = GetFile("C:\temp\KZL_HEALTH_BENEFITS.log", "w", "a", %FilePath_Absolute);

&REC_HEALTH_BEN = CreateRecord(Record.KZL_HEALTH_BEN);
&SQL_HEALTH_BEN = CreateSQL("%SelectAll(:1) where STATUS_FLAG =:2", &REC_HEALTH_BEN, "S");

While &SQL_HEALTH_BEN.Fetch(&REC_HEALTH_BEN)
try
&Proc_Count = &Proc_Count + 1;
rem ***** Set the Log File *****;
rem &fileLog = GetFile("C:\temp\KZL_HEALTH_BENEFITS.log", "w", "a", %FilePath_Absolute);
&fileLog.WriteLine("Begin");
rem ***** Get current PeopleSoft Session *****;
&oSession = %Session;
&oSession.PSMessagesMode = 1;

rem ***** Get the Component Interface *****;
&oKzlHealthBenefits = &oSession.GetCompIntfc(CompIntfc.KZL_HEALTH_BENEFITS);
If &oKzlHealthBenefits = Null Then
errorHandler();
throw CreateException(0, 0, "GetCompIntfc failed");
End-If;

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

rem ***** Set Component Interface Get/Create Keys *****;
&Emplid = &REC_HEALTH_BEN.EMPLID.Value;
&oKzlHealthBenefits.EMPLID = &Emplid;
&oKzlHealthBenefits.EMPL_RCD = &REC_HEALTH_BEN.EMPL_RCD.Value;

rem ***** Execute Get *****;
If Not &oKzlHealthBenefits.Get() Then
rem ***** No rows exist for the specified keys.*****;
errorHandler();
throw CreateException(0, 0, "Get failed");
End-If;
&PlanType = &REC_HEALTH_BEN.PLAN_TYPE.VALUE;
&fileLog.WriteLine("&PlanType =" | &PlanType);

&oBenefitParticCollection = &oKzlHealthBenefits.BENEFIT_PARTIC;
&oBenefitPartic = &oBenefitParticCollection.ItemByKeys(&PlanType);
&fileLog.WriteLine("In Ben Partic");
If &oBenefitPartic <> Null Then
Else
&oBenefitPartic = &oBenefitParticCollection.Item(1);


If All(&oBenefitPartic.PLAN_TYPE) Then
&oBenefitPartic = &oBenefitParticCollection.InsertItem(1);
End-If;
&oBenefitPartic.PLAN_TYPE = &PlanType;
End-If;
rem ***** Set HEALTH_BENEFIT Collection Field Properties -- Parent: BENEFIT_PARTIC Collection *****;
&Effdt = &REC_HEALTH_BEN.EFFDT.Value;
&fileLog.WriteLine(" &Effdt = " | &Effdt);
&oHealthBenefitCollection = &oBenefitPartic.HEALTH_BENEFIT;
&oHealthBenefit = &oHealthBenefitCollection.ItemByKeys(&Effdt);
&fileLog.WriteLine("In Health Ben");
If &oHealthBenefit <> Null Then
&oHealthBenefit = &oHealthBenefitCollection.Item(1);
Else
&oHealthBenefit = &oHealthBenefitCollection.Item(1);
If All(&oHealthBenefit.EFFDT) Then
&oHealthBenefit = &oHealthBenefitCollection.InsertItem(1);

End-If;
&oHealthBenefit.EFFDT = &Effdt;
End-If;
&Covrg_Cd = &REC_HEALTH_BEN.COVRG_CD.Value;
rem &Effdt = &REC_HEALTH_BEN.EFFDT.Value;
&Health_Provider_Id = &REC_HEALTH_BEN.HLTH_PROVIDER_ID.Value;
&Previously_Seen = &REC_HEALTH_BEN.PREVIOUSLY_SEEN.Value;
&Oth_Insurance_Ind = &REC_HEALTH_BEN.OTH_INSURANCE_IND.Value;
&Oth_Insurance_Name = &REC_HEALTH_BEN.OTH_INSURANCE_NAME.Value;
REM &oHealthBenefit.EFFDT = &Effdt;
&oHealthBenefit.COVERAGE_BEGIN_DT = &REC_HEALTH_BEN.COVERAGE_BEGIN_DT.Value;
&oHealthBenefit.COVERAGE_ELECT = &REC_HEALTH_BEN.COVERAGE_ELECT.Value;
&oHealthBenefit.COVERAGE_ELECT_DT = &REC_HEALTH_BEN.COVERAGE_ELECT_DT.Value;
&oHealthBenefit.BENEFIT_PLAN = &REC_HEALTH_BEN.BENEFIT_PLAN.Value;
&oHealthBenefit.COVRG_CD = &Covrg_Cd;
&oHealthBenefit.MED_PREM_PRETAX = &REC_HEALTH_BEN.MED_PREM_PRETAX.Value;
&oHealthBenefit.HLTH_PROVIDER_ID = &Health_Provider_Id;
&oHealthBenefit.PREVIOUSLY_SEEN = &Previously_Seen;
&oHealthBenefit.OTH_INSURANCE_IND = &Oth_Insurance_Ind;
&oHealthBenefit.OTH_INSURANCE_NAME = &Oth_Insurance_Name;
&oHealthBenefit.COBRA_EVENT_ID = &REC_HEALTH_BEN.COBRA_EVENT_ID.value;
rem ***** Set HEALTH_DEPENDNT Collection Field Properties -- Parent: HEALTH_BENEFIT Collection *****;

Evaluate &Covrg_Cd
When 2
&oHealthDependntCollection = &oHealthBenefit.HEALTH_DEPENDNT;
SQLExec("SELECT DEPENDENT_BENEF FROM PS_DEPENDENT_BENEF WHERE EMPLID =:1 AND RELATIONSHIP='SP'", &Emplid, &Dependent_Benef);
&oHealthDependnt = &oHealthDependntCollection.ItemByKeys(&Dependent_Benef);
If &oHealthDependnt <> Null Then
Else
&oHealthDependnt = &oHealthDependntCollection.Item(1);
If All(&oHealthDependnt.DEPENDENT_BENEF) Then
&oHealthDependnt = &oHealthDependntCollection.InsertItem(1);
End-If;
&oHealthDependnt.DEPENDENT_BENEF = &Dependent_Benef;
&oHealthDependnt.HLTH_PROVIDER_ID_1 = &Health_Provider_Id;
&oHealthDependnt.PREVIOUSLY_SEEN_1 = &Previously_Seen;
&oHealthDependnt.OTH_INSURANCE_IND_1 = &Oth_Insurance_Ind;
&oHealthDependnt.OTH_INSURANCE_NAME_1 = &Oth_Insurance_Name;
End-If;
Break;

When = 3
&oHealthDependntCollection = &oHealthBenefit.HEALTH_DEPENDNT;
rem &oHealthDependnt = &oHealthDependntCollection.Item(1);
SQLExec("SELECT DEPENDENT_BENEF FROM PS_DEPENDENT_BENEF WHERE EMPLID =:1 AND RELATIONSHIP='C'", &Emplid, &Dependent_Benef);
&oHealthDependnt = &oHealthDependntCollection.ItemByKey(&Dependent_Benef);
If &oHealthDependnt <> Null Then
Else
&oHealthDependnt = &oHealthDependntCollection.Item(1);
If All(&oHealthDependnt.DEPENDENT_BENEF) Then
&oHealthDependnt = &oHealthDependntCollection.InsertItem(1);
End-If;
&oHealthDependnt.DEPENDENT_BENEF = &Dependent_Benef;
&oHealthDependnt.HLTH_PROVIDER_ID_1 = &Health_Provider_Id;
&oHealthDependnt.PREVIOUSLY_SEEN_1 = &Previously_Seen;
&oHealthDependnt.OTH_INSURANCE_IND_1 = &Oth_Insurance_Ind;
&oHealthDependnt.OTH_INSURANCE_NAME_1 = &Oth_Insurance_Name;
End-If;
Break;
When 4
&oHealthDependntCollection = &oHealthBenefit.HEALTH_DEPENDNT;

rem &oHealthDependnt = &oHealthDependntCollection.Item(1);
SQLExec("SELECT DEPENDENT_BENEF FROM PS_DEPENDENT_BENEF WHERE EMPLID =:1 AND RELATIONSHIP='SP'", &Emplid, &Dependent_Benef);
&oHealthDependnt = &oHealthDependntCollection.ItemByKey(&Dependent_Benef);
If &oHealthDependnt <> Null Then
Else
&oHealthDependnt = &oHealthDependntCollection.Item(1);
If All(&oHealthDependnt.DEPENDENT_BENEF) Then
&oHealthDependnt = &oHealthDependntCollection.InsertItem(1);
End-If;
&oHealthDependnt.DEPENDENT_BENEF = &Dependent_Benef;
&oHealthDependnt.HLTH_PROVIDER_ID_1 = &Health_Provider_Id;
&oHealthDependnt.PREVIOUSLY_SEEN_1 = &Previously_Seen;
&oHealthDependnt.OTH_INSURANCE_IND_1 = &Oth_Insurance_Ind;
&oHealthDependnt.OTH_INSURANCE_NAME_1 = &Oth_Insurance_Name;
End-If;

rem &oHealthDependnt = &oHealthDependntCollection.InsertItem(1);
SQLExec("SELECT DEPENDENT_BENEF FROM PS_DEPENDENT_BENEF WHERE EMPLID =:1 AND RELATIONSHIP='C'", &Emplid, &Dependent_Benef);
&oHealthDependnt = &oHealthDependntCollection.ItemByKey(&Dependent_Benef);
If &oHealthDependnt <> Null Then
Else
&oHealthDependnt = &oHealthDependntCollection.Item(1);
If All(&oHealthDependnt.DEPENDENT_BENEF) Then
&oHealthDependnt = &oHealthDependntCollection.InsertItem(1);
End-If;
&oHealthDependnt.DEPENDENT_BENEF = &Dependent_Benef;
&oHealthDependnt.HLTH_PROVIDER_ID_1 = &Health_Provider_Id;
&oHealthDependnt.PREVIOUSLY_SEEN_1 = &Previously_Seen;
&oHealthDependnt.OTH_INSURANCE_IND_1 = &Oth_Insurance_Ind;
&oHealthDependnt.OTH_INSURANCE_NAME_1 = &Oth_Insurance_Name;
End-If;
Break;
When-Other
Break;
End-Evaluate;


rem ***** Clear all Fields *****;
&Dependent_Benef = " ";
&Health_Provider_Id = " ";
&Covrg_Cd = " ";
&Effdt = " ";
&Previously_Seen = " ";
&Oth_Insurance_Ind = " ";
&Oth_Insurance_Name = " ";
rem ***** End: Get/Set Component Interface Properties *****;
rem ***** Execute Save *****;
If Not &oKzlHealthBenefits.Save() Then;
errorHandler();
throw CreateException(0, 0, "Save failed");
End-If;

rem ***** Execute Cancel *****;
If Not &oKzlHealthBenefits.Cancel() Then;
errorHandler();
throw CreateException(0, 0, "Cancel failed");
End-If;

catch Exception &ex
rem Handle the exception;
&fileLog.WriteLine(&ex.ToString());
end-try;
End-While;
&Proc_Success = &Proc_Count - &Proc_Error;
&fileLog.WriteLine("*******************************************************************");
&fileLog.WriteLine("Number of Prcessed Rows:" | &Proc_Count);
&fileLog.WriteLine("Number of Successful Rows :" | &Proc_Success);
&fileLog.WriteLine("Number of Errorful Rows :" | &Proc_Error);
&fileLog.WriteLine("*******************************************************************");
&fileLog.WriteLine("End");
&fileLog.Close();



Share/Bookmark