Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
maxi1555
Contributor
0 Kudos
Hi experts,

I’m writing this post because SAP provide only 18 message definitions for X12 version 004010, I'm talking about the following XSDs:



if you are one of those who have seen that list and you have cried, this blog is for you!

 

My first questions about this was:

  • What would happen if I created my own X12 message?

  • Would it work?


Then I started to analyze the XSDs and found a pattern, and I created my own XSD and It worked:



We are able to create any message of X12 version 004010!, so the next questions came to my head:

  • Will I need to create the X12 version 004010 messages from scratch ?

  • Where can I find the definitions?


If you look at the XSDs provided by SAP, they have thousands of definition lines, it is not an option create it from scratch, but if you have a SAP PO system with the B2B addon you have all the XSDs in other format.

After analyzing the XSDs provided by SAP PO I found a pattern,so understanding the patterns of the SAP PO XSDs and the patterns of the CPI XSDs I have created the following script to convert the SAP PO XSDs in CPI XSDs:
class test {
static main(args) {
def msgNumber = "920"//You have to know it!
def docNumber = "S_F01/D_67"//You have to find it!
def msgName = "Claimant"//You have to find it!
//We read the input files, SAP PO XSD & CPI XSD TEMPLATE
def PI_XSD_STRING = new File("src/PI_XSD").getText("UTF-8").replaceAll("[\n\r\t]", "")//we need a flat string
def CPI_RESULT_XSD_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:hci=\"http://sap.com/hci\" xmlns:ica=\"http://www.sap.com/ica/metameta_schema/metainfo\"><xsd:complexType name=\"M_XXX\"><xsd:sequence><xsd:element name=\"S_ST\"><xsd:complexType><xsd:sequence><xsd:element name=\"D_143\"><xsd:simpleType><xsd:restriction base=\"xsd:token\"><xsd:length value=\"3\"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name=\"D_329\"><xsd:simpleType><xsd:restriction base=\"xsd:string\"><xsd:minLength value=\"4\"/><xsd:maxLength value=\"9\"/></xsd:restriction></xsd:simpleType></xsd:element></xsd:sequence></xsd:complexType></xsd:element>CONTENT<xsd:element name=\"S_SE\"><xsd:annotation><xsd:documentation>Transaction Set Trailer. To indicate the end of the transaction set and provide the count of the transmitted segments (including the beginning (ST) and ending (SE) segments) CONTROL SEGMENT</xsd:documentation></xsd:annotation><xsd:complexType><xsd:sequence><xsd:element name=\"D_96\"><xsd:annotation><xsd:documentation>SE01 | Number of Included Segments</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base=\"xsd:string\"><xsd:minLength value=\"1\"/><xsd:maxLength value=\"10\"/></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name=\"D_329\"><xsd:annotation><xsd:documentation>SE02 | Transaction Set Control Number</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base=\"xsd:string\"><xsd:minLength value=\"4\"/><xsd:maxLength value=\"9\"/></xsd:restriction></xsd:simpleType></xsd:element></xsd:sequence></xsd:complexType></xsd:element></xsd:sequence></xsd:complexType><xsd:element name=\"M_XXX\" type=\"M_XXX\"><xsd:annotation><xsd:appinfo><hci:resourceinfo><hci:info key=\"typeSystem\" value=\"ASC-X12\"/><hci:info key=\"typeSystemVersion\" value=\"004010\"/><hci:info key=\"category\" value=\"Template\"/><hci:info key=\"rootNode\" value=\"M_XXX\"/><hci:info key=\"responsibleAgencyName\" value=\"Accredited Standards Committee X12\"/><hci:info key=\"responsibleAgencyCode\" value=\"116\"/><hci:info key=\"messageType\" value=\"XXX\"/><hci:info key=\"messageName\" value=\"MESSAGE_NAME\"/><hci:info key=\"documentNumber\" value=\"M_XXX/XPATH_TO_DOCUMENT_NUMBER\"/></hci:resourceinfo></xsd:appinfo></xsd:annotation></xsd:element></xsd:schema>"
//We change the message number and anothers fields
CPI_RESULT_XSD_STRING = CPI_RESULT_XSD_STRING.replaceAll("XXX",msgNumber);
CPI_RESULT_XSD_STRING = CPI_RESULT_XSD_STRING.replaceAll("XPATH_TO_DOCUMENT_NUMBER",docNumber);
CPI_RESULT_XSD_STRING = CPI_RESULT_XSD_STRING.replaceAll("MESSAGE_NAME",msgName);
//We extract the usefull content from SAP PO XSD, This begins after D_329 field and ends before S_SE segment
def CONTENT_BEGIN_STRING = "<xsd:element name=\"D_329\"><xsd:annotation><xsd:documentation>ST02 | Transaction Set Control Number</xsd:documentation></xsd:annotation><xsd:simpleType><xsd:restriction base=\"xsd:string\"><xsd:minLength value=\"4\"/><xsd:maxLength value=\"9\"/></xsd:restriction></xsd:simpleType></xsd:element>"
def CONTENT_END_STRING = "<xsd:element name=\"S_SE\">"
def CONTENT_BEGIN_INDEX_INT = PI_XSD_STRING.indexOf(CONTENT_BEGIN_STRING)+CONTENT_BEGIN_STRING.length()
def CONTENT_END_INDEX_INT = PI_XSD_STRING.indexOf(CONTENT_END_STRING);
def CONTENT_STRING = PI_XSD_STRING.substring(CONTENT_BEGIN_INDEX_INT, CONTENT_END_INDEX_INT)
//We put the content extracted from SAP PO XSD into CPI XSD
CPI_RESULT_XSD_STRING = CPI_RESULT_XSD_STRING.replaceAll("CONTENT",CONTENT_STRING)
//We need to adjust the name of group of segments, in SAP PO those start with "L_", followed of numbers in some cases,
//but in CPI those start with "G_" followed of the name of the first segment inside of it
def GROUP_SEGMENT_ID_STRING = "L_",GROUP_SEGMENT_ID_CPI_STRING = "G_",GROUP_SEGMENT_NAME_STRING = "",FIRST_SEGMENT_AFTER_GROUP_SEGMENT_BEGIN_ID_STRING = "<xsd:element name=\"S",FIRST_SEGMENT_AFTER_GROUP_SEGMENT_END_ID_STRING = "\"",FIRST_SEGMENT_AFTER_GROUP_SEGMENT_BEGIN_INDEX_INT = 0,FIRST_SEGMENT_AFTER_GROUP_SEGMENT_END_INDEX_INT = 0,FIRST_SEGMENT_AFTER_GROUP_SEGMENT_NAME_STRING = "",GROUP_SEGMENT_ID_BEGIN_INDEX_INT = CPI_RESULT_XSD_STRING.indexOf(GROUP_SEGMENT_ID_STRING)
while( GROUP_SEGMENT_ID_BEGIN_INDEX_INT > 0){
GROUP_SEGMENT_NAME_STRING = CPI_RESULT_XSD_STRING.substring(GROUP_SEGMENT_ID_BEGIN_INDEX_INT+GROUP_SEGMENT_ID_STRING.length(), GROUP_SEGMENT_ID_BEGIN_INDEX_INT+GROUP_SEGMENT_ID_STRING.length() + CPI_RESULT_XSD_STRING.substring(GROUP_SEGMENT_ID_BEGIN_INDEX_INT+GROUP_SEGMENT_ID_STRING.length()).indexOf(FIRST_SEGMENT_AFTER_GROUP_SEGMENT_END_ID_STRING)+ FIRST_SEGMENT_AFTER_GROUP_SEGMENT_END_ID_STRING.length()-1)
FIRST_SEGMENT_AFTER_GROUP_SEGMENT_BEGIN_INDEX_INT = GROUP_SEGMENT_ID_BEGIN_INDEX_INT + CPI_RESULT_XSD_STRING.substring(GROUP_SEGMENT_ID_BEGIN_INDEX_INT).indexOf(FIRST_SEGMENT_AFTER_GROUP_SEGMENT_BEGIN_ID_STRING)+ FIRST_SEGMENT_AFTER_GROUP_SEGMENT_BEGIN_ID_STRING.length()
FIRST_SEGMENT_AFTER_GROUP_SEGMENT_END_INDEX_INT = FIRST_SEGMENT_AFTER_GROUP_SEGMENT_BEGIN_INDEX_INT + CPI_RESULT_XSD_STRING.substring(FIRST_SEGMENT_AFTER_GROUP_SEGMENT_BEGIN_INDEX_INT).indexOf(FIRST_SEGMENT_AFTER_GROUP_SEGMENT_END_ID_STRING) + FIRST_SEGMENT_AFTER_GROUP_SEGMENT_END_ID_STRING.length() - 1
FIRST_SEGMENT_AFTER_GROUP_SEGMENT_NAME_STRING = CPI_RESULT_XSD_STRING.substring(FIRST_SEGMENT_AFTER_GROUP_SEGMENT_BEGIN_INDEX_INT,FIRST_SEGMENT_AFTER_GROUP_SEGMENT_END_INDEX_INT)
CPI_RESULT_XSD_STRING = CPI_RESULT_XSD_STRING.replaceFirst(GROUP_SEGMENT_ID_STRING+GROUP_SEGMENT_NAME_STRING, GROUP_SEGMENT_ID_CPI_STRING+FIRST_SEGMENT_AFTER_GROUP_SEGMENT_NAME_STRING )
GROUP_SEGMENT_ID_BEGIN_INDEX_INT = CPI_RESULT_XSD_STRING.indexOf(GROUP_SEGMENT_ID_STRING)
}
//We write the result 😉
new File("src/ASC-X12_"+msgNumber+"_004010.xsd").write CPI_RESULT_XSD_STRING
}
}

In the previous script I converted the message 920 of X12 Version 004010 from the XSD  of message 920 X12 Version 004010 downloaded from SAP PO, I think that explains itself, so I will not go into details( I'm not a Groovy guy so sorry if my code is not the best).

So I uploaded my "ASC-X12_920_004010.xsd" generated by the script to CPI and I made a simple test of a simple EDI2XML IFLOW:



 

Request:

EDI X12 Version 004010 message 920 with only the mandatory fields
ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*1~
GS*OW*7705551212*3111350000*20000128*0557*3317*T*004010~
ST*920*2~
F01*3*4*5*6*7~
F02~
SE*4*9~
GE*1*200031010~
IEA*1*100031010~

Response:
<?xml version="1.0" encoding="UTF-8"?><ns0:Interchange xmlns:ns0="urn:sap.com:typesystem:b2b:116:asc-x12:004010">
<S_ISA>
<D_I01>01</D_I01>
<D_I02>0000000000</D_I02>
<D_I03>01</D_I03>
<D_I04>0000000000</D_I04>
<D_I05_1>ZZ</D_I05_1>
<D_I06>ABCDEFGHIJKLMNO</D_I06>
<D_I05_2>ZZ</D_I05_2>
<D_I07>123456789012345</D_I07>
<D_I08>101127</D_I08>
<D_I09>1719</D_I09>
<D_I10>U</D_I10>
<D_I11>00400</D_I11>
<D_I12>000003438</D_I12>
<D_I13>0</D_I13>
<D_I14>P</D_I14>
<D_I15>1</D_I15>
</S_ISA>
<FunctionalGroup>
<S_GS>
<D_479>OW</D_479>
<D_142>7705551212</D_142>
<D_124>3111350000</D_124>
<D_373>20000128</D_373>
<D_337>0557</D_337>
<D_28>3317</D_28>
<D_455>T</D_455>
<D_480>004010</D_480>
</S_GS>
<M_920>
<S_ST>
<D_143>920</D_143>
<D_329>2</D_329>
</S_ST>
<S_F01>
<D_373>3</D_373>
<D_127>4</D_127>
<D_610>5</D_610>
<D_140>6</D_140>
<D_544>7</D_544>
</S_F01>
<G_F02/>
<S_SE>
<D_96>4</D_96>
<D_329>9</D_329>
</S_SE>
</M_920>
<S_GE>
<D_97>1</D_97>
<D_28>200031010</D_28>
</S_GE>
</FunctionalGroup>
<S_IEA>
<D_I16>1</D_I16>
<D_I12>100031010</D_I12>
</S_IEA>
</ns0:Interchange>

 

And the questions that does not let me sleep at night are:

  1. Why SAP has only released 18 messages for X12 Version 004010?

  2. Why have they changed the structure of it?.


The CPI consultants need the XSDs for yesterday 😉

 

Max.
8 Comments
Labels in this area