Click here to Skip to main content
15,881,281 members
Articles
Tip/Trick
(untagged)

MEC: How to Set Message Counter for EDI Message

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
5 Sep 2016CPOL1 min read 7K   2
How to set message counter for EDI message

When you are sending/creating EDI messages, it is necessary to include a unique message interchange number. This is to ensure each message that we are sending is unique.

In EANCOM/EDIFACT

Element 0020 of UNB segment:

UNB+UNOA:4+xxxxxxx:14+xxxxxx+20160905:0831+00000000000057+    +ORDERS++1'

In X12

Element ISA13 of ISA segment:

ISA*00* *00* *ZZ*167520391 *ZZ*39319445 *991201*1248*U*00200*000000001*0*P*>

This number needs to be persistent. The middleware we are using for EDI transformation should cater to this requirement. I used MS-BizTalk  Server for two EDI projects, which cater to the same (just by a configuration).

M3 e-Collaborator (MEC) does the same thing in a different way. In the MEC, database (e.g. MEC_Storage_TST) has a table (UTIL_Message_Counters) for this purpose.

Table structure is like this:

image

Note 1: To be able to use this class, you must first create this table (use the SQL script MeC_Utilities_db_script.sql).

You don’t have to enter a record or write code to save/get data. Instead, you have to write 2 lines of Java code in your mapper to get the Value (Unique Message Interchange Number).

Note 2: Values in Key fields are case sensitive.

Steps

  1. Initialize the message counter for the map.
    myMap is reference to the Map.
    C#
    MessageCounter mc = new MessageCounter(myMap);
  2. Get a new counter value using one of 3 overloads:
    C#
    /*
    * getNewValue(String counterId)
    * counterID = Choose suitable name (max 20 chars)
    *
    * Returns new counter for the map
    */
     String newVal = mc.getNewValue("MsgCounter");

    or:

    C#
    /*
    * getNewValue(String counterId, int keyFields);
    * counterID = Choose suitable name (max 20 chars)
    *
    * Returns new counter for the map AND partner ID
    */
     String newVal = mc.getNewValue("MsgCounter",mc.MAP_NAME + mc.PARTNER_ID);

    or:

    C#
    /*
    * getNewValue(String counterId, int keyFields, String cono, String divi, String date) 
    * counterID = Choose suitable name (max 20 chars)
    *
    * Returns new counter for the map AND partner ID AND cono AND divi AND date.
    * you can omit cono and divi by setting null 
    * below code resets the counter for each day (format CCYYMMDD).
    */
     String newVal = mc.getNewValue("MsgCounter",mc.MAP_NAME + mc.PARTNER_ID, null, null, DATE);

If everything is OK, you will return the new counter, otherwise –1.

If you look at the table (UTIL_Message_Counters), a record has been added and value will be incremented each time when getNewValue() is called.

image

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Brandix Lanka Pvt Ltd.
Sri Lanka Sri Lanka
I’ve started my career in 2001 with Microsoft .net ver 1.0. I’m a MCSD for .net.

Currently, I’m working for Sri Lanka’s largest apparel exporter as a Software Engineer. All projects in .net, MS Sql Server, Biztalk Server, WCF and WPF. And also, I’m developing components to the ERP. In addition to that, I’ve involved to create architecture of ERP integration.

Comments and Discussions

 
QuestionGood point however .net EDI libraries like RDPCrystal EDI Library can... Pin
FatCatProgrammer11-Jul-17 2:55
FatCatProgrammer11-Jul-17 2:55 
Good point however .net EDI libraries like RDPCrystal EDI Library can generate these ids for you
Relativity

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.