Free EDI Training Guide
Careers | Contact | About | Home
Amosoft EDI Services Call (800) 761-4269 Login
EDI Loops

EDI Loops - How to identify END of an EDI X12 Loop?
In order to identify the end of an EDI Loop you must remember a few EDI-Loops Rules
Rule #1: Each Loop has Loop ID and may contain one or more Segments
Rule #2: Each Loop has only one segment that is defined as a starting loop
Rule #3: Each Loop MUST start with the segment that was defined as the starting segment for that loop, even if this segment is optional!
Rule #4: Each Loop may have a parent Loop ID for nesting purpose
Rule #5: Each Nested Loop must have a parent Loop ID
Rule #6: Not all Loops have parent Loop ID, but if they do, they MUST show up only as nested loops within their parent loop, they can NOT be independent!
Rule #7: Loops that don't have parent Loop ID can't be nested within other loops
Rule #8: Loop ID can NOT be nested within the same Loop ID

These EDI-Loops Rules are extremely important in order to understand EDI-Loops and how they work, since EDI-Loops don't have start/end tags to help us identify it segments and nested loops.

Now, How to find the end of the EDI-Loop?
Finding the End of an EDI-Loop is not strait forward as the beginning of the Loop, however, you have to use few steps in order to identify the end of the loop.
I'll use a very common Loop ID in most cases, Loop ID=N1, for loop that contain the segments N1, N2, N3, N4 (used in Transaction Set 850, i.e. Purchase Order)
These segments used to identify a party by type of organization, name, and code
N1 contain Company Name
N2 contain Additional Name information
N3 contain Address Information
N4 contain Geographic Location

Step #1: For each segment in the Transaction Set, find the Loop ID, you can tell if a segment belong to a loop by looking at it Loop ID in the implementation guideline or in the EDI data dictionary, some companies use SEF files, so whatever your using, get the current segment Loop ID
Step #2: If Loop ID exists for that segment then find the segment name that start this Loop ID (Rule #2)
Step #3: Now, since we know the Loop ID (we found it on step 2), then we can keep reading the next Segments and test each one of them with the rules from above:
  • 1. if we run into a segment that has no Loop ID, the previous segment may be the end of our loop
  • 2. if we run into a segment with the same Loop ID as ours and segment name is the starting segment of that loop, it means that this is a beginning of new loop (Rule #8), so the end of our loop may be the previous segment of the new Loop
  • 3. if we run into a segment with different Loop ID then ours and parent Loop ID is different then ours it can mean two things:
    • 3.1 This segment is the beginning of new Loop - Nested within our Loop
    • 3.2 This segment is the beginning of new Loop - Not Nested within our Loop

To find out which one of the two cases that segment is, we have to climb up the Loop levels until we find a Loop that doesn't have a parent Loop ID, And while we were climbing up the Loop level, the Loop Parent ID was NOT equal to our Loop ID (because that would mean that this Loop is nested within our loop).
When we find such segment, it means that this is a beginning of new loop (Rule #6), so the end of our loop may be the previous segment of the new Loop.

Once we found if its Nested within our Loop or Not we do one of the following:
  • 3.1 (continued) - This segment can NOT be a sign for the end of our Loop
  • 3.2 (continued) - This segment may be the end of our Loop

Out of all these segments, the First segment right after our segment, is the end of our Loop

How to climb up the Loop levels?
For every segment that we visit, we have to find out if it has Loop ID. If it does, then we can look up in the EDI-Dictionary, what is the segment Loop ID and what segment is the first segment that should show up on every Loop instance, that fisrt segment is our way to climb up in the Loop levels. Once we have the first element, we can ask who is the Parent Loop ID of this first segment?
The Parent Loop ID will help us climb up the Loop level. When we find the Parent Loop ID of the first segment of Our Loop, we can search up all the previous segments and test if they have Loop ID, and if they do, then is that Loop ID equal to Our Parent Loop ID, once we find such segment, we can repeat the whole process with same question, until we run into segment that does not have any Parent Loop ID, that is when we know that we are at the root level of the transaction set.

EDI Software & Services   EDI Industries EDI Resources
EDI Software EDI Integration EDI for Retailers EDI Articles
Web Based EDI Solution EDI Outsourcing EDI for Suppliers EDI Documents
AS2 Software EDI Consulting EDI for Manufacturers Partners
ASN Software VAN Services EDI for Grocery Success Stories
QuickBooks EDI Software   EDI for Food Brokers EDI Overview
Microsoft Dynamics AX EDI Software   EDI for Logistics The Future of EDI
Microsoft Dynamics GP EDI Software   EDI Healthcare Supply Why should I use EDI?
Microsoft Dynamics SL EDI Software   EDI HIPAA More about EDI
Microsoft Dynamics NAV EDI Software     ASC-X12
SAP Business One EDI Software     DISA
SAP R/3 EDI Software     HIPAA
Oracle JD Edwards EDI Software     EDI Standards
Epicor Retail EDI Software     Employment Opportunities
Sage MAS 90 EDI Software      
Sage MAS 200 EDI Software      
Sage MAS 500 EDI Software      
Sage PFW ERP EDI Software      
Sage Accpac ERP EDI Software      
Sage Pro ERP EDI Software      

Get more business with EDI Outsourcing quote-blue.png
or call us (310) 862-4259

From our News

EDI Outsourcing: Outsource EDI Project
There are many benefits of EDI, and one of the most conspicuous benefits of EDI is that it is the safest way of transferring data and information to the recipients. Now, the web based EDI service is used comprehensively by the business companies across the world. However,

11601 Wilshire Blvd. Suite 500

Los Angeles, CA 90025

Sales Inquiries: +1 800-761-4268

Contact Us arrow-yellow.gif