GETANDSET

You can use GETANDSET when you have an input file that keeps track of control information that serves as an input to your map and the control information in the file needs to be updated based on processing that occurs in your map.

The GETANDSET function gets a fixed length value from the input data stream, updates that value in the input data stream, and returns either the original or updated value.

Syntax:

GETANDSET (single-fixed-size-item-object-name,  single-item-expression,
single-integer-expression)

Meaning:
GETANDSET (original_value ,new_value, integer_that_determines_which_value_to_return)
Returns:
A single-fixed-size-item and replaces the original value in the input data stream.

This function does not support decrementing integers past 0 into negative numbers.

GETANDSET updates an input by finding the object represented by original_value and replacing it with the value represented by the new_value. The function returns either the original_value or the new_value, depending on the value of the integer_that_determines_which_value_to_return. For example,

  • If integer_that_determines_which_value_to_return has the value 1, original_value is returned.
  • If integer_that_determines_which_value_to_return has the value 2, new_value is returned.
  • If integer_that_determines_which_value_to_return has any other value, original_value is returned.
  • If one of the input arguments evaluates to "none", GETANDSET returns "none".

    The original value specified for new_value must be a fixed size item. During map execution, the original value is updated to reflect the evaluation of GETANDSET. When the source is a file, that file will be updated after map completion. However, if the source is a database, message, or application, the content of the source is in memory and the source, itself, is not updated.

Examples

  • New Tracking# = GETANDSET (Tracking#:Card, Tracking#:Card + 3, 1)

    This rule finds the object Tracking#:Card (assume that it has the value 6), adds 3 to it, giving 9, and replaces the 6 with the 9 in the data location of Tracking#:Card. Subsequent references to Tracking#:Card will find its value to be 9. If Card is an input card whose source is a file, the file is rewritten with the new value.

    Because the third input argument (integer_that_determines_which_value_to_return) is 1, the returned value is the original value of 6.


Feedback