Writing an XML report driver and routine

Generating XML output

To produce an XML report, initiate the report with the START REPORT instruction followed by the TO XML HANDLER clause, to specify the SAX document handler that will process the XML report output:
START REPORT order_report 
      TO XML HANDLER om.XmlWriter.createFileWriter("orders.xml")

In the report routine, you must use the PRINTX statement to general XML output:

REPORT order_report(rec)
  ...
  FORMAT
    ON EVERY ROW
      PRINTX NAME = order rec.*
  ...
END REPORT

The PRINTX instruction takes an optional NAME argument to define the name of the XML node.

Nested XML reports

If a new report is started with START REPORT instruction inside a REPORT routine producing XML, and if there is no destination specified in the START REPORT instruction, the sub-report inherits the XML output target of the parent, and sub-report nodes will be merged into the parent XML output:

REPORT order_report(rec)
  ...
  FORMAT
    ON EVERY ROW
      PRINTX NAME = order rec.*
      -- Merges sub-report output to parent report XML handler
      START REPORT sub_report
      FOR ...
          OUTPUT TO REPORT sub_report(...)
      END FOR
      FINISH REPORT sub_report
  ...
END REPORT

API for global XML handler

The fgl_report_set_document_handler() built-in function can be used to specify a general XML handler, for START REPORT instructions which do not use the TO XML HANDLER clause:
MAIN
  ...
  CALL fgl_report_set_document_handler( om.XmlWriter.createFileWriter("orders.xml") )
  ...
  START REPORT order_report -- Produces XML output to "orders.xml"
  ...
END MAIN
Note: The fgl_report_set_document_handler() function is supported for backward compatibility, it is recommended to use START REPORT … TO XML HANDLER instead.