Example 4

This scenario builds on Example 2 from the chapter Restructure function.

The prerequisites are exactly the same as before, we want to group the time transactions per day (date) and employee. The problem is that the input element Date now contains a time stamp, for example 2013-06-17T16:43:23. The time transactions may be created at different times per day. This setting makes it impossible to group the time transactions per date using the input data as it is. We need to remove the time part of the time stamps before restructuring the data. To achieve this, we need to use Collector functions.

  1. Create collector loops.

    To collect the input data, we need two nested loops, one for the repetitive element Employee and one for the repetitive element Time.

    The loops are controlled by these elements. Insert one Collector function into each loop.

  2. Collect data.

    1. Drag and drop the input elements FirstName, LastName, and EmployeeNumber to the first Collector function.

    2. Because we want to modify the date, we create a UVJ function.

      Insert a UVJ function into the inner loop before the second Collector function.

      Drag and drop the input element Date to the Java function and create an output parameter oDate.

    3. Create a logic in the UVJ function to remove time, so that the input date and time 2013-06-17T16:43:23 will be converted to 20130617. Use the EDIFACT format "102", that is the format CCYYMMDD. This format is equal to D8 for ANSI X12.

      For example, use this Java code:

      oDate = new DateTimeConverter().setXMLDateTime(iDate).getEDIDateTime("102");
    4. Create a new input parameter Date in the second Collector function.

      Drag and drop the Java function’s output parameter oDate to the Collector function’s input parameter Date.

    5. Drag and drop the input elements Project and Hours to the second Collector function.

  3. Create restructure loops.

    This step is the same as step 1 in Example 2. Create the three nested restructure loops after the collector loops.

  4. Select data.

    Instead of using the input document’s elements, we use the Collector functions’ output parameters.

    1. Drag and drop these parameters:

      • Date from the second Collector function to the first Restructure function

      • FirstName from the first Collector function to the second Restructure function, and so on

    2. Because we are restructuring the data, you do not need to match the loop levels for the Collector functions and the Restructure functions. Additionally, you have already created the collector loops for this purpose, so you do not need to select input loop levels for the Restructure functions as you do in Example 2.

    3. Drag and drop from the Restructure functions’ output parameters to the elements and attribute in the output document.

  5. Sort and group the data.

    This step is the same as step 4 in Example 2. This example only differs on how you define which data to use. Sorting and grouping are done exactly in the same way as in Example 2.