65.9K
CodeProject is changing. Read more.
Home

MEC: How to Set Message Counter for EDI Message

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Sep 6, 2016

CPOL

1 min read

viewsIcon

7264

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.
    MessageCounter mc = new MessageCounter(myMap);
  2. Get a new counter value using one of 3 overloads:
    /*
    * getNewValue(String counterId)
    * counterID = Choose suitable name (max 20 chars)
    *
    * Returns new counter for the map
    */
     String newVal = mc.getNewValue("MsgCounter");

    or:

    /*
    * 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:

    /*
    * 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