EDIFACT ORDERS Purchase Order Last updated: 2026-09-29
ORDERS is the UN/EDIFACT purchase order message. A buyer sends it to a supplier to order goods or services. D96A is the directory most retail and manufacturing partners still use.
The header carries BGM (220 is an order), dates, references and NAD parties. UNS separates the header from the detail section, where each LIN group is an order line with PIA, QTY and PRI segments.
At a glance
- Standard
- EDIFACT
- Version
D96A- Sent by
- Buyer to supplier
- Responses
- CONTRL, ORDRSP, DESADV, INVOIC
- ediFabric .NET template
TSORDERSinEdiFabric.Templates.Edifact- OpenEDI definition
- View ORDERS in the spec library
ORDERS structure
The full EDIFACT ORDERS layout from its OpenEDI definition, the same model ediFabric uses to parse, validate and generate it: 54 loops and 162 segment positions, in file order. Loops are shaded and their segments indented; Max use is how many times a segment or loop may repeat.
| Segment / loop | Name | Usage | Max use |
|---|---|---|---|
UNH | Message header | Mandatory | 1 |
BGM | Beginning of message | Mandatory | 1 |
DTM | Date/time/period | Mandatory | 35 |
PAI | Payment instructions | Optional | 1 |
ALI | Additional information | Optional | 5 |
IMD | Item description | Optional | 1 |
FTX | Free text | Optional | 99 |
| RFF loop | Reference | Optional | 10 |
RFF | Reference | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| NAD loop | Name and address | Optional | 99 |
NAD | Name and address | Mandatory | 1 |
LOC | Place/location identification | Optional | 25 |
FII | Financial institution information | Optional | 5 |
| RFF loop | Reference | Optional | 10 |
RFF | Reference | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| DOC loop | Document/message details | Optional | 5 |
DOC | Document/message details | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| CTA loop | Contact information | Optional | 5 |
CTA | Contact information | Mandatory | 1 |
COM | Communication contact | Optional | 5 |
| TAX loop | Duty/tax/fee details | Optional | 5 |
TAX | Duty/tax/fee details | Mandatory | 1 |
MOA | Monetary amount | Optional | 1 |
LOC | Place/location identification | Optional | 5 |
| CUX loop | Currencies | Optional | 5 |
CUX | Currencies | Mandatory | 1 |
PCD | Percentage details | Optional | 5 |
DTM | Date/time/period | Optional | 5 |
| PAT loop | Payment terms basis | Optional | 10 |
PAT | Payment terms basis | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
PCD | Percentage details | Optional | 1 |
MOA | Monetary amount | Optional | 1 |
| TDT loop | Details of transport | Optional | 10 |
TDT | Details of transport | Mandatory | 1 |
| LOC loop | Place/location identification | Optional | 10 |
LOC | Place/location identification | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| TOD loop | Terms of delivery or transport | Optional | 5 |
TOD | Terms of delivery or transport | Mandatory | 1 |
LOC | Place/location identification | Optional | 2 |
| PAC loop | Package | Optional | 10 |
PAC | Package | Mandatory | 1 |
MEA | Measurements | Optional | 5 |
| PCI loop | Package identification | Optional | 5 |
PCI | Package identification | Mandatory | 1 |
RFF | Reference | Optional | 1 |
DTM | Date/time/period | Optional | 5 |
GIN | Goods identity number | Optional | 10 |
| EQD loop | Equipment details | Optional | 10 |
EQD | Equipment details | Mandatory | 1 |
HAN | Handling instructions | Optional | 5 |
MEA | Measurements | Optional | 5 |
FTX | Free text | Optional | 5 |
| SCC loop | Scheduling conditions | Optional | 10 |
SCC | Scheduling conditions | Mandatory | 1 |
FTX | Free text | Optional | 5 |
RFF | Reference | Optional | 5 |
| QTY loop | Quantity | Optional | 10 |
QTY | Quantity | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| APR loop | Additional price information | Optional | 25 |
APR | Additional price information | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
RNG | Range details | Optional | 1 |
| ALC loop | Allowance or charge | Optional | 15 |
ALC | Allowance or charge | Mandatory | 1 |
ALI | Additional information | Optional | 5 |
DTM | Date/time/period | Optional | 5 |
| QTY loop | Quantity | Optional | 1 |
QTY | Quantity | Mandatory | 1 |
RNG | Range details | Optional | 1 |
| PCD loop | Percentage details | Optional | 1 |
PCD | Percentage details | Mandatory | 1 |
RNG | Range details | Optional | 1 |
| MOA loop | Monetary amount | Optional | 2 |
MOA | Monetary amount | Mandatory | 1 |
RNG | Range details | Optional | 1 |
| RTE loop | Rate details | Optional | 1 |
RTE | Rate details | Mandatory | 1 |
RNG | Range details | Optional | 1 |
| TAX loop | Duty/tax/fee details | Optional | 5 |
TAX | Duty/tax/fee details | Mandatory | 1 |
MOA | Monetary amount | Optional | 1 |
| RCS loop | Requirements and conditions | Optional | 100 |
RCS | Requirements and conditions | Mandatory | 1 |
RFF | Reference | Optional | 5 |
DTM | Date/time/period | Optional | 5 |
FTX | Free text | Optional | 5 |
| LIN loop | Line item | Optional | 200000 |
LIN | Line item | Mandatory | 1 |
PIA | Additional product id | Optional | 25 |
IMD | Item description | Optional | 99 |
MEA | Measurements | Optional | 5 |
QTY | Quantity | Optional | 10 |
PCD | Percentage details | Optional | 5 |
ALI | Additional information | Optional | 5 |
DTM | Date/time/period | Optional | 35 |
MOA | Monetary amount | Optional | 10 |
GIN | Goods identity number | Optional | 1000 |
GIR | Related identification numbers | Optional | 1000 |
QVR | Quantity variances | Optional | 1 |
DOC | Document/message details | Optional | 5 |
PAI | Payment instructions | Optional | 1 |
FTX | Free text | Optional | 99 |
| CCI loop | Characteristic/class id | Optional | 999 |
CCI | Characteristic/class id | Mandatory | 1 |
CAV | Characteristic value | Optional | 10 |
MEA | Measurements | Optional | 10 |
| PAT loop | Payment terms basis | Optional | 10 |
PAT | Payment terms basis | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
PCD | Percentage details | Optional | 1 |
MOA | Monetary amount | Optional | 1 |
| PRI loop | Price details | Optional | 25 |
PRI | Price details | Mandatory | 1 |
CUX | Currencies | Optional | 1 |
APR | Additional price information | Optional | 1 |
RNG | Range details | Optional | 1 |
DTM | Date/time/period | Optional | 5 |
| RFF loop | Reference | Optional | 10 |
RFF | Reference | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| PAC loop | Package | Optional | 10 |
PAC | Package | Mandatory | 1 |
MEA | Measurements | Optional | 5 |
QTY | Quantity | Optional | 5 |
DTM | Date/time/period | Optional | 5 |
| RFF loop | Reference | Optional | 1 |
RFF | Reference | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| PCI loop | Package identification | Optional | 5 |
PCI | Package identification | Mandatory | 1 |
RFF | Reference | Optional | 1 |
DTM | Date/time/period | Optional | 5 |
GIN | Goods identity number | Optional | 10 |
| LOC loop | Place/location identification | Optional | 9999 |
LOC | Place/location identification | Mandatory | 1 |
QTY | Quantity | Optional | 1 |
DTM | Date/time/period | Optional | 5 |
| TAX loop | Duty/tax/fee details | Optional | 10 |
TAX | Duty/tax/fee details | Mandatory | 1 |
MOA | Monetary amount | Optional | 1 |
LOC | Place/location identification | Optional | 5 |
| NAD loop | Name and address | Optional | 99 |
NAD | Name and address | Mandatory | 1 |
LOC | Place/location identification | Optional | 5 |
| RFF loop | Reference | Optional | 5 |
RFF | Reference | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| DOC loop | Document/message details | Optional | 5 |
DOC | Document/message details | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| CTA loop | Contact information | Optional | 5 |
CTA | Contact information | Mandatory | 1 |
COM | Communication contact | Optional | 5 |
| ALC loop | Allowance or charge | Optional | 99 |
ALC | Allowance or charge | Mandatory | 1 |
ALI | Additional information | Optional | 5 |
DTM | Date/time/period | Optional | 5 |
| QTY loop | Quantity | Optional | 1 |
QTY | Quantity | Mandatory | 1 |
RNG | Range details | Optional | 1 |
| PCD loop | Percentage details | Optional | 1 |
PCD | Percentage details | Mandatory | 1 |
RNG | Range details | Optional | 1 |
| MOA loop | Monetary amount | Optional | 2 |
MOA | Monetary amount | Mandatory | 1 |
RNG | Range details | Optional | 1 |
| RTE loop | Rate details | Optional | 1 |
RTE | Rate details | Mandatory | 1 |
RNG | Range details | Optional | 1 |
| TAX loop | Duty/tax/fee details | Optional | 5 |
TAX | Duty/tax/fee details | Mandatory | 1 |
MOA | Monetary amount | Optional | 1 |
| TDT loop | Details of transport | Optional | 10 |
TDT | Details of transport | Mandatory | 1 |
| LOC loop | Place/location identification | Optional | 10 |
LOC | Place/location identification | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| TOD loop | Terms of delivery or transport | Optional | 5 |
TOD | Terms of delivery or transport | Mandatory | 1 |
LOC | Place/location identification | Optional | 2 |
| EQD loop | Equipment details | Optional | 10 |
EQD | Equipment details | Mandatory | 1 |
HAN | Handling instructions | Optional | 5 |
MEA | Measurements | Optional | 5 |
FTX | Free text | Optional | 5 |
| SCC loop | Scheduling conditions | Optional | 100 |
SCC | Scheduling conditions | Mandatory | 1 |
FTX | Free text | Optional | 5 |
RFF | Reference | Optional | 5 |
| QTY loop | Quantity | Optional | 10 |
QTY | Quantity | Mandatory | 1 |
DTM | Date/time/period | Optional | 5 |
| RCS loop | Requirements and conditions | Optional | 100 |
RCS | Requirements and conditions | Mandatory | 1 |
RFF | Reference | Optional | 5 |
DTM | Date/time/period | Optional | 5 |
FTX | Free text | Optional | 5 |
| STG loop | Stages | Optional | 10 |
STG | Stages | Mandatory | 1 |
| QTY loop | Quantity | Optional | 3 |
QTY | Quantity | Mandatory | 1 |
MOA | Monetary amount | Optional | 1 |
UNS | Section control | Mandatory | 1 |
MOA | Monetary amount | Optional | 12 |
CNT | Control total | Optional | 10 |
| ALC loop | Allowance or charge | Optional | 10 |
ALC | Allowance or charge | Mandatory | 1 |
ALI | Additional information | Optional | 1 |
MOA | Monetary amount | Mandatory | 2 |
UNT | Message trailer | Mandatory | 1 |
Sample ORDERS file
A D96A purchase order with header parties and order lines. Paste it into EdiNation to see every element named and validated.
UNB+UNOB:1+SENDER1:14:ZZUK+RECEIVER1:1:ZZUK+071101:1701+131++ORDERS++1++1' UNH+000000101+ORDERS:D:96A:UN' BGM+220+128576+9' DTM+137:20020830:102' PAI+::42' FTX+ZZZ+1+001::91' RFF+CT:652744' DTM+171:20020825:102' NAD+BY+5412345000013::9' RFF+VA:87765432' CTA+OC+:P FORGET' COM+0044715632478:TE' NAD+SU+4012345500004::9' RFF+VA:56225432' CUX+2:GBP:9+3:EUR:4+1.67' DTM+134:2002080120020831:718' TDT+20++30+31' TOD+3++CIF:23:9' LOC+1+BE-BRU' LIN+1++4000862141404:SRS' PIA+1+ABC1234:IN' IMD+C++TU::9' QTY+21:48' MOA+203:699.84' PRI+AAA:14.58:CT:AAE:1:KGM' RFF+PL:AUG93RNG04' DTM+171:20020801:102' PAC+2+:51+CS' PCI+14' LOC+7+3312345502000::9' QTY+11:24' DTM+2:20020915:102' LOC+7+3312345501003::9' QTY+11:24' DTM+2:20020913:102' TAX+7+VAT+++:::17.5+S' UNS+S' CNT+2:1' UNT+38+000000101' UNZ+1+131'
The same ORDERS as JSON
ediFabric turns every loop, segment and element into a named field. This is the transaction from the sample, in the JSON that ediFabric Native and Cloud return and accept.
{
"UNH": {
"MessageReferenceNumber_01": "000000101",
"MessageIdentifier_02": {
"MessageType_01": "ORDERS",
"MessageVersionNumber_02": "D",
"MessageReleaseNumber_03": "96A",
"ControllingAgencyCoded_04": "UN"
}
},
"BGM": {
"DOCUMENTMESSAGENAME_01": {
"Documentmessagenamecoded_01": "220"
},
"Documentmessagenumber_02": "128576",
"Messagefunctioncoded_03": "9"
},
"DTM": [
{
"DATETIMEPERIOD_01": {
"Datetimeperiodqualifier_01": "137",
"Datetimeperiod_02": "20020830",
"Datetimeperiodformatqualifier_03": "102"
}
}
],
"PAI": {
"PAYMENTINSTRUCTIONDETAILS_01": {
"Paymentmeanscoded_03": "42"
}
},
"FTX": [
{
"Textsubjectqualifier_01": "ZZZ",
"Textfunctioncoded_02": "1",
"TEXTREFERENCE_03": {
"Freetextcoded_01": "001",
"Codelistresponsibleagencycoded_03": "91"
}
}
],
"RFFLoop": [
{
"RFF": {
"REFERENCE_01": {
"Referencequalifier_01": "CT",
"Referencenumber_02": "652744"
}
},
"DTM": [
{
"DATETIMEPERIOD_01": {
"Datetimeperiodqualifier_01": "171",
"Datetimeperiod_02": "20020825",
"Datetimeperiodformatqualifier_03": "102"
}
}
]
}
],
"NADLoop": [
{
"NAD": {
"Partyqualifier_01": "BY",
"PARTYIDENTIFICATIONDETAILS_02": {
"Partyididentification_01": "5412345000013",
"Codelistresponsibleagencycoded_03": "9"
}
},
"RFFLoop": [
{
"RFF": {
"REFERENCE_01": {
"Referencequalifier_01": "VA",
"Referencenumber_02": "87765432"
}
}
}
],
"CTALoop": [
{
"CTA": {
"Contactfunctioncoded_01": "OC",
"DEPARTMENTOREMPLOYEEDETAILS_02": {
"Departmentoremployee_02": "P FORGET"
}
},
"COM": [
{
"COMMUNICATIONCONTACT_01": {
"Communicationnumber_01": "0044715632478",
"Communicationchannelqualifier_02": "TE"
}
}
]
}
]
},
{
"NAD": {
"Partyqualifier_01": "SU",
"PARTYIDENTIFICATIONDETAILS_02": {
"Partyididentification_01": "4012345500004",
"Codelistresponsibleagencycoded_03": "9"
}
},
"RFFLoop": [
{
"RFF": {
"REFERENCE_01": {
"Referencequalifier_01": "VA",
"Referencenumber_02": "56225432"
}
}
}
]
}
],
"CUXLoop": [
{
"CUX": {
"CURRENCYDETAILS_01": {
"Currencydetailsqualifier_01": "2",
"Currencycoded_02": "GBP",
"Currencyqualifier_03": "9"
},
"CURRENCYDETAILS_02": {
"Currencydetailsqualifier_01": "3",
"Currencycoded_02": "EUR",
"Currencyqualifier_03": "4"
},
"Rateofexchange_03": "1.67"
},
"DTM": [
{
"DATETIMEPERIOD_01": {
"Datetimeperiodqualifier_01": "134",
"Datetimeperiod_02": "2002080120020831",
"Datetimeperiodformatqualifier_03": "718"
}
}
]
}
],
"TDTLoop": [
{
"TDT": {
"Transportstagequalifier_01": "20",
"MODEOFTRANSPORT_03": {
"Modeoftransportcoded_01": "30"
},
"TRANSPORTMEANS_04": {
"Typeofmeansoftransportidentification_01": "31"
}
}
}
],
"TODLoop": [
{
"TOD": {
"Termsofdeliveryortransportfunctioncoded_01": "3",
"TERMSOFDELIVERYORTRANSPORT_03": {
"Termsofdeliveryortransportcoded_01": "CIF",
"Codelistqualifier_02": "23",
"Codelistresponsibleagencycoded_03": "9"
}
},
"LOC": [
{
"Placelocationqualifier_01": "1",
"LOCATIONIDENTIFICATION_02": {
"Placelocationidentification_01": "BE-BRU"
}
}
]
}
],
"LINLoop": [
{
"LIN": {
"Lineitemnumber_01": "1",
"ITEMNUMBERIDENTIFICATION_03": {
"Itemnumber_01": "4000862141404",
"Itemnumbertypecoded_02": "SRS"
}
},
"PIA": [
{
"Productidfunctionqualifier_01": "1",
"ITEMNUMBERIDENTIFICATION_02": {
"Itemnumber_01": "ABC1234",
"Itemnumbertypecoded_02": "IN"
}
}
],
"IMD": [
{
"Itemdescriptiontypecoded_01": "C",
"ITEMDESCRIPTION_03": {
"Itemdescriptionidentification_01": "TU",
"Codelistresponsibleagencycoded_03": "9"
}
}
],
"QTY": [
{
"QUANTITYDETAILS_01": {
"Quantityqualifier_01": "21",
"Quantity_02": "48"
}
}
],
"MOA": [
{
"MONETARYAMOUNT_01": {
"Monetaryamounttypequalifier_01": "203",
"Monetaryamount_02": "699.84"
}
}
],
"PRILoop": [
{
"PRI": {
"PRICEINFORMATION_01": {
"Pricequalifier_01": "AAA",
"Price_02": "14.58",
"Pricetypecoded_03": "CT",
"Pricetypequalifier_04": "AAE",
"Unitpricebasis_05": "1",
"Measureunitqualifier_06": "KGM"
}
}
}
],
"RFFLoop": [
{
"RFF": {
"REFERENCE_01": {
"Referencequalifier_01": "PL",
"Referencenumber_02": "AUG93RNG04"
}
},
"DTM": [
{
"DATETIMEPERIOD_01": {
"Datetimeperiodqualifier_01": "171",
"Datetimeperiod_02": "20020801",
"Datetimeperiodformatqualifier_03": "102"
}
}
]
}
],
"PACLoop": [
{
"PAC": {
"Numberofpackages_01": "2",
"PACKAGINGDETAILS_02": {
"Packagingrelatedinformationcoded_02": "51"
},
"PACKAGETYPE_03": {
"Typeofpackagesidentification_01": "CS"
}
},
"PCILoop": [
{
"PCI": {
"Markinginstructionscoded_01": "14"
}
}
]
}
],
"LOCLoop": [
{
"LOC": {
"Placelocationqualifier_01": "7",
"LOCATIONIDENTIFICATION_02": {
"Placelocationidentification_01": "3312345502000",
"Codelistresponsibleagencycoded_03": "9"
}
},
"QTY": {
"QUANTITYDETAILS_01": {
"Quantityqualifier_01": "11",
"Quantity_02": "24"
}
},
"DTM": [
{
"DATETIMEPERIOD_01": {
"Datetimeperiodqualifier_01": "2",
"Datetimeperiod_02": "20020915",
"Datetimeperiodformatqualifier_03": "102"
}
}
]
},
{
"LOC": {
"Placelocationqualifier_01": "7",
"LOCATIONIDENTIFICATION_02": {
"Placelocationidentification_01": "3312345501003",
"Codelistresponsibleagencycoded_03": "9"
}
},
"QTY": {
"QUANTITYDETAILS_01": {
"Quantityqualifier_01": "11",
"Quantity_02": "24"
}
},
"DTM": [
{
"DATETIMEPERIOD_01": {
"Datetimeperiodqualifier_01": "2",
"Datetimeperiod_02": "20020913",
"Datetimeperiodformatqualifier_03": "102"
}
}
]
}
],
"TAXLoop": [
{
"TAX": {
"Dutytaxfeefunctionqualifier_01": "7",
"DUTYTAXFEETYPE_02": {
"Dutytaxfeetypecoded_01": "VAT"
},
"DUTYTAXFEEDETAIL_05": {
"Dutytaxfeerate_04": "17.5"
},
"Dutytaxfeecategorycoded_06": "S"
}
}
]
}
],
"UNS": {
"Sectionidentification_01": "S"
},
"CNT": [
{
"CONTROL_01": {
"Controlqualifier_01": "2",
"Controlvalue_02": "1"
}
}
],
"UNT": {
"NumberofSegmentsinaMessage_01": "38",
"MessageReferenceNumber_02": "000000101"
}
}Parse and validate an ORDERS file
Read the file into typed objects with ediFabric .NET, or post it to the ediFabric Cloud REST API from any language and get JSON back.
using EdiFabric.Templates.EdifactD96A; License.SetSerial("YOUR_SERIAL_KEY"); using (var stream = File.OpenRead(@"C:\edi\PurchaseOrder.txt")) using (var reader = new EdifactReader(stream, "EdiFabric.Templates.Edifact")) { var items = await reader.ReadToEndAsync(); foreach (var transaction in items.OfType<TSORDERS>()) { if (transaction.IsValid(out MessageErrorContext errors)) Console.WriteLine($"{transaction.UNH.MessageReferenceNumber_01} is valid"); else Console.WriteLine(string.Join(Environment.NewLine, errors.Flatten())); } }
curl -X POST 'https://api.edination.com/v2/edifact/read' \ -H 'Ocp-Apim-Subscription-Key: YOUR_SERIAL_KEY' \ -H 'Content-Type: application/octet-stream' \ --data-binary '@PurchaseOrder.txt'
Generate an ORDERS file
Populate a TSORDERS object in .NET, or post JSON in the shape shown above to ediFabric Cloud, and get a valid ORDERS file back.
using EdiFabric.Templates.EdifactD96A; License.SetSerial("YOUR_SERIAL_KEY"); var transaction = new TSORDERS(); // Message header transaction.UNH = new UNH(); transaction.UNH.MessageReferenceNumber_01 = "0001"; transaction.UNH.MessageIdentifier_02 = new S009(); transaction.UNH.MessageIdentifier_02.MessageType_01 = "ORDERS"; transaction.UNH.MessageIdentifier_02.MessageVersionNumber_02 = "D"; transaction.UNH.MessageIdentifier_02.MessageReleaseNumber_03 = "96A"; transaction.UNH.MessageIdentifier_02.ControllingAgencyCoded_04 = "UN"; // Order number 128576 transaction.BGM = new BGM(); transaction.BGM.DOCUMENTMESSAGENAME_01 = new C002(); transaction.BGM.DOCUMENTMESSAGENAME_01.Documentmessagenamecoded_01 = "220"; transaction.BGM.Documentmessagenumber_02 = "128576"; transaction.BGM.Messagefunctioncoded_03 = "9"; // Repeating DTM transaction.DTM = new List<DTM>(); // ... set the remaining loops and segments the same way // SegmentBuilders is in the Common project of the example repository using (var stream = new MemoryStream()) { using (var writer = new EdifactWriter(stream)) { writer.Write(SegmentBuilders.BuildUnb("1")); writer.Write(transaction); } Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray())); }
# the JSON returned by /read, edited or produced by your application curl -X POST 'https://api.edination.com/v2/edifact/write' \ -H 'Ocp-Apim-Subscription-Key: YOUR_SERIAL_KEY' \ -H 'Content-Type: application/json' \ --data-binary '@PurchaseOrder.json' \ -o 'PurchaseOrder.txt'
Complete ediFabric .NET example
A complete C# program for the EDIFACT ORDERS, built on TSORDERS in EdiFabric.Templates.Edifact. The same code is in the ediFabric .NET examples on GitHub.
using EdiFabric.Core.Model.Edi;
using EdiFabric.Core.Model.Edi.Edifact;
using EdiFabric.Framework.Readers;
using EdiFabric.Framework.Writers;
using EdiFabric.Templates.EdifactD96A;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using EdiFabric.Examples.EDIFACT.Common;
namespace EdiFabric.Examples.EDIFACT.ORDERS
{
class Program
{
static void Main(string[] args)
{
SerialKey.Set(Common.SerialKey.Get());
Read();
Write();
}
///
/// Read Purchase Orders
///
static void Read()
{
var ediStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\Edifact\PurchaseOrder.txt");
List ediItems;
using (var ediReader = new EdifactReader(ediStream, "EdiFabric.Templates.Edifact"))
ediItems = ediReader.ReadToEnd().ToList();
var transactions = ediItems.OfType();
foreach (var transaction in transactions)
{
if (transaction.HasErrors)
{
// partially parsed
var errors = transaction.ErrorContext.Flatten();
}
}
}
///
/// Write Purchase Orders
///
static void Write()
{
var transaction = BuildPurchaseOrder("1");
using (var stream = new MemoryStream())
{
using (var writer = new EdifactWriter(stream))
{
writer.Write(SegmentBuilders.BuildUnb("1"));
writer.Write(transaction);
}
var ediString = stream.LoadToString();
}
}
///
/// Build purchase order.
/// Original from https://www.gs1.org/standards/edi-xml-gs1-eancom/eancom-orders-s4/syntax-4
///
public static TSORDERS BuildPurchaseOrder(string controlNumber)
{
var result = new TSORDERS();
// Message header
result.UNH = new UNH();
result.UNH.MessageReferenceNumber_01 = controlNumber.PadLeft(14, '0');
result.UNH.MessageIdentifier_02 = new S009();
result.UNH.MessageIdentifier_02.MessageType_01 = "ORDERS";
result.UNH.MessageIdentifier_02.MessageVersionNumber_02 = "D";
result.UNH.MessageIdentifier_02.MessageReleaseNumber_03 = "96A";
result.UNH.MessageIdentifier_02.ControllingAgencyCoded_04 = "UN";
// Order number 128576
result.BGM = new BGM();
result.BGM.DOCUMENTMESSAGENAME_01 = new C002();
result.BGM.DOCUMENTMESSAGENAME_01.Documentmessagenamecoded_01 = "220";
result.BGM.Documentmessagenumber_02 = "128576";
result.BGM.Messagefunctioncoded_03 = "9";
// Repeating DTM
result.DTM = new List();
// Message date 30th of August 2002
var dtm = new DTM();
dtm.DATETIMEPERIOD_01 = new C507();
dtm.DATETIMEPERIOD_01.Datetimeperiodqualifier_01 = "137";
dtm.DATETIMEPERIOD_01.Datetimeperiod_02 = "20020830";
dtm.DATETIMEPERIOD_01.Datetimeperiodformatqualifier_03 = "102";
result.DTM.Add(dtm);
// Instruction to pay in Bank Account
result.PAI = new PAI();
result.PAI.PAYMENTINSTRUCTIONDETAILS_01 = new C534();
result.PAI.PAYMENTINSTRUCTIONDETAILS_01.Paymentmeanscoded_03 = "42";
// Repeating FTX
result.FTX = new List();
// Free text mutually defined
var ftx = new FTX();
ftx.Textsubjectqualifier_01 = "ZZZ";
ftx.Textfunctioncoded_02 = "1";
ftx.TEXTREFERENCE_03 = new C107();
ftx.TEXTREFERENCE_03.Freetextcoded_01 = "001";
ftx.TEXTREFERENCE_03.Codelistresponsibleagencycoded_03 = "91";
result.FTX.Add(ftx);
// Repeating RFF Groups
result.RFFLoop = new List();
// Begin RFF Group
var rffLoop = new Loop_RFF_ORDERS();
// Order is based on contract number 652744
rffLoop.RFF = new RFF();
rffLoop.RFF.REFERENCE_01 = new C506();
rffLoop.RFF.REFERENCE_01.Referencequalifier_01 = "CT";
rffLoop.RFF.REFERENCE_01.Referencenumber_02 = "652744";
// Repeating DTM
rffLoop.DTM = new List();
// Date of contract 25th of August 2002
var rffDtm1 = new DTM();
rffDtm1.DATETIMEPERIOD_01 = new C507();
rffDtm1.DATETIMEPERIOD_01.Datetimeperiodqualifier_01 = "171";
rffDtm1.DATETIMEPERIOD_01.Datetimeperiod_02 = "20020825";
rffDtm1.DATETIMEPERIOD_01.Datetimeperiodformatqualifier_03 = "102";
rffLoop.DTM.Add(rffDtm1);
// End RFF Group
result.RFFLoop.Add(rffLoop);
// Repeating NAD Groups
result.NADLoop = new List();
// Begin NAD Group 1
var nadLoop1 = new Loop_NAD_ORDERS();
// Buyer is identified by GLN 5412345000013
nadLoop1.NAD = new NAD();
nadLoop1.NAD.Partyqualifier_01 = "BY";
nadLoop1.NAD.PARTYIDENTIFICATIONDETAILS_02 = new C082();
nadLoop1.NAD.PARTYIDENTIFICATIONDETAILS_02.Partyididentification_01 = "5412345000013";
nadLoop1.NAD.PARTYIDENTIFICATIONDETAILS_02.Codelistresponsibleagencycoded_03 = "9";
// Repeating RFF Groups
nadLoop1.RFFLoop = new List();
// Begin RFF Group
var rffLoopNad = new Loop_RFF_ORDERS();
// Buyer’s VAT number is 87765432
rffLoopNad.RFF = new RFF();
rffLoopNad.RFF.REFERENCE_01 = new C506();
rffLoopNad.RFF.REFERENCE_01.Referencequalifier_01 = "VA";
rffLoopNad.RFF.REFERENCE_01.Referencenumber_02 = "87765432";
// End RFF Group
nadLoop1.RFFLoop.Add(rffLoopNad);
// Repeating CTA Groups
nadLoop1.CTALoop = new List();
// Begin CTA Group
var ctaLoop = new Loop_CTA_ORDERS();
// Order contact is PForget
ctaLoop.CTA = new CTA();
ctaLoop.CTA.Contactfunctioncoded_01 = "OC";
ctaLoop.CTA.DEPARTMENTOREMPLOYEEDETAILS_02 = new C056();
ctaLoop.CTA.DEPARTMENTOREMPLOYEEDETAILS_02.Departmentoremployee_02 = "P FORGET";
// Repeating COM
ctaLoop.COM = new List();
// Telephone number of order contact
var com = new COM();
com.COMMUNICATIONCONTACT_01 = new C076();
com.COMMUNICATIONCONTACT_01.Communicationnumber_01 = "0044715632478";
com.COMMUNICATIONCONTACT_01.Communicationchannelqualifier_02 = "TE";
ctaLoop.COM.Add(com);
// End CTA Group
nadLoop1.CTALoop.Add(ctaLoop);
// End NAD Group 1
result.NADLoop.Add(nadLoop1);
// Begin NAD Group 2
var nadLoop2 = new Loop_NAD_ORDERS();
// Supplier is identified by GLN 4012345500004
nadLoop2.NAD = new NAD();
nadLoop2.NAD.Partyqualifier_01 = "SU";
nadLoop2.NAD.PARTYIDENTIFICATIONDETAILS_02 = new C082();
nadLoop2.NAD.PARTYIDENTIFICATIONDETAILS_02.Partyididentification_01 = "4012345500004";
nadLoop2.NAD.PARTYIDENTIFICATIONDETAILS_02.Codelistresponsibleagencycoded_03 = "9";
// Repeating RFF Groups
nadLoop2.RFFLoop = new List();
// Begin RFF Group
var rffLoopNad2 = new Loop_RFF_ORDERS();
// Supplier’s VAT number is 56225432
rffLoopNad2.RFF = new RFF();
rffLoopNad2.RFF.REFERENCE_01 = new C506();
rffLoopNad2.RFF.REFERENCE_01.Referencequalifier_01 = "VA";
rffLoopNad2.RFF.REFERENCE_01.Referencenumber_02 = "56225432";
// End RFF Group
nadLoop2.RFFLoop.Add(rffLoopNad2);
// End NAD Group 2
result.NADLoop.Add(nadLoop2);
// Repeating CUX Groups
result.CUXLoop = new List();
// Begin CUX Group
var cuxLoop = new Loop_CUX_ORDERS();
// Ordering currency is Pounds Sterling with the invoicing currency identified as Euros
// The exchange rate between them is 1 Pound Sterling equals 1.67 Euros
cuxLoop.CUX = new CUX();
cuxLoop.CUX.CURRENCYDETAILS_01 = new C504();
cuxLoop.CUX.CURRENCYDETAILS_01.Currencydetailsqualifier_01 = "2";
cuxLoop.CUX.CURRENCYDETAILS_01.Currencycoded_02 = "GBP";
cuxLoop.CUX.CURRENCYDETAILS_01.Currencyqualifier_03 = "9";
cuxLoop.CUX.CURRENCYDETAILS_02 = new C504();
cuxLoop.CUX.CURRENCYDETAILS_02.Currencydetailsqualifier_01 = "3";
cuxLoop.CUX.CURRENCYDETAILS_02.Currencycoded_02 = "EUR";
cuxLoop.CUX.CURRENCYDETAILS_02.Currencyqualifier_03 = "4";
cuxLoop.CUX.Rateofexchange_03 = "1.67";
// Repeating DTM
cuxLoop.DTM = new List();
// Period on which rate of exchange date is based is the
// 1st of August 2002 - 31st of August 2002
var dtmCux = new DTM();
dtmCux.DATETIMEPERIOD_01 = new C507();
dtmCux.DATETIMEPERIOD_01.Datetimeperiodqualifier_01 = "134";
dtmCux.DATETIMEPERIOD_01.Datetimeperiod_02 = "2002080120020831";
dtmCux.DATETIMEPERIOD_01.Datetimeperiodformatqualifier_03 = "718";
cuxLoop.DTM.Add(dtmCux);
// End CUX Group
result.CUXLoop.Add(cuxLoop);
// Repeating TDT Groups
result.TDTLoop = new List();
// Begin TDT Group
var tdtLoop = new Loop_TDT_ORDERS();
// Order requests that the main carriage transport used to deliver the goods is a truck
tdtLoop.TDT = new TDT();
tdtLoop.TDT.Transportstagequalifier_01 = "20";
tdtLoop.TDT.MODEOFTRANSPORT_03 = new C220();
tdtLoop.TDT.MODEOFTRANSPORT_03.Modeoftransportcoded_01 = "30";
tdtLoop.TDT.TRANSPORTMEANS_04 = new C228();
tdtLoop.TDT.TRANSPORTMEANS_04.Typeofmeansoftransportidentification_01 = "31";
// End TDT Group
result.TDTLoop.Add(tdtLoop);
// Repeating TOD Groups
result.TODLoop = new List();
// Begin TOD Group
var todLoop = new Loop_TOD_ORDERS();
// Terms of delivery are to be Cost, Insurance and Freight
todLoop.TOD = new TOD();
todLoop.TOD.Termsofdeliveryortransportfunctioncoded_01 = "3";
todLoop.TOD.TERMSOFDELIVERYORTRANSPORT_03 = new C100();
todLoop.TOD.TERMSOFDELIVERYORTRANSPORT_03.Termsofdeliveryortransportcoded_01 = "CIF";
todLoop.TOD.TERMSOFDELIVERYORTRANSPORT_03.Codelistqualifier_02 = "23";
todLoop.TOD.TERMSOFDELIVERYORTRANSPORT_03.Codelistresponsibleagencycoded_03 = "9";
// Repeating LOC Group
todLoop.LOC = new List();
// The named port is Brussels
var loc = new LOC();
loc.Placelocationqualifier_01 = "1";
loc.LOCATIONIDENTIFICATION_02 = new C517();
loc.LOCATIONIDENTIFICATION_02.Placelocationidentification_01 = "BE-BRU";
todLoop.LOC.Add(loc);
// End TOD Group
result.TODLoop.Add(todLoop);
// Repeating LIN Groups
result.LINLoop = new List();
// Begin LIN Group 1
var linLoop1 = new Loop_LIN_ORDERS();
// First product order is identified by GTIN 4000862141404
linLoop1.LIN = new LIN();
linLoop1.LIN.Lineitemnumber_01 = "1";
linLoop1.LIN.ITEMNUMBERIDENTIFICATION_03 = new C212();
linLoop1.LIN.ITEMNUMBERIDENTIFICATION_03.Itemnumber_01 = "4000862141404";
linLoop1.LIN.ITEMNUMBERIDENTIFICATION_03.Itemnumbertypecoded_02 = "SRS";
// Repeating PIA
linLoop1.PIA = new List();
// In addition the buyer’s part number ABC1234 is provided
var pia = new PIA();
pia.Productidfunctionqualifier_01 = "1";
pia.ITEMNUMBERIDENTIFICATION_02 = new C212();
pia.ITEMNUMBERIDENTIFICATION_02.Itemnumber_01 = "ABC1234";
pia.ITEMNUMBERIDENTIFICATION_02.Itemnumbertypecoded_02 = "IN";
linLoop1.PIA.Add(pia);
// Repeating IMD
linLoop1.IMD = new List();
// The ordered item is a traded unit
var imd = new IMD();
imd.Itemdescriptiontypecoded_01 = "C";
imd.ITEMDESCRIPTION_03 = new C273();
imd.ITEMDESCRIPTION_03.Itemdescriptionidentification_01 = "TU";
imd.ITEMDESCRIPTION_03.Codelistresponsibleagencycoded_03 = "9";
linLoop1.IMD.Add(imd);
// Repeating QTY
linLoop1.QTY = new List();
// Ordered quantity is 48 units
var qty = new QTY();
qty.QUANTITYDETAILS_01 = new C186();
qty.QUANTITYDETAILS_01.Quantityqualifier_01 = "21";
qty.QUANTITYDETAILS_01.Quantity_02 = "48";
linLoop1.QTY.Add(qty);
// Repeating MOA
linLoop1.MOA = new List();
// Value of order line is 699.84 Pounds Sterling
var moa = new MOA();
moa.MONETARYAMOUNT_01 = new C516();
moa.MONETARYAMOUNT_01.Monetaryamounttypequalifier_01 = "203";
moa.MONETARYAMOUNT_01.Monetaryamount_02 = "699.84";
linLoop1.MOA.Add(moa);
// Repeating PRI Groups
linLoop1.PRILoop = new List();
// Begin PRI Group
var priLoop = new Loop_PRI_ORDERS();
// Fixed net calculation price is 14.58 Pounds Sterling
priLoop.PRI = new PRI();
priLoop.PRI.PRICEINFORMATION_01 = new C509();
priLoop.PRI.PRICEINFORMATION_01.Pricequalifier_01 = "AAA";
priLoop.PRI.PRICEINFORMATION_01.Price_02 = "14.58";
priLoop.PRI.PRICEINFORMATION_01.Pricetypecoded_03 = "CT";
priLoop.PRI.PRICEINFORMATION_01.Pricetypequalifier_04 = "AAE";
priLoop.PRI.PRICEINFORMATION_01.Unitpricebasis_05 = "1";
priLoop.PRI.PRICEINFORMATION_01.Measureunitqualifier_06 = "KGM";
// End PRI Group
linLoop1.PRILoop.Add(priLoop);
// Repeating RFF Groups
linLoop1.RFFLoop = new List();
// Begin RFF Group
var rffLoopLin = new Loop_RFF_ORDERS();
// Price is taken from the price list AUG93RNG04
rffLoopLin.RFF = new RFF();
rffLoopLin.RFF.REFERENCE_01 = new C506();
rffLoopLin.RFF.REFERENCE_01.Referencequalifier_01 = "PL";
rffLoopLin.RFF.REFERENCE_01.Referencenumber_02 = "AUG93RNG04";
// Repeating DTM
rffLoopLin.DTM = new List();
// Price list date 1st of August 2002
var dtmRff = new DTM();
dtmRff.DATETIMEPERIOD_01 = new C507();
dtmRff.DATETIMEPERIOD_01.Datetimeperiodqualifier_01 = "171";
dtmRff.DATETIMEPERIOD_01.Datetimeperiod_02 = "20020801";
dtmRff.DATETIMEPERIOD_01.Datetimeperiodformatqualifier_03 = "102";
rffLoopLin.DTM.Add(dtmRff);
// End RFF Group
linLoop1.RFFLoop.Add(rffLoopLin);
// Repeating PAC Groups
linLoop1.PACLoop = new List();
// Begin PAC Group
var pacLoop = new Loop_PAC_ORDERS_2();
// Two packages (cases) barcoded with ITF14
pacLoop.PAC = new PAC();
pacLoop.PAC.Numberofpackages_01 = "2";
pacLoop.PAC.PACKAGINGDETAILS_02 = new C531();
pacLoop.PAC.PACKAGINGDETAILS_02.Packagingrelatedinformationcoded_02 = "51";
pacLoop.PAC.PACKAGETYPE_03 = new C202();
pacLoop.PAC.PACKAGETYPE_03.Typeofpackagesidentification_01 = "CS";
// Repeating PCI Groups
pacLoop.PCILoop = new List();
// Begin PCI Group
var pciLoop = new Loop_PCI_ORDERS();
// The expiry date of the product is to be marked on it's packaging
pciLoop.PCI = new PCI();
pciLoop.PCI.Markinginstructionscoded_01 = "14";
// End PCI Group
pacLoop.PCILoop.Add(pciLoop);
// End PAC Group
linLoop1.PACLoop.Add(pacLoop);
// Repeating LOC Groups
linLoop1.LOCLoop = new List();
// Begin LOC Group 1
var locLoop1 = new Loop_LOC_ORDERS_2();
// The second place to which the product is to be delivered is identified by GLN 3312345502000
locLoop1.LOC = new LOC();
locLoop1.LOC.Placelocationqualifier_01 = "7";
locLoop1.LOC.LOCATIONIDENTIFICATION_02 = new C517();
locLoop1.LOC.LOCATIONIDENTIFICATION_02.Placelocationidentification_01 = "3312345502000";
locLoop1.LOC.LOCATIONIDENTIFICATION_02.Codelistresponsibleagencycoded_03 = "9";
// The quantity to be delivered at this location is 24
locLoop1.QTY = new QTY();
locLoop1.QTY.QUANTITYDETAILS_01 = new C186();
locLoop1.QTY.QUANTITYDETAILS_01.Quantityqualifier_01 = "11";
locLoop1.QTY.QUANTITYDETAILS_01.Quantity_02 = "24";
// Repeating DTM
locLoop1.DTM = new List();
// The quantity should be delivered on the 15th of September 2002
var dtmLoc = new DTM();
dtmLoc.DATETIMEPERIOD_01 = new C507();
dtmLoc.DATETIMEPERIOD_01.Datetimeperiodqualifier_01 = "2";
dtmLoc.DATETIMEPERIOD_01.Datetimeperiod_02 = "20020915";
dtmLoc.DATETIMEPERIOD_01.Datetimeperiodformatqualifier_03 = "102";
locLoop1.DTM.Add(dtmLoc);
// End LOC Group 1
linLoop1.LOCLoop.Add(locLoop1);
// Begin LOC Group 2
var locLoop2 = new Loop_LOC_ORDERS_2();
// The first place to which the product is to be delivered is identified by GLN 3312345501003
locLoop2.LOC = new LOC();
locLoop2.LOC.Placelocationqualifier_01 = "7";
locLoop2.LOC.LOCATIONIDENTIFICATION_02 = new C517();
locLoop2.LOC.LOCATIONIDENTIFICATION_02.Placelocationidentification_01 = "3312345501003";
locLoop2.LOC.LOCATIONIDENTIFICATION_02.Codelistresponsibleagencycoded_03 = "9";
// The quantity to be delivered at this location is 24
locLoop2.QTY = new QTY();
locLoop2.QTY.QUANTITYDETAILS_01 = new C186();
locLoop2.QTY.QUANTITYDETAILS_01.Quantityqualifier_01 = "11";
locLoop2.QTY.QUANTITYDETAILS_01.Quantity_02 = "24";
// Repeating DTM
locLoop2.DTM = new List();
// The quantity should be delivered on the 13th of September 2002
var dtmLoc2 = new DTM();
dtmLoc2.DATETIMEPERIOD_01 = new C507();
dtmLoc2.DATETIMEPERIOD_01.Datetimeperiodqualifier_01 = "2";
dtmLoc2.DATETIMEPERIOD_01.Datetimeperiod_02 = "20020913";
dtmLoc2.DATETIMEPERIOD_01.Datetimeperiodformatqualifier_03 = "102";
locLoop2.DTM.Add(dtmLoc2);
// End LOC Group 2
linLoop1.LOCLoop.Add(locLoop2);
// Repeating TAX Groups
linLoop1.TAXLoop = new List();
// Begin TAX Group
var taxLoop = new Loop_TAX_ORDERS();
// The product is subject to the standard VAT rate of 17.5%
taxLoop.TAX = new TAX();
taxLoop.TAX.Dutytaxfeefunctionqualifier_01 = "7";
taxLoop.TAX.DUTYTAXFEETYPE_02 = new C241();
taxLoop.TAX.DUTYTAXFEETYPE_02.Dutytaxfeetypecoded_01 = "VAT";
taxLoop.TAX.DUTYTAXFEEDETAIL_05 = new C243();
taxLoop.TAX.DUTYTAXFEEDETAIL_05.Dutytaxfeerate_04 = "17.5";
taxLoop.TAX.Dutytaxfeecategorycoded_06 = "S";
// End TAX Group
linLoop1.TAXLoop.Add(taxLoop);
// End LIN Group 1
result.LINLoop.Add(linLoop1);
// Message detail/summary separator
result.UNS = new UNS();
result.UNS.Sectionidentification_01 = "S";
// Repeating CNT
result.CNT = new List();
// Count of the number of LIN segments in the message
var cnt = new CNT();
cnt.CONTROL_01 = new C270();
cnt.CONTROL_01.Controlqualifier_01 = "2";
cnt.CONTROL_01.Controlvalue_02 = "1";
result.CNT.Add(cnt);
return result;
}
}
}More operations in ediFabric .NET
- Parse EDIFACT files
- Generate EDIFACT files
- Validate EDIFACT messages
- Generate EDIFACT acknowledgments
- Save EDIFACT files to DB
- Convert between EDIFACT and JSON
- Convert between EDIFACT and XML
Template and sample downloads
ediFabric .NET parses, validates and generates the EDIFACT ORDERS with TSORDERS in EdiFabric.Templates.Edifact. The template ships in the NuGet package; download the source to adapt it to a trading partner's implementation guide.
- EF_EDIFACT_D96A_Codes.cs 35.3 KB
- EF_EDIFACT_D96A_ComplexElements.cs 71.2 KB
- EF_EDIFACT_D96A_Segments.cs 38.2 KB
- EF_EDIFACT_D96A_ORDERS.cs 31.3 KB
ORDERS questions
What is the difference between EDIFACT ORDERS and EANCOM ORDERS?
EANCOM is the GS1 subset of EDIFACT. EANCOM ORDERS uses the same segments but only those GS1 users need, with GS1 identifiers such as GLN and GTIN.
What does UNS mean in an ORDERS message?
UNS+S separates the header section from the detail section. Everything after it belongs to the line items until the summary section.
What is the X12 equivalent?
The X12 850 purchase order.
How do I parse and generate EDIFACT ORDERS files in .NET?
In .NET, install EdiFabric and EdiFabric.Templates.Edifact, read the file with EdifactReader into TSORDERS objects and write them back with EdifactWriter. From any other language, post the file to the ediFabric Cloud REST API, which returns the same structure as JSON and converts JSON back to EDIFACT.
Resources
Parse your first EDIFACT ORDERS in five minutes
The Community plan is free forever and needs no credit card. It includes ediFabric .NET, Native and Cloud with one serial key.
Sign up free Validate EDI files free