Mapper main function

This is the main entry point for the mapper. This function initializes the mapper, then loops for each batch that requires mapping. The mapping of a batch is performed by calling ProcessBatch(). After processing all of the batches, this function prepares the final output message by copying the message headers and the complete message to OutputRoot.

CREATE FUNCTION Main() RETURNS BOOLEAN
MAPPER: BEGIN
   -----------------------------
   -- Mapper Initialization Code
   -----------------------------
   IF NOT PSEUDO_CONST_INIT THEN
      CALL InitPseudoConstants();
   END IF;

   -- Initialize the reference rOutputBody
   -- we will build the mapped output on the environment
   -- at the end it will be copied to OutputRoot
   -- this allows us to manage memory
   CREATE LASTCHILD OF Environment AS rOutputBody DOMAIN OUTPUT_DOMAIN;

   --------------------------------------------------
   -- BAT_ITER loop runs for each object transitioned
   --------------------------------------------------
   BAT_ITER: WHILE LASTMOVE(rInputBat) DO

      -- this maps one batch
      CALL ProcessBatch();

      -- Go on to the next object
      MOVE rInputBat NEXTSIBLING REPEAT NAME;

   END WHILE BAT_ITER;

   -- now construct and propagate the real message
   CALL CopyEntireMessage();
   SET OutputRoot.{OUTPUT_DOMAIN} = rOutputBody;

   RETURN TRUE; -- final propagate
END MAPPER;