Example Build stage in DataStage

An example Build stage, called Divide, which divides one number by another and writes the result and any remainder to an output link. The stage also checks whether you are trying to divide by zero and, if you are, sends the input record to a reject link.

To demonstrate the use of properties, the stage also lets you define a minimum divisor. If the number you are dividing by is smaller than the minimum divisor you specify when adding the stage to a job, then the record is also rejected.

The input to the stage is defined as auto read, while the two outputs have auto write disabled. The code has to explicitly write the data to one or other of the output links. In the case of a successful division the data written is the original record plus the result of the division and any remainder. In the case of a rejected record, only the original record is written.

The input record has two columns: dividend and divisor. Output 0 has four columns: dividend, divisor, result, and remainder. Output 1 (the reject link) has two columns: dividend and divisor.

If the divisor column of an input record contains zero or is less than the specified minimum divisor, the record is rejected, and the code uses the macro transferAndWriteRecord(1) to transfer the data to port 1 and write it. If the divisor is not zero, the code uses doTransfersTo(0) to transfer the input record to Output 0, assigns the division results to result and remainder and finally calls writeRecord(0) to write the record to output 0.

Using the Stage Type dialog box, this stage is defined in IBM® DataStage® in the following manner:

  1. General details are supplied in the General tab.
  2. Details about the stage's creation are supplied on the Creator page.
  3. The optional property of the stage is defined on the Properties tab.
  4. Details of the inputs and outputs are defined on the interfaces tab of the Build page.

    Details about the single input to Divide are given on the Input sub-tab of the Interfaces tab. A table definition for the inputs link is available to be loaded from the IBM DataStage Repository.

    Details about the outputs are given on the Output sub-tab of the Interfaces tab.

    When you use the stage in a job, make sure that you use table definitions compatible with the tables defined in the input and output sub-tabs.

    Details about the transfers carried out by the stage are defined on the Transfer sub-tab of the Interfaces tab.

  5. The code itself is defined on the Logic tab. In this case all the processing is done in the Per-Record loop and so is entered on the Per-Record sub-tab.
  6. As this example uses all the compile and build defaults, all that remains is to click Generate to build the stage.