XMLP: Generating XML Report from Scratch(My Own Example)





Generating the XML Publisher Report from Scratch:

       Full Program : 




        Main Section : 





      Truncate: 







      Truncate SQL Code:






       INIT Code:




       Do Select: 




       Insert into staging table and updating the staging table:





       
     Prepare and generate the report:





     
            XMLGEN code:



REM ****************************************Modification Summary ******************************************;
REM SL.No                   Developer                              Mod. No.           Date                                                                         Changes       
REM -----                     -----------                                 ----------            ----------                               -------------------------------------------
REM  01          Krishnam Raju       AD0005      11/17/2015       Added code to generate the XML file
REM********************************************************************************************************;
Function StartObjectNode(&ObjectTypeCode As string)
   Evaluate &ObjectTypeCode
   When "-1"
      &inXMLProjObjNode = &inXMLDoc.DocumentElement.AddElement("LAC_EOPS_RPT");
      Break;
   End-Evaluate;
End-Function;
Function EndObjectNode(&ObjectTypeCode As string)
   Evaluate &ObjectTypeCode
   When "0"
      &inXMLRecCount.NodeValue = String(&inXMLRecObjNode.ChildNodeCount - 1);
      Break;
   End-Evaluate;
End-Function;
Function CreateParentStgXML()
   Local XmlNode &inXMLProjNode, &inXMLClassNotesNode;
   Local Record &rec_LAC_EOPS_STG;
   Local Rowset &rs_LAC_EOPS_STG;
   Local integer &I, &J, &K, &L;
   &rec_LAC_EOPS_STG = CreateRecord(Record.LAC_EOPS_STG);
   &rs_LAC_EOPS_STG = CreateRowset(Record.LAC_EOPS_STG);
  

  MessageBox(0, "", 0, 0, "&ProcessInstance : " | &ProcessInstance);
   &rscount_header = &rs_LAC_EOPS_STG.Fill("where PROCESS_INSTANCE = :1", &ProcessInstance);
  For &Z = 1 To &rscount_header
      &inXMLHeaderNode = &inXMLProjObjNode.AddElement("HEADER");
      &EMPLID = &rs_LAC_EOPS_STG(&Z).LAC_EOPS_STG.EMPLID.Value;
      For &K = 1 To &rec_LAC_EOPS_STG.FieldCount
         &fieldname = &rec_LAC_EOPS_STG.GetField(&K).Name;
         &inxmlPNode1 = &inXML | &fieldname;
         &inxmlPNode1 = &inXMLHeaderNode.AddElement(&fieldname);
         &inxmlPNode1.NodeValue = &rs_LAC_EOPS_STG(&Z).LAC_EOPS_STG.GetField(@("FIELD." | &fieldname)).Value;
      End-For;
   End-For;
End-Function;
Local File &file;
&inXMLDoc = CreateXmlDoc("<?xml version='1.0'?><ROOT/>");
StartObjectNode("-1");
&ProcessInstance = LAC_EOPS_AET.PROCESS_INSTANCE.Value;
CreateParentStgXML();
EndObjectNode("-1");
&OUTPUTfile = "LAC_EOPS_" | LAC_EOPS_AET.PROCESS_INSTANCE.Value | ".XML";
&file = GetFile(&OUTPUTfile, "W", %FilePath_Absolute);
&file.WriteLine(&inXMLDoc.GenFormattedXmlString());
&file.Close();


        GENRPT code:

REM ****************************************Modification Summary ******************************************;
REM SL.No                   Developer                               Mod. No.          Date                                                                         Changes       
REM -----                     -----------                                  ----------           ----------                               -------------------------------------------
REM  01         Krishnam Raju N      AD0005      11/17/2015       Added code to generate the CSG Report output
REM********************************************************************************************************;
import PSXP_RPTDEFNMANAGER:*;
Local Record &rcdQryPrompts;
Local string &sTmpltID, &sLangCd;
Local date &AsOfDate;
Local File &file;
/* get report definition object */
&sRptDefn = "LAC_EOPS_RPT";
Local string &OUTPUTFMT = "PDF";
&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn(&sRptDefn);
&oRptDefn.Get();
/* fill query runtime prompt record */
<*&rcdQryPrompts = &oRptDefn.GetPSQueryPromptRecord();
If Not &rcdQryPrompts = Null Then
   /* Assign PS Qry Prompt values */
   &rcdQryPrompts.PROCESS_INSTANCE.Value = LAC_CSG_RPT_AET.PROCESS_INSTANCE.Value;
  
   &oRptDefn.SetPSQueryPromptRecord(&rcdQryPrompts);
End-If;
*>
&OUTPUTfile = "LAC_EOPS_" | LAC_EOPS_AET.PROCESS_INSTANCE.Value | ".XML";
MessageBox(0, "", 0, 0, &OUTPUTfile);
&file = GetFile(&OUTPUTfile, "W", %FilePath_Relative);
&oRptDefn.SetRuntimeDataXMLFile(&OUTPUTfile);
/*generate report*/
&sTmpltID = "LAC_EOPS_RPT_1";
&sLangCd = "ENG";
&AsOfDate = %Date;
&sOutFormat = &oRptDefn.GetDefaultOutputFormat();
&oRptDefn.ProcessReport(&sTmpltID, &sLangCd, &AsOfDate, &sOutFormat);
/*publish report */
&oRptDefn.Publish("", "", "", LAC_EOPS_AET.PROCESS_INSTANCE);



Comments

Popular posts from this blog

BI Publisher: If Condition with sub-string in rtf template