/*********************************************************/
/** Northrop Grumman **/
/** Information Technology **/
/** Advanced XML Publisher with PeopleCode demo **/
/** XML File Generation Examples **/
/** Contact: [Link]@[Link] **/
/*********************************************************/
import PSXP_XMLGEN:*;
import PSXP_RPTDEFNMANAGER:*;
Function LoadTestDataSet() Returns Rowset;
Local Rowset &RS_Training, &RS_Employee;
Local Record &JOB_REC, &LOCATION_TBL_REC, &COMPANY_TBL_REC, &JOBCODE_TBL_REC;
Local integer &i;
/* create records */
&JOB_REC = CreateRecord([Link]);
&LOCATION_TBL_REC = CreateRecord(Record.LOCATION_TBL);
&COMPANY_TBL_REC = CreateRecord(Record.COMPANY_TBL);
&JOBCODE_TBL_REC = CreateRecord(Record.JOBCODE_TBL);
/* create rowsets */
&RS_Training = CreateRowset(Record.X_TRAINING_VW); /* child rowset */
&RS_Employee = CreateRowset(Record.X_EE_RPT_LTR_VW, &RS_Training); /* parent
rowset */
/* Fill Parent */
&RS_Employee.Fill("where emplid like 'KU000%' and exists (select 'x' from ps_
training t where [Link] = [Link])");
/* Loop through parent rowset for processing on each row */
For &i = 1 To &RS_Employee.ActiveRowCount
/* Fill child rowset */
&RS_Training = &RS_Employee(&i).GetRowset(Scroll.X_TRAINING_VW);
&RS_Training.Fill("where emplid = :1", &RS_Employee(&i).X_EE_RPT_LTR_VW.EM
[Link]);
/* Get job row for linking other data */
&JOB_REC.[Link] = &RS_Employee(&i).X_EE_RPT_LTR_VW.[Link];
&JOB_REC.EMPL_RCD.Value = 0;
/* get the current effdt & effseq for the EEs job row */
SQLExec("select %dateout([Link]), [Link] from ps_job j where [Link] =
:1 and j.empl_rcd = :2 and [Link] = (select max([Link]) from ps_job j2 where
[Link] = [Link] and j2.empl_rcd = j.empl_rcd and [Link] <= %datein(:3))
and [Link] = (select max([Link]) from ps_job j3 where [Link] = [Link]
and j3.empl_rcd = j.empl_rcd and [Link] = [Link])", &JOB_REC.[Link], &J
OB_REC.EMPL_RCD.Value, %Date, &JOB_REC.[Link], &JOB_REC.[Link]);
&JOB_REC.SelectByKey();
/* retrieve specific location data for description in report */
&LOCATION_TBL_REC.[Link] = &JOB_REC.SETID_LOCATION.Value;
&LOCATION_TBL_REC.[Link] = &JOB_REC.[Link];
&LOCATION_TBL_REC.SelectByKeyEffDt(%Date);
&RS_Employee(&i).X_EE_RPT_LTR_VW.LOCATION_DESCR.Value = &LOCATION_TBL_REC.
[Link];
/* retrieve specific company data for description in report */
&COMPANY_TBL_REC.[Link] = &JOB_REC.[Link];
&COMPANY_TBL_REC.SelectByKeyEffDt(%Date);
&RS_Employee(&i).X_EE_RPT_LTR_VW.COMPANY_DESCR.Value = &COMPANY_TBL_REC.DE
[Link];
/* retrieve specific jobcode data for description in report */
&JOBCODE_TBL_REC.[Link] = &JOB_REC.SETID_JOBCODE.Value;
&JOBCODE_TBL_REC.[Link] = &JOB_REC.[Link];
&JOBCODE_TBL_REC.SelectByKeyEffDt(%Date);
&RS_Employee(&i).X_EE_RPT_LTR_VW.JOB_DESCR.Value = &JOBCODE_TBL_REC.DESCR.
Value;
End-For;
Return &RS_Employee;
End-Function;
Local PSXP_XMLGEN:RowSetDS &oXML_GENERATOR;
Local File &XSD_File, &XML_File;
Local Rowset &RS_Employee;
Local string &XML_Filename_path, &XSD_Filename_path, &my_schema, &my_xml;
Local integer &i;
/* Load data into rowset */
&RS_Employee = LoadTestDataSet();
/* output files */
/* create xsd */
&oXML_GENERATOR = create psxp_xmlgen:RowSetDS();
&my_schema = &oXML_GENERATOR.getXSDSchema(&RS_Employee);
&XSD_File = GetFile("[Link]", "W");
&XSD_File.WriteLine(&my_schema);
/* Get filename and path for creating xml file */
&XSD_Filename_path = &XSD_File.Name;
&XSD_File.Close();
rem create sample xml file;
rem &my_xml = &oXML_GENERATOR.getXMLData(&RS_Employee, &XSD_Filename_path);
&my_xml = &oXML_GENERATOR.getXMLData(&RS_Employee, "");
&XML_File = GetFile("[Link]", "W");
&XML_File.WriteLine(&my_xml);
/* save file name and path for publishing */
&XML_Filename_path = &XML_File.Name;
&XML_File.Close();
/* Gen XML Pub report with data file */
&oXML_PUB = create PSXP_RPTDEFNMANAGER:ReportDefn("X_TRAIN_RPT");
&oXML_PUB.Get();
/* tell the report where to find the xml file data source */
&oXML_PUB.SetRuntimeDataXMLfile(&XML_Filename_path);
/* Process Report */
&oXML_PUB.ProcessReport("", "", %Date, "");
/* save to clear think time functions */
DoSaveNow();
/* publish report to new window */
rem &oXML_PUB.DisplayOutput();
/* find location of resulting XML Report */
&sDirSep = "/";
&ReportFileName = &oXML_PUB.ID | "." | Lower(&oXML_PUB.GetOutDestFormatString(2)
);
&ReportFilePath = &oXML_PUB.OutDestination | &sDirSep | "RptInst" | &sDirSep | &
ReportFileName;
rem MessageBox(0, "", 299, 0, "File: %1", &ReportFilePath);
DoSaveNow();
/* use the attachment functions to pop the new merged document to a new window *
/
/* Report pop */
&Returncode = PutAttachment("record://X_FILEATTACH", &ReportFileName, &ReportFil
ePath);
&retcode = ViewAttachment("record://X_FILEATTACH", &ReportFileName, &ReportFileN
ame);
/* xsd pop */
&Returncode = PutAttachment("record://X_FILEATTACH", "[Link]", &XSD_File
name_path);
&retcode = ViewAttachment("record://X_FILEATTACH", "[Link]", "[Link]
.xml");
/* xml pop */
&Returncode = PutAttachment("record://X_FILEATTACH", "[Link]", &XML_Filename
_path);
&retcode = ViewAttachment("record://X_FILEATTACH", "[Link]", "[Link]");
/*********************************************************/
/** Northrop Grumman **/
/** Information Technology **/
/** Advanced XML Publisher with PeopleCode demo **/
/** XML File Generation Examples **/
/** Contact: [Link]@[Link] **/
/*********************************************************/