Start of change

Writing a generator for the RPG DATA-GEN operation code

The DATA-GEN operation generates a structured document from an RPG variable. The operation requires a generator that creates the document using the names and values repeatedly passed to it by DATA-GEN. The generator uses callback functions to pass the text for the document to the RPG runtime, which places the data into an RPG variable or a file in the Integrated File System.

Handling clean-up activities

Usually, the generator can perform its clean-up activities during an "end' event. However, in some cases, there may not be an "end" event. This can occur in the following circumstances:
  • An error occurs during the DATA-GEN operation.
  • A DATA-GEN *START operation begins a sequence of DATA-GEN operations, but no matching DATA-GEN *END operation is done before the RPG procedure ends. See Sequences of DATA-GEN operations.
Tip: If your generator has code that needs to run when the generation is complete, set the doTerminateEvent subfield in the parameter passed to the generator to '1'. If that indicator is on after the most recent call to the generator, the RPG runtime will call the generator with a QrnDgEvent_12_Terminate event.
Warning: During the QrnDgEvent_12_Terminate event, the generator cannot call the callback procedures. Attempting to do so will result in an exception.
End of change