You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

Inserting data for parent and child records through component interface from external file

2 replies [Last post]
Guest's picture
Guest

Hi , Can any one help me on this issue Read the data using Filelayout(fixed) and inserted through the component interface.
Thanks in Advance,
Sou

Guest's picture
Guest
Re: Inserting data for parent and child records through ...

Hi,

Can u please mention the issue clearly..

Guest's picture
Guest
Re: Inserting data for parent and child records through ...

Hi,

I got issue while inserting data for parent and child records from external file(fixed) through component interface.

Here is my code below:

/* ===>
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, &oSouOrdCi;
Local ApiObject &oSouOrdLnTblCollection, &oSouOrdLnTbl;
Local ApiObject &SOU_ORD_LN_TBLItm;

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 *****************************************************************;
rem * PeopleCode to Import Data *;
rem *****************************************************************;
Local File &FILE1;
Local Record &REC1;
Local Rowset &RS1, &RS2;

&FILE1 = GetFile("C:\temp\SOU_ORD_DETAILS.txt", "R", %FilePath_Absolute);
&LOGFILE = GetFile("C:\temp\SOU_ORD_DETAILS.txt.err", "W", %FilePath_Absolute);
&FILE1.SetFileLayout(FileLayout.SOU_OR_FL);
&LOGFILE.SetFileLayout(FileLayout.SOU_OR_FL);
&RS1 = &FILE1.CreateRowset();
&RS2 = CreateRowset(Record.SOU_ORD_HDR_TBL, CreateRowset(Record.SOU_ORD_LN_TBL));

While &RS1 <> Null
&RS1 = &FILE1.ReadRowset();
&RS2 = &RS1(1).GetRowset(Scroll.SOU_ORD_LN_TBL);
If &RS2.ActiveRowCount > 1 Then

try
rem ***** Set the Log File *****;
&fileLog = GetFile("C:\Temp\SOU_ORD_CI.log", "W", %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 = 3;

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

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

rem ***** Set Component Interface Get/Create Keys *****;
&oSouOrdCi.SOU_ORDER_ID_FLD = &RS1(1).SOU_ORD_HDR_TBL.SOU_ORDER_ID_FLD.Value;

rem ***** Execute Get *****;
REM If Not &oSouOrdCi.Get() Then
rem ***** No rows exist for the specified keys.*****;
REM errorHandler();
REM throw CreateException(0, 0, "Get failed");
REM End-If;

rem ***** Execute Create ******;
If Not &oSouOrdCi.Create() Then;
rem ***** Unable to Create Component Interface for the Add keys provided. *****;
errorHandler();
throw CreateException(0, 0, "Create failed");

rem ***** Begin: Get/Set Component Interface Properties *****;
rem ***** Get/Set Level 0 Field Properties *****;
rem &fileLog.WriteLine("&oSouOrdCi.SOU_CUSTOMERID_FLD = " | &oSouOrdCi.SOU_CUSTOMERID_FLD);
&oSouOrdCi.SOU_CUSTOMERID_FLD = &RS1(1).SOU_ORD_HDR_TBL.SOU_CUSTOMERID_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdCi.SOU_PREFERED_2 = " | &oSouOrdCi.SOU_PREFERED_2);
&oSouOrdCi.SOU_PREFERED = &RS1(1).SOU_ORD_HDR_TBL.SOU_PREFERED.Value;
REM &fileLog.WriteLine("&oSouOrdCi.SOU_ORDER_DATE_FLD = " | &oSouOrdCi.SOU_ORDER_DATE_FLD);
&oSouOrdCi.SOU_ORDER_DATE_FLD = &RS1(1).SOU_ORD_HDR_TBL.SOU_ORDER_DATE_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdCi.SOU_EMPID = " | &oSouOrdCi.SOU_EMPID);
&oSouOrdCi.SOU_EMPID = &RS1(1).SOU_ORD_HDR_TBL.SOU_EMPID.Value;
REM &fileLog.WriteLine("&oSouOrdCi.SOU_ORDER_STATUS = " | &oSouOrdCi.SOU_ORDER_STATUS);
&oSouOrdCi.SOU_ORDER_STATUS = &RS1(1).SOU_ORD_HDR_TBL.SOU_ORDER_STATUS.Value;
REM &fileLog.WriteLine("&oSouOrdCi.SOU_ORDERFILL_FLD = " | &oSouOrdCi.SOU_ORDERFILL_FLD);
&oSouOrdCi.SOU_ORDERFILL_FLD = &RS1(1).SOU_ORD_HDR_TBL.SOU_ORDERFILL_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdCi.SOU_ORDCOMP_FLD = " | &oSouOrdCi.SOU_ORDCOMP_FLD);
&oSouOrdCi.SOU_ORDCOMP_FLD = &RS1(1).SOU_ORD_HDR_TBL.SOU_ORDCOMP_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdCi.SOU_SHIPDATE_FLD = " | &oSouOrdCi.SOU_SHIPDATE_FLD);
&oSouOrdCi.SOU_SHIPDATE_FLD = &RS1(1).SOU_ORD_HDR_TBL.SOU_SHIPDATE_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdCi.SOU_GRANDTOT_FLD = " | &oSouOrdCi.SOU_GRANDTOT_FLD);
&oSouOrdCi.SOU_GRANDTOT_FLD = &RS1(1).SOU_ORD_HDR_TBL.SOU_GRANDTOT_FLD.Value;

rem ***** Set/Get SOU_ORD_LN_TBL Collection Field Properties -- Parent: PS_ROOT Collection *****;
&oSouOrdLnTblCollection = &oSouOrdCi.SOU_ORD_LN_TBL;
Local integer &i114;
rem If &RS2.ActiveRowCount > 1 Then;
For &i114 = 1 To &oSouOrdLnTblCollection.Count;
rem &SOU_ORD_LN_TBLItm = &oSouOrdLnTblCollection.InsertItem(&oSouOrdLnTblCollection.CurrentItemNum());
&oSouOrdLnTbl = &oSouOrdLnTblCollection.Item(&i114);
REM &fileLog.WriteLine("&oSouOrdLnTbl.SOU_LINE_FLD = " | &oSouOrdLnTbl.SOU_LINE_FLD);
&oSouOrdLnTbl.SOU_LINE_FLD = &RS2(1).SOU_ORD_LN_TBL.SOU_LINE_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdLnTbl.SOU_ITEMID_FLD = " | &oSouOrdLnTbl.SOU_ITEMID_FLD);
&oSouOrdLnTbl.SOU_ITEMID_FLD = &RS2(1).SOU_ORD_LN_TBL.SOU_ITEMID_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdLnTbl.SOU_DISCOUNT_FLD = " | &oSouOrdLnTbl.SOU_DISCOUNT_FLD);
&oSouOrdLnTbl.SOU_DISCOUNT_FLD = &RS2(1).SOU_ORD_LN_TBL.SOU_DISCOUNT_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdLnTbl.SOU_ITMTOTAL_FLD = " | &oSouOrdLnTbl.SOU_ITMTOTAL_FLD);
&oSouOrdLnTbl.SOU_ITMTOTAL_FLD = &RS2(1).SOU_ORD_LN_TBL.SOU_ITMTOTAL_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdLnTbl.SOU_UNITPRICE_FLD = " | &oSouOrdLnTbl.SOU_UNITPRICE_FLD);
&oSouOrdLnTbl.SOU_UNITPRICE_FLD = &RS2(1).SOU_ORD_LN_TBL.SOU_UNITPRICE_FLD.Value;
REM &fileLog.WriteLine("&oSouOrdLnTbl.SOU_QUANTITY_FLD = " | &oSouOrdLnTbl.SOU_QUANTITY_FLD);
&oSouOrdLnTbl.SOU_QUANTITY_FLD = &RS2(1).SOU_ORD_LN_TBL.SOU_QUANTITY_FLD.Value;
End-For;
End-If;
rem end-for;

rem ***** End: Get/Set Component Interface Properties *****;

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

rem ***** Execute Cancel *****;
rem If Not &oSouOrdCi.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;

&FILE1.Close();
&LOGFILE.Close();
End-If;
End-While;

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

Thanks.

Post new comment

CAPTCHA
The question below is to prevent automated spam submissions.
7 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.