Configuring Character-Level Validation
In most cases, validation of EDI fields means comparing, at mapping runtime, the field value with a list of possible values defined in a MapForce configuration file. For example, if the field value matches one the possible values defined in the configuration file, it is considered valid.
However, certain fields might need more advanced validation rules, meaning that their validation logic cannot be expressed as a simple list of possible values. An example of a field which requires complex validation is Data Element 8155 used in the VERMAS (Verification of Mass) message of UN/EDIFACT D16A. This field accepts not only code values defined in the UN/EDIFACT standard, but also external codes specified by the ISO 6346 standard. The ISO 6346 standard, in its turn, defines validation rules at character-level, namely:
•First character can be one of these: 1, 2, 3, 4, A, B, C, D, E, F, G, H, K, L, M, N, P
•Second character can be one of these: 0, 2, 4, 5, 6, 8, 9, C, D, E, F, L, M, N, P
•Third and fourth character can be: G0, G1, G2, G3, etc. (values are too many to be listed here).
It is possible to adapt validation logic such as the one above to MapForce as well. In this case, MapForce will validate Data Element 8155 not only according to the UN/EDIFACT code values, but also taking into consideration the rules above applicable to the ISO 6346 standard.
From a MapForce configuration perspective, the rules expressed by the three bullets above can be regarded as three separate lists of values. The first list is one character long, the second list is one character long, and the third list is two characters long. All three lists are finite and their values are known. This information makes it possible to validate the value of the data element by means of MapForce configuration.
To see an example of how character-level validation must be configured, open the ISO6346.Codelist file from the C:\Program Files\Altova\MapForce2023\MapForceEDI\EDIFACT directory. This file supplied by default with MapForce is configured to perform validation of Data Element 8155 according to ISO 6346 rules stated above.
<?xml version="1.0" encoding="UTF-8"?>
ISO6346.Codelist configuration file
|Note:||Some of the values from the sample code listing above were removed, for simplicity.|
In the code listing above, notice that, the <Field> element is defined three times. This makes it possible to validate the field content at character level. Namely, each occurrence of <Field> validates one of the rules stated in the bullets above at a time. To achieve this, each <Field> has several attributes (highlighted in the code listing above):
•Name - This attribute indicates that the list of values being validated belongs to the same field. In other words, it binds all three lists to the same field (in this case, "F8155").
•ListName - This attribute gives a name to a list of values. Lists of values with the same name are grouped into one code list. Notice that in the example above all three lists have the same ListName="ISO6346". This is needed specifically for character level validation. The actual characters to be validated are specified by the Length and Offset attributes of each list in the group, as explained below.
•Length - This attribute specifies the number of characters to be validated (the starting position of characters in the field is defined by the Offset attribute). Notice that character length varies for each <Field>: the first and the second list of values is one character long, while the third list of values contains two characters.
•Offset - This attribute specifies the position at which MapForce (or the external execution engine) must start reading the characters from the data field which is being validated. The first character has offset 1, the second character has offset 2, and so on. The actual number of characters is defined by the Length attribute.
If the Length attribute is defined, the Offset attribute must be defined as well. Also, the value of both Length and Offset must be greater than zero.
In the code listing above, the following Length-Offset combinations were defined:
•Length="1", Offset="1" - this combination will validate one character of the field, starting at offset 1
•Length="1", Offset="2" - this combination will validate one character of the field, starting at offset 2
•Length="2", Offset="3" - this combination will validate two characters of the field, starting at offset 3
Each Length-Offset combination, combined with the code values defined under <Values>, represents a validation condition at character level. When the mapping runs, all character-level conditions must be satisfied (because all have the same ListName attribute value) for field validation to be successful. In other words, when validating a message that includes Data Element 8155, MapForce will apply the following logic:
•The field characters are validated against the list of code values defined in the configuration file (in this case, ISO6346.Codelist) for a matching Length-Offset combination. For example, the first character of the field must be one of the following: 1, 2, 3, 4, B, C, G, H, L, M, N.
•The field value must satisfy all conditions at character-level (in this case, three conditions must be satisfied) in order for validation to be successful.
•If any of the conditions is not satisfied, the field value is not valid, and a validation error is produced in MapForce (or in the execution engine running the EDI mapping (such as MapForce Server, or a C#, C++, or Java program).
•A field may have more than one list of possible code values. In ordered to be considered valid, the field value must be present in at least one of the lists.