Jan 20, 2013

PeopleSoft : App Engine: XML Export File using File Layout


Creating a File Layout.
  1. Create or Select a Record for your data.  I used a view, to avoid having to deal with joins in PeopleCode.
  2. Create a File Layout Definition.
  3. Create an Application Engine Program, with a tiny bit of code in it.
  4. Stuff all these things into a project so you can maintain your sanity at a later time.
After you have selected the record with the data you want to export, create a new File Layout Definition (File->New Definition->File Layout).


On the definition tab, right click “NEW FILE” and select Insert Record.  Search for the record you are using for your data, and double click it.  The Record Definition, and its columns will show up under “NEW FILE” now.  Save your File Layout Definition.

Click the Property Icon , then click the “Use” tab, and select XML in the “File Layout Format” drop down. Click OK.

Create a new Application Engine Program (File->New->Application Engine Program).  Right click “Step01″ and select “Insert Action”.  Click where it says “SQL”, and select “PeopleCode” from the drop down.

Double click the new action to edit the PeopleCode.  Copy and paste this PeopleCode into the window:
Local Record &Rec;
Local File &File;
Local SQL &SQL;


&File = GetFile("c:\temp\export_sample.xml", "W", %FilePath_Absolute);
If &File.IsOpen Then
If &File.SetFileLayout(FileLayout.YOUR_FILE_LAYOUT_DEFINITION) Then
&Rec = CreateRecord(Record.YOUR_RECORD_DEFINITION);
&SQL = CreateSQL("%Selectall(:1)", &Rec);
While &SQL.Fetch(&Rec)
&File.WriteRecord(&Rec);
&File.WriteLine("</YOUR_RECORD_DEFINITION>");
End-While;
Else
Error ("File Layout Not Correct");
End-If;
Else
Error ("file not open");
End-If;
&File.Close();

No comments:

Post a Comment