PeopleSoft – PeopleCode for reading the file using the rowset and file layout objects, the file being read contains the header and lines & this combination repeats.
Function EditRecord(&REC As Record) Returns boolean;
Local integer &E;
REM &REC.ExecuteEdits(%Edit_Required + %Edit_DateRange + %Edit_YesNo + %Edit_TranslateTable + %Edit_PromptTable + %Edit_OneZero);
&REC.ExecuteEdits(%Edit_DateRange + %Edit_YesNo + %Edit_OneZero);
If &REC.IsEditError Then
For &E = 1 To &REC.FieldCount
&MYFIELD = &REC.GetField(&E);
If &MYFIELD.EditError Then
&MSGNUM = &MYFIELD.MessageNumber;
&MSGSET = &MYFIELD.MessageSetNumber;
&LOGFILE.WriteLine("****Record:" | &REC.Name | ", Field:" | &MYFIELD.Name);
&LOGFILE.WriteLine("****" | MsgGet(&MSGSET, &MSGNUM, ""));
End-If;
End-For;
MessageBox(0, "", 0, 0, "Error(s) found in file " | &FileNameForReading | " is being read");
&FileTemp = CreateRecord(Record.Z_AR_FILE_TMP);
&FileTemp.PROCESS_INSTANCE.VALUE = Z_AR_ALNCE_AET.PROCESS_INSTANCE.Value;
&FileTemp.FILE_SEQ.VALUE = Z_AR_FILE_TMP.FILE_SEQ.Value;
&FileTemp.ARCHIVE_PROCESS.VALUE = "D"; /*if errors found in file then do not archive this file*/
&FileTemp.update();
Return False;
Else
Return True;
End-If;
End-Function;
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
Local Rowset &RS1, &RSP;
Local string &RecordName;
Local Record &REC2, &RECP;
Local SQL &SQL1;
Local integer &I, &L;
&SQL1 = CreateSQL("%Insert(:1)");
&RecordName = "RECORD." | &RS2.DBRecordName;
&REC2 = CreateRecord(@(&RecordName));
&RECP = &RSParent(1).GetRecord(@(&RecordName));
For &I = 1 To &RS2.ActiveRowCount
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
If (EditRecord(&REC2)) Then
&REC2.PROCESS_INSTANCE.Value = Z_AR_ALNCE_AET.PROCESS_INSTANCE.Value;
&REC2.FILE_SEQ.Value = Z_AR_ALNCE_AET.FILE_SEQ.Value;
&REC2.Z_AR_STATUS.Value = "P";
If &REC2.Name = "Z_AR_GCTL_TMP" Then
&REC2.OPRID.Value = %OperatorId;
&REC2.ASSN_OPRID.Value = %OperatorId;
MessageBox(0, "", 0, 0, "ORIGIN-EEE" | &REC2.ORIGIN_ID.Value | "EEE");
End-If;
&SQL1.Execute(&REC2);
&RS2(&I).GetRecord(1).CopyFieldsTo(&RECP);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&RSP = &RSParent.GetRow(1).GetRowset(&L);
ImportSegment(&RS1, &RSP);
End-If;
End-For;
If &RSParent.ActiveRowCount > 0 Then
&RSParent.DeleteRow(1);
End-If;
Else
&LOGFILE.WriteRowset(&RS);
&LOGFILE.WriteLine("****Correct error in this record and delete all error messages");
&LOGFILE.WriteRecord(&REC2);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&LOGFILE.WriteRowset(&RS1);
End-If;
End-For;
End-If;
End-For;
End-Function;
rem *****************************************************************;
rem * PeopleCode to Import Data *;
rem *****************************************************************;
Local File &FILE1;
Local Record &REC1;
Local SQL &SQL1;
Local Rowset &RS1, &RS2;
Local integer &M;
SQLExec("SELECT DESCR254 FROM PS_Z_AR_FILE_TMP WHERE PROCESS_INSTANCE = :1 AND FILE_SEQ = :2", Z_AR_ALNCE_AET.PROCESS_INSTANCE.Value, Z_AR_ALNCE_AET.FILE_SEQ.Value, &FileNameForReading);
MessageBox(0, "", 0, 0, &FileNameForReading | " is being read");
&FILE1 = GetFile(&FileNameForReading, "r", "a", %FilePath_Absolute);
&LOGFILE = GetFile(&FileNameForReading | ".err", "W", %FilePath_Absolute);
&FILE1.SetFileLayout(FileLayout.Z_AR_ALLN_FLO);
&LOGFILE.SetFileLayout(FileLayout.Z_AR_ALLN_FLO);
&RS1 = &FILE1.CreateRowset();
&RS = CreateRowset(Record.Z_AR_GCTL_TMP, CreateRowset(Record.Z_AR_PITM_TMP));
&SQL1 = CreateSQL("%Insert(:1)");
&RS1 = &FILE1.ReadRowset();
While &RS1 <> Null;
ImportSegment(&RS1, &RS);
&RS1 = &FILE1.ReadRowset();
rem MessageBox(0, "", 0, 0, "File contains " | &RS1.RowCount | " lines to be proccessed");
End-While;
&FILE1.Close();
&LOGFILE.Close();
2 comments:
Hi, thank you for the file layout example. I have created an AE program to load csv file using the generated code from PeopleSoft. The issue I am having is if the first line of the input file contains a header information, the program fails. I wan unable to locate the logic in your example to check for/ignore the first line. I hope you can help me with code sample.
Thank you,
Add a counter like below, the header will be ignored
&LineCount = 0;
While &RS1 <> Null;
&LineCount = &LineCount + 1;
If &LineCount > 1 Then
ImportSegment(&RS1, &RS);
End-If;
&RS1 = &FILE1.ReadRowset();
End-While;
Post a Comment