MEC: How to Set Message Counter for EDI Message


When you sending/creating EDI messages it is necessary to include 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 need to be persistent. The middleware we are using for EDI transformation should cater this requirement. I used MS-BizTalk  Server for two EDI projects, which cater 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 parnter 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 parnter 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 OK, you will return the new counter other wise –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

Comments

Popular posts from this blog

IIS 7.5: 401 Unauthorized Access Error (Keep prompting Username/password)

Calculating Elapsed Time Accurately (C#)

Connecting DB2/iSeries From .net Application