exist

The exist function tests to determine if a field is empty (null). It returns a non-zero (true) value if there is data in a specified field in internal storage. If data is not present in the specified field, this function returns a zero (false) value. This function is typically used as a part of a condition.

There are some situations when the if exist returns a non-zero (true) value whether or not the condition is true (for example, if the field or element has a "Use Code" standard rule applied to it). You can work around this by only using if exist for date- and number-type fields. Be certain that all references to the field which is interrogated are nested within the if exist begin block.

Note: For string-type fields, use the format if field1 = "".

All modes of operation are exercised by SWIFT MX and FIN maps in the exist extended rule. FIN maps reference the traditional usage ($group.#field) of the exist function while the MX maps reference only the group name ($group).

Note: The group name only usage is reserved for the XML syntax only, because of how the blocks are inserted into the map structure during the compilation process to handle the XML start and end tags in an XML document.

The exist function accepts a block reference denoted with a % prefix, as well as a group reference denoted with the $ prefix. The group reference supports a scenario in which an element was supplied in the input file but none of its conditional children existed. Instead of using variables to test for the condition of a parent element (parentNode) you can just use the group reference (only for XML). If you wanted to check for the existence of the parentNode in this scenario, you can add a flag to the extended rule of the parentNode to determine this condition if the child fields are missing. For example:

integer p; 
p = exist($parentNode);

Common use

The exist function is more often used as !exist (not exist) to store a default value into a field if the field does not exist. The exist function is often used with segments such as SDQ where there can be multiple pairs of information for stores and quantities. You can check to make sure a pair exists before attempting to manipulate the value, for example summing the quantities. The exist function is also used to only output a qualifier if the field it’s qualifying exists.

Syntax

if exist($GROUP_NAME[index][index][index].#FIELD_NAME) then

Example

if exist(#FIELDA) then 
#FIELDB = “EA”;
//Return a non-zero value if the condition is true (data is present in
//the specified instance of the FIELDA field). A zero value is
//returned if the condition is false (no data is present in the
//specified instance of the FIELDNAME field).
if !exist(#FIELDC) then
#FIELDC = “100”;
//Populate FIELDC with the value of 100 if it does not exist already.