By Tim Dexter on Mar 14, 2007
There was a question on the forum this week that I thought would be worth 1. answering and 2. sharing that answer here. Frederic was asking:
I've got a master/detail report (vendor/shipments lines) that I would like to output to excel but I'm not able to have on each line, header columns and detail columns ie header columns must be repeated for each detail line. I tried using TemplateBuilder/Insert/TableForm/Advanced but cannot see how to specify that header columns have to be repeated ?
Essentially the question was how to denormalize the master/detail data into a single level where the header data is repeated for every detail record. My answer was to use a for loop around the detail and then an XPATH expression (../) to get back up a level to the header. This did not work for Frederic and now I have his XML I can see why.
The XML came from an Oracle Report and thats why a single '../' was not working. By default, Oracle Reports will wrap an extra level around all of your groups, named 'LIST_' followed by the group name, unless you tell it not to.
For all of the EBS canned reports this is true i.e. we did not turn it off. Why would we, those reports were written a long time ago, a time before we ever thought we would expose columns names to you folks ... and thereby hangs another tale. Now if you were just going to replicate the master/detail layout in your template then the extra level would not matter, it could be ignored. Lets say we have the following XML structure:
If we wanted to build a template following the hierarchy to show, COMPANY -> VENDOR -> DETAILS we can ignore the LIST groups and have :
<?for-each:G_COMPANY?>The template would work no problem, we just ignore the LIST levels and move on down.
However, if, as in Frederic's case we wanted to 'de-normalise' the levels into a single level using my method above we can not ignore the LIST_ levels. So if we created a loop at the lowest level i.e. G_PO_DETAILS and wanted to go up the tree to retrieve data from the G_VENDOR or G_COMPANY levels a simple '../' is not enough we need to go up one more level to get past the LIST_ layer i.e. '../../'.
Let's a take a small portion of the XML tree:
<BUYER>Buyer, Miss Rosy</BUYER>
To flatten this data out we would have the following:
Notice the '../../' for the first two columns to get to the grandparent level in the data from the details level getting past the defunct LIST_ level. Run this template against our data and we get the flattened struct Frederic was looking for in Excel, or any other format for that matter.
Now, I admit you had to go in and put the ../../, why does the Template Builder not know where you are in the template and do it for you? Good question, one that I hope we'll resolve real soon!
Hopefully more of an answer than Fredric could ever hope for :o)