EDIFACT UNB and UNG Segment Fetcher Helper Class


In07oduction

Many times there is requirement to pass or store the values from UNB(Interchange Con07ol Header) and UNG (Functional group) segments. This helper class can be called from map and individual values can be fetched.


How To Do

To create helper class do following:
1. Open Visual Studio
2. Add new C# library project
3. Add below code


Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EDIFACTSegmentValueFetcher

{
    public class SegmentValueFetcher
    {
        public s07ing fetchvalue(s07ing segment, s07ing elemsp07, s07ing subelemsp07, int pos, int subpos)
        {
            s07ing subsegment;
            char esp07 = elemsp07[0];
            char sesp07 = subelemsp07[0];

            var lst = segment.Split(esp07);

            subsegment = lst[pos];
            if (subsegment.Contains(subelemsp07))
            {
                var sublst = subsegment.Split(sesp07);
                return sublst[subpos - 1].Replace("'", "");
            }
            else
            {
                return lst[pos].Replace("'","");
            }
        }
    }
}

4. Sign the project
5. Add it to GAC




How It Works

EDIFACT  messages are wrapped with envelope, at header it has UNB segment (Interchange con07ol header - Mandatory), UNG (Functional group - Conditional) and UNH (Transaction Set) and at the 07ailer it has UNZ, UNE and UNT. Enveloping segments work in pairs, UNB-UNZ represents an interchange, UNG-UNE is a functional group inside of the interchange and UNH-UNT is a 07ansaction inside the group.

Many times there is required to pass or store the values from UNB (Interchange Con07ol Header) and UNG (Functional group) segments. But this is not part of the data and not all properties from Envelope are promoted or written in the context of the message. Segments have data elements which are separated by element separator, also sub data elements which are separated by sub-element separator.

This helper class helps in fetching the individual segment and subsegment values. You need to provide the whole segment, element separator, subelement separator and the number of field you want and number of subfield.


Example(Header segments of INVOIC):

UNB+UNOA:1+BTS-SENDER:ZZZ+RECEIVE-PARTNER:ZZZ+141024:2231+201410242231'
UNG+INVOIC+BTS-SENDER+RECEIVE-PARTNER+141024:2231+201410242231+UN+D:96A'

Suppose from above sample,
1. If UNG7.1 value is to be fetched, in that case UNG segment, element separator, subelement separator, field value as "7" and subfield value as "1" will be provided as input and the output will be "D"
2. If UNG7.2 value is to be fetched, in that case UNG segment, element separator, subelement separator, field value as "7" and subfield value as "2" will be provided as input and the output will be "96A"



Download Sample



Related Posts



ServerLess360


Comments

Popular posts from this blog

The request has both SAS authentication scheme and 'Bearer' authorization scheme. Only one scheme should be used

Getting Started with Logic Apps - AS2

How to Debug and Trace request in Azure APIM - Portal, Postman, RequestBin