EDI X12 Data Types

EDI X12 standard has 7 main data types used for data elements, which are ID, B, AN, Nn, Rn, DT and TM. This article compare and contrast these data types in detail.

25 Jul 2022 by Udith Gunaratna

Electronic Data Interchange (EDI) is a standard format used to electronically interchange business information such as Purchase Orders, Shipping Noticed and Invoices between companies. Currently, there are 2 main EDI standards as X12 (mainly used in the USA) and EDIFACT (mainly used in Europe). The data on these EDI documents are represented via sections called “Loops” and “Segments”. A “loop” consists of segments and/or sub loops, where a segment consists of subsections called “Data Elements”.

The EDI specification for a particular EDI transaction type (e.g. 850 - Purchase Orders) specifies 3 main attributes for each such data element, which are Minimum Length, Maximum Length and Data Type. In this article, we are going to discuss the main Data Types used in EDI X12 standard.

The following image shows the definition of PO1 segment on Walmart 850 documents, with data elements having the above mentioned attributes specified. (Source)

Walmart 850 - PO1 Segment Open image on lightbox

What is X12 EDI?

X12 is the most widely used EDI standard within the USA, which is formally referred to as ASC X12 EDI. This X12 standard was introduced in the 1970s, and evolved for more than four decades and the main purpose of that is to establish a well-defined set of EDI standards and corresponding documents to be used within organizations for a multitude of purposes. Having such a central standard eliminates the communication problems arising from different organizations having different incompatible software for EDIs. X12 standard is more prominently used in industries such as retail, shipping/logistics and healthcare.

EDI X12 Data Types

Following are the main data types used in the EDI X12 standard.

  • ID - Pre-defined Identifier
  • B - Binary
  • AN - Alphanumeric
  • N / Nn - Numeric data with implied decimal
  • R / Rn - Decimal numeric data
  • DT - Date
  • TM - Time

ID

The data elements with type as ID must use a code value from a pre-defined list of IDs specified by the relevant EDI standard.

For example, the following is the list of ID values that can be used with the BEG02 (ID: 92) data element of Purchase Order (850) transactions. Any other value except for these values can not be used for this particular data element.

BEG02 IDs Open image on lightbox

Usually these default ID lists contain many pre-defined IDs covering all the use cases of that data element across different EDI domains/industries. Therefore, most EDI vendors prefer to use a subset of values from that list, which are adequate to cover their use cases.

For example, the following is the list of ID values accepted by Walmart for the same BEG02 (ID: 92) data element discussed above. You can see that Walmart only accepts 3 (BE, RL and SA) out of the 66 ID codes available for this element. In this kind of scenario, using an ID code not belong to these 3 can make the EDI document invalid, even though that ID code is valid according to the generic EDI specification.

Walmart BEG02 IDs Open image on lightbox

B

The data elements with type as B are used to specify binary values. The value of such an element will be a sequence of octets in the range of binary value 00000000 to 11111111. Although an element of this type does not have a defined length in its attributes, usually the preceding element value specifies the expected length.

Binary (B) data type is only used within the BIN segments of EDI X12 transactions

AN

The data elements with type as AN should contain alphanumeric values. Although the word “alphanumeric” typically means alphabetical characters and numbers, in EDI X12 specification this type is considered as a sequence of printable characters.

An AN type value can consist of the characters from the following Basic and Extended character lists. The significant characters should be left justified. Although an AN value should not have trailing spaces, any leading spaces are considered as significant and included.

Basic characters

Uppercase letters A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Numeric digits 0 1 2 3 4 5 6 7 8 9
Special characters ! " & ' ( ) * + , - . / : ; ? =
The space character  

Extended characters

Lowercase letters a b c d e f g h i j k l m n o p q r s t u v w x y z
Other special chars % ~ @ [ ] _ { } \ | < >
National characters # $

N / Nn

The data elements with type as N or Nn (N0, N1, N2…) do not contain an explicit decimal on their value. But the value of n indicates where the implied decimal is from the right end of the value of this element.

Type N and type N0 are equivalent, i.e. n is considered as 0 if data type is mentioned as just N.

For example, if the type is N2 (i.e. n = 2) and the value of the element is 1234567, it means that the implied decimal is before the last 2 (n) digits of the value (i.e. between 5 and 6). So the actual value represented by this element will be 12345.67. Please see some more sample cases below.

Type Actual Value EDI Element Value Explanation
N0 / N 12345.00 12345 Whole number (12345) + no decimals
N1 12345.00 123450 Whole number (12345) + 1 decimal (0)
N2 12345.00 1234500 Whole number (12345) + 2 decimals (00)
N3 12345.789 12345789 Whole number (12345) + 3 decimals (789)

Usually an Nn value should not have leading zeros, unless they are required to satisfy the minimum length condition of the element. A negative value should have the minus (-) sign, and it is not counted when determining the length of the value.

R / Rn

The data elements with type as R or Rn (R0, R1, R2…) contain the decimal in the value, if the actual value contain a fraction. But the decimal part is optional if the value is an integer. Usually a Rn value should not have leading zeros, unless they are required to satisfy the minimum length condition of the element. Trailing zeros of the decimal part is also should be omitted, unless they are required to indicate the precision. A negative value should have the minus (-) sign, and it is not counted when determining the length of the value.

Unlike in N type, type R and type R0 are not equivalent. R0 indicates that the value should not have a decimal part, while having type as just R allows the precision of the original values as it is, except for trailing zeros on the decimal part.

Type Actual Value EDI Element Value Explanation
R 123.450 123.45 Precision of the original value, but without trailing zeros
R0 123.450 123 with 0 decimals
R1 123.420 123.4 upto only 1 decimal, rounded off
R1 123.450 123.5 upto only 1 decimal, rounded off
R2 123.450 123.45 upto only 2 decimals
R2 123.00 123 upto only 2 decimals, but decimals not included as actual value does not have a fraction
R3 123.450 123.450 upto only 3 decimals, trailing zero included to satisfy precision of 3
R4 123.450 123.4500 upto only 4 decimals, 2 trailing zeros included to satisfy precision of 4

DT

The data elements with type as DT contains a Date value in either CCYYMMDD or YYMMDD format, with

  • CC = century
  • YY = year of the century (00-99)
  • MM = month of the year (01-12)
  • DD = date of the month (01-31).

Which of the above 2 formats to be used for a particular element can be determined by the maximum length attribute.

Actual Date Max Length Used Format EDI Element Value
May 31st, 2022 8 CCYYMMDD 20220531
May 31st, 2022 6 YYMMDD 220531

TM

The data elements with type as TM contains a 24-hr clock time value in either HHMM, HHMMSS, HHMMSSD or HHMMSSDD format, with

  • HH = hours (00-23)
  • MM = minutes (00-59)
  • SS = integer seconds (00-59)
  • D = tenths of second (0-9)
  • DD = hundredths of second (00-99).

Which of the above formats to be used for a particular element can be determined by the maximum length attribute.

Actual Time Max Length Used Format EDI Element Value
14:15:20.32 4 HHMM 1415
14:15:20.32 6 HHMMSS 141520
14:15:20.32 7 HHMMSSD 1415203
14:15:20.32 8 HHMMSSDD 14152032