Skip to Content

EDI X12 – XSD Converter from SAP PO to CPI

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=\"\" xmlns:hci=\"\" xmlns:ica=\"\"><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	
		//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\">"	
		//We put the content extracted from SAP PO XSD into CPI XSD
		//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
		//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:



EDI X12 Version 004010 message 920 with only the mandatory fields



<?xml version="1.0" encoding="UTF-8"?><ns0:Interchange xmlns:ns0="">


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 😉



You must be Logged on to comment or reply to a post.
  • Hello Max,

    many thanks for the interesting blog and the very good questions.

    We published the 18 most frequently used XSD for X12 and UN/EDIFACT together with our set of B2B capabilities at CPI in July, last year. The main purpose of this small set of XSDs was that the partners and customers can start using and testing these B2B capabilities at CPI.

    The manual provisioning of these XSD is just an interim solution, because our road-map entails the provisioning of all required B2B standard and de-facto libraries just on integration content advisor (ICA) for SAP Cloud Platfrom Integration. The new version was released on Jan 22nd, 2018 (see:

    ICA will provide all versions, all message types, and especially all documentation per B2B standard library and you can directly use it in ICA for the specification/customization of your own structures and the specification of mappings to the corresponding customized structures.

    Please contact me, if you need more information about the ICA. I will publish further blogs, soon.

    Kind regards,


    • Hi Gunther,

      Thanks for you reply, I had access to the “basic” ICA tool and I found the following problems:

      1. You have to paid for ICA
      2. You have to pad for X12
      3. The library UN/CEFACT is empty
      4. You only can use the structures in your library(predefined by SAP), means that you can not use custom structures or external WSDLs,XSDs,OData,BAPIs, etc…. to build MIGs
      5. You can not export the definitions of your library, you must build a MAG to get the XSDs, so you’re forcing us to use the tool to get them
      6. The idocs version in the library are for 1709 and we are almost in 1802, will not this cause problems?


      I think the tool is very usefull for scenarios where you have EDI(X12,UN/EDIFACT,UN/CEFACT) and IDOCs, but there are other types of communication nowadays in addition of IDOCs.


      I’ll wait for the further blogs, if I’m wrong in something, please let me know it.


      Kind Regards.


  • Hello Max,

    regarding your problems:

    1.) This is correct, ICA is a part of the enterprise edition license

    2.) This is correct, you have to pay for it all time, because the X12 content is in general not for free. This is a part of usage policy of ASC X12 use (see: You have to purchase for every X12 content/versions (

    3.) ICA should provide UN/EDIFACT, too. It has to be purchased, too. Because a partner provides the whole content.

    4.) OK - This is a completely new approach and paradigm. We are adding further features in the next takts. The definition of customer specific structures is on our roadmap.

    4.a) We will provide further libraries such as cXML, APIs, etc. soon.

    5.) The intention is that we provide all versions and the whole library of IDoc. The 1709 release is our starting point.

    Kind regards,



    • Hi Gunther,

      From my point of view, the XSDs should be independent of ICA tool, SAP is creating an unnecessary dependence.

      I understand that the product is new, but due to the limitation that ICA has, SAP is limiting and obstructing the CPI developments that the ICA tool does not cover.

      The clearest example is to integrate a non IDOC service( ODATA,BAPI,SOAP,etc) with an X12 message not provided in the 004010 package, we are being forced to pay for ICA, pay for X12 library to only get the XSDs and not use ICA tool, since it does not cover this scenario, It does not make any sense to me,in the worst case scenarios, SAP could sell the XSDs separately.


      It's just the opinion of a CPI consultant 🙂


      Kind Regards.


      • Hello Max,

        following points:

        1. you will get the IDocs, OData, SOAPs and other libaries via ICA in May 2019
        2. you can also generate XSDs in ICA, which you can use similar like the other XSDs.



        • Hi Gunther,

          Thanks for the update, I'm really waiting for it, and someday for the TPM GUI version 😉

          I'm not sure why doesn't exist the TPM GUI version in CPI, It should be a nice milestone for the CPI & ICA tool, do you have any date to release it ?.


          Kind Regards.


    • Hello Sravya,

      the SAP PO X12 converter is just for the processing of data and all provided content can be only used in SAP PO runtime and not outside such as for documentation purposes. If you take a X12 XSD from API Business Hub, you have to purchase for a license via X12 store anyway. This is not the case, if you go for SAP Store + ICA, because if you purchase for a license via SAP Store, you will get a full legitimization to use it in ICA without buying a license via X12 store.