Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

FILE LAYOUT

PeopleTools supports reading and writing to plain text files, and to files that have a format based
on a File Layout that has been created in PeopleSoft Application Designer.
 If the file is a plain text file, data is read or written using text strings.
 If the file is based on a File Layout, you can use text strings, rowset, or record objects.
This simplifies reading, writing, and manipulating hierarchical transaction data with PeopleCode.
Here the following work is done on single record and multiple records.
First we discuss on single flat file modal for this the following definitions were created.
Following steps are required to perform data transfer between flat file to single record and vice-
versa
Create a table with 3 fields like deptid, emplid and salary as shown below

Create a file layout definition.


Drag the record definition on to the file lay out definition.

Click on Preview tab of file layout and select the record name at segment name and set the
default file name.
4.Click on AE button and save the AE Program. The People code will be automatically
generated as given below.

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_Required + %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;
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
&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;

&FILE1 = GetFile("C:\Documents and Settings\Administrator\Desktop\


SINGLE_READ.txt", "r", "a", %FilePath_Absolute);
&LOGFILE = GetFile("C:\Documents and Settings\Administrator\Desktop\
SINGLE_READ.txt.err", "W", %FilePath_Absolute);
&FILE1.SetFileLayout(FileLayout.JOLT_SREC_READ);
&LOGFILE.SetFileLayout(FileLayout.JOLT_SREC_READ);
&RS1 = &FILE1.CreateRowset();
&RS = CreateRowset(Record.JOLT_EMPL);
&SQL1 = CreateSQL("%Insert(:1)");
&RS1 = &FILE1.ReadRowset();
While &RS1 <> Null;
ImportSegment(&RS1, &RS);
&RS1 = &FILE1.ReadRowset();
End-While;

&FILE1.Close();
&LOGFILE.Close();
By directly running the AE Program the information can be uploaded to the record
from flat file.
To write a flat file with data from a record create another filelayout definition and AE
Program with the code as given below

THE Flat-file may be of three types


1. Comma separated file
2. fixed length file
3. XML file
These types should be mention in the properties tab of the filelayout definition
The structure of flat files for fixed format and comma separated are as below
For multiple records , assume two records having parent child relation ship, create two more
filelayout definitions for reading and writing flat file.
Here In our example two records were created with fields
JOLT_DEPT (DEPTID,MANAGER_ID,LOCATION) -------- PARENT
JOLT_EMPL (DEPTID,EMPLID,TOTAL_SALARY) ----------CHILD
While reading data from flat-file the rows will be identified by the starting character of every line
and that value should be set in the file lay out segment properties.In our example the starting
number ‘1’ in the flat-file represents the parent record and ‘2’ represents the child record.
The file record ID field of filelayout segment properties should be set either 1 or 2
depending on the record whether a parent record or child record.
To write data from record to the flat-file the following code is written on a separate
AE Program.

To read data from flat file and upload to the data base the following code is written
on a separate AE Program as below.

This can be directly checked from the Query Analyzer


The file record ID field of filelayout segment properties should be set either 1 or 2
depending on the record whether a parent record or child record.
Double click on encircled area to get the file layout segment properties and the value
is set to 1 if it is dept record and set to 2 for the empl(child) record.

You might also like