Sie sind auf Seite 1von 34

Using PeopleSoft File Layout

( (Third Party Administrator File Generation) y )

Judi Doolittle, OCP, Oracle ACE Natasha Garcia Sandia National L b S di N i l Laboratories i

What we will cover


Writing Data to a Flat File Methods to Read and Write (Plain Text Files) Writing Files (Defined by a File Layout) Creating an App Engine (to Export Data to Flat File) Creating Multilevel File Layout PeopleCode for Multilevel File Layout Segments in File Layout

Writing Data to a Flat File


File Class Methods
ReadLine (string) W it Li ( t i ) WriteLine (string) WriteString (string)

PeopleCode Example
Local string &string; Local File &Myfile, &Myfile2; &MyFile = GetFile( test.txt , R); GetFile(test txt R ); &MyFile2 = GetFile(c:\temp\test2.txt, W, %FilePath_Absolute); If &M Fil I O &MyFile.IsOpen Then Th While &Myfile.ReadLine(&string); &MyFile2.WriteLine(&string); End-While; E d Whil End-If; &MyFile.Close(); &M Fil Cl () &MyFile2.Close();
N

PeopleCode Example
Local X lD &i L l XmlDoc &inxmldoc ld /* load message to file */ &xmlfile = GetFile("IB MSG TEMP xml" "W"); GetFile("IB_MSG_TEMP.xml", If &xmlfile.IsOpen Then &xmlstring = &inxmldoc GenFormattedXmlString(); &inxmldoc.GenFormattedXmlString(); &xmlfile.WriteString(&xmlstring); &xmlfile.Close(); End-If;

Methods to Read and Write (Plain Text Files)


WriteRecord- writes the contents of a record object to the file. You can use this to write one file record at a time and not have to instantiate and populate a rowset object. WriteRowset- writes the contents of a rowset object, rowset, object rowset to the output file associated with the file object that calls the method. Calling this method one time writes the entire g contents of the rowset to the file.
N

CreateRowset
Local Rowset &rs_carry_desig; &rs_carry_desig = CreateRowset(Record.AV_DESIGNATION);

CreateSQL Function
I t ti t a SQL object from the SQL classthen it Instantiates bj t f th l th opens it on the sqlstring and/or input values. The sqlstring is the parameter that holds the SQL statement SQL errors will cause PeopleCode to terminate with an error MetaSQL
%SelectAll is a way to select everything in a record Tip: Remember to wrap DateTime fields with %DateOut, %TimeOut, %DateIn, and %TimeIn

PeopleCode Example
Local R L l Record & 1 d &rec1; Local SQL &SQL; /*Create Instance of Record */ &rec1 = CreateRecord(record tc help me tbl); CreateRecord(record.tc_help_me_tbl); / Create /*Create SQL object to populate rowset */ / &SQL = CreateSQL(%selectall(:1), &rec1);

Writing Files using File Layout


Local File &M File &MyFile; Local Record &rec1; Local SQL &SQL1; /*Create Instance of Record */ &rec1 = CreateRecord(record.tc_help_me_tbl); &MyFile = GetFile(c:\temp\help me.txt, A, %FilePath_Absolute); y ( p p_ , , ); &MyFile.setFileLayout(FileLayout.help_me); /*Create SQL object to populate rowset */ &SQL1 = CreateSQL(%selectall(:1), &rec1); CreateSQL( %selectall(:1) While &SQL1.Fetch(&rec1) &MyFile.WriteRecord(&rec1); End-While; &MyFile.Close();
N

Creating an App Engine (to Export Data to Flat File)


Steps
Application Designer, File, New, Application Engine Program Select Insert, Action Save the Program Change the Action type to PeopleCode Enter Code Save Run

Steps for Creating a Multilevel File Layout


1. 1 2. 3. 3 4. 5. 6. 7. 7 8. 9. 10. Create View C t a Vi Create a new file layout Drop and drag the view into the layout Use the toolbar arrows to determine hierarchy Double-click the record name to set segment properties Assign a unique file record ID to each record Note: start position and length are set automatically Click OK Click Yes to increment the start position of all fields Save the File
J

Easiest Way to do File Layout Layout Match to View


Record SL_BEN_COBC_VW

File Layout one to one to View

File Record ID
Identifies the record Can be used with fixed and CSV files ID must be included in your flat file Assigned at the file layout segment level

COBRA TPA (Thi d P t (Third Party Administrator) File Layout Example

Creating Rowsets and File


/ Create /***Create Rowset Instance / Instance***/ &sl_rowset = CreateRowset(Record.SL_BEN_COBC_VW); &sl_rowset2 = &sl_rowset.GetRow(1).GetRowset(1); /***Create File Instance***/ If &whereto = "local" Then &path = "c:\temp\"; Else /* Get Unix path for files */
SQLExec("Select sl_charval from sl_pr_parm_tbl where sl_keyval = 'PATH-PROD-UNIX'", &path);

End-If; /* Filename */ &filename = &curdate | "_CB_PAR_" | &clientid | ".txt"; /** Create an instance of the File - this will be opened in Write mode with an absolute path. Then associate it with the appropriate File Layout */ &COBRAFile GetFile(&path &filename, "W" %Fil P th Ab l t ) &COBRAFil = G tFil (& th | &fil "W", %FilePath_Absolute); /*********** Filelayout ************************************/ &COBRAFile.SetFileLayout(FileLayout.SL_COB_PAR);

SQL Statements
/* Create SQL object to retrieve values */ &SQL1 = CreateSQL("%selectall(:1)", &recl); &SQL2 = CreateSQL("%selectall(:1)", &rec2); &SQL3 = CreateSQL("%selectall(:1)", &rec3);

Looping the Level One Record


/ /* Loop through the rowset to get the values and write the rowset to file */ / While &SQL_HDR.Fetch(&recl) /*copy record to rowset */ &recl.CopyFieldsTo(&rowset1.GetRow(1).SL_BEN_COB_HDR); /* Write rowset to file */ &COBRAFile.WriteRowset(&rowset1); &COBRAFil W it R t(& t1) End-While; /* Fetch data from SL_BEN_COBP_VW */ While &SQL_PAR.Fetch(&rec2) &I = 1; /* Copy record to the rowset */ &rec2.CopyFieldsTo(&rowset2.GetRow(&I).SL_BEN_COBP_VW); &rowset2.InsertRow(&I); &COBRAFile.WriteRowset(&rowset2); &I = &I + 1; End-While; While &SQL_TRL.Fetch(&rec3) /*copy record to rowset */ &rec3.CopyFieldsTo(&rowset3.GetRow(1).SL_BEN_COB_TRL); /* Write rowset to file */ &COBRAFile.WriteRowset(&rowset3); End-While;

Segments
Uses:
Specify the action to take for rows of data Li it fields on th fil l Limit fi ld the file layout t Identify File Layout

Indicate Action
You need to send a flat file to another app
Indicate Action
Insert Update Delete

Use Segment to indicate the action

Limit Fields
Following provided from: PeopleSoft Integration Tools and Utilities, File Layout and Data Interchange section You have a file and you only want two fields from it One way is to update everything and then manually delete the unwanted data Or insert a segment name it the same as the table and insert only the two fields you want

Limit Fields Cont.


You have data that changes or you need to insert new rows C t a single fi ld named AUDIT ACTION Create i l field d AUDIT_ACTION which will indicate if the record is new or changed Use PeopleCode to look for the field and value and process conditional logic

Identifying the File Layout


Use a segment to identify the part of the file you want to import 999 P d t /* Product /*use PRODUCT layout*/ l t*/

Steps to work with a Segment


Drag and d D d drop your record i t th fil l d into the file layout t Select Insert Segment Record Name, Max Length, & File Record ID (if you have one) ) Place your cursor on the Segment Name Select
Insert File Field or Insert Database Field

Then arrange the Segments in the order you want

Stepping Through Inserting a Segment

Creating a Child Segment


Insert a Child Segmenthighlight record, select Insert, ChildSegment, and enter file record name

Putting it all together (real world example)

What we covered
Writing Data to a Flat File Methods to Read and Write (Plain Text Files) Writing Files (Defined by a File Layout) Creating an App Engine (to Export Data to Flat File) Creating Multilevel File Layout PeopleCode for Multilevel File Layout Segments in File Layout

Book Signing
Time: 11:45 am to 12:45 pm Location: Bookstore

Download Presentation
http://www.oraclepressbooks.com/downloads/

Questions
jhotsin@sandia.gov Judi_doolittle@ioug.org nygarci@sandia.gov