Sei sulla pagina 1di 2

Example ...

I created a view called "BT_TEST_HDR" that pulls from 4 fields (EMPLID, EMPL_RCD
, EFFDT, NAME) from PS_EMPLOYEES.
I created a view called "BT_TEST_DTL" that pulls 4 fields (EMPLID, EMPL_RCD, COM
P_RATECD, COMPRATE) from PS_COMPENSATION
for the current effdt/effseq. Some of our employees have multiple comp rates (NA
HRLY, NAHRLY2, NAHRLY3, etc.) based on
shifts they work ... so there could be many-to-one rates per employee.
Now - I created a File Layout.
First - I inserted in BT_TEST_HDR.
Then - I inserted in BT_TEST_DTL.
After doing so - I indented BT_TEST_DTL as a child segment of BT_TEST_HDR using
the right arrow (->) button.
Next - I removed the fields EMPLID and EMPL_RCD from the BT_TEST_DTL child segme
nt (since they are already in my parent segment BT_TEST_HDR). The result is a fi
le
layout that looks like this:
File layout Structure :->
NEW FILE
BT_TEST_HDR
EMPLID
EMPL_RCD
EFFDT
NAME
BT_TEST_DTL
COMP_RATECD
COMPRATE
I saved my file layout at BT_TEST_FL.
Next - I created a new App Engine program called BT_TEST_AE. This is a simple ex
ample - so I have Section MAIN, Step01 with
one action (PeopleCode).
I dragged the file layout into my PeopleCode program to auto-geneerate code. I t
hen modified the generated code to come
up with what you see below
(I only used drag-drop to create a baseline ... as Curtis mentioned - it helps s
tructure - that's about it unless you're importing):
rem ************************************;
rem * MODIFIED PeopleCode to EXPORT Data;
rem ************************************;
Local File &FILE1;
Local Record &REC1, &REC2;
Local SQL &SQL1, &SQL2;
Local Rowset &RSExport;
Local integer &I;
/* open our write file */
&FILE1 = GetFile("c:\temp\output.txt", "W", "a",
%FilePath_Absolute);
/* set our output file layout */
&FILE1.SetFileLayout(FileLayout.BT_TEST_FL);

/* create an in-memory rowset based on file layout */


&RSExport = &FILE1.CreateRowset();
/* define SQL1 as our header view SQL */
&SQL1 = CreateSQL("%SelectAll(:1)", Record.BT_TEST_HDR);
/* define in-memory records based on header and detail records
*/
&REC1 = CreateRecord(Record.BT_TEST_HDR);
&REC2 = CreateRecord(Record.BT_TEST_DTL);
/* fetch rows from our header view into our in-memory record */
While &SQL1.Fetch(&REC1);
/* for each fetched row - copy field values to our file layout
rowset level 0 record */
&REC1.CopyFieldsTo(&RSExport(1).GetRecord(Record.BT_TEST_HDR));
/* for each fetched row, fetch comp records for employee */
&SQL2 = CreateSQL("%Selectall(:1) Where EMPLID = :2 And
EMPL_RCD = :3", Record.BT_TEST_DTL,
&REC1.GetField(Field.EMPLID).Value,
&REC1.GetField(Field.EMPL_RCD).Value);
&I = 0;
While &SQL2.Fetch(&REC2);
/* Increment our row counter for our child rowset and - if
not our first pass - insert a row */
If &I > 0 Then
&RSExport(1).GetRowset(Scroll.BT_TEST_DTL).InsertR ow(&I);
End-If;
&I = &I + 1;
/* I could use CopyFieldsTo here - but I'll set individual
field values instead */
&RSExport(1).GetRowset(Scroll.BT_TEST_DTL)(&I).Get Record(Record.
BT_TEST_DTL).GetField(Field.COMP_RATECD).Value &REC2.GetField(Field.COMP_RATECD)
.Value;
&RSExport(1).GetRowset(Scroll.BT_TEST_DTL)(&I).Get Record(Record.
BT_TEST_DTL).GetField(Field.COMPRATE).Value &REC2.GetField(Field.COMPRATE).Value
;
End-While;
/* Close our &SQL2 object */
&SQL2.Close

Potrebbero piacerti anche