Skip to Content

SAP XI IN ACTION-I

Please read the blog SAP XI IN ACTION before continuing further. I actually planned to depict the implementation of entire approach in this blog but we are stuck up with the XI server issues and due to which I cannot take good snapshots. In this blog , I just want to share a generic mapping object which is used extensively in the design. We have used generic mapping object for converting any flat file structure to any hierarchical idoc structure. It is required because file adapter has the generic interface structure as specified in the previous blog and sample xml file generated for MRI interface would look like this:

It has to be converted to the hierarchical structure of MRI Idoc as shown below. It cannot be done at the file adapter CC due to the limitation of adapter. I have taken a simple Idoc structure for ease of demonstration.

XML after file CC

It is very complex to design the mapping in graphical editor so I went for java mapping. Even in this case we have to develop mapping programs for every interface and each developer has to put his own logic for his interface. Instead I thought of an approach, which would make the code generic, and each developer just specifies the Idoc structure in his interface specific code and generic code will convert any file structure to hierarchical structure .It cuts down the development efforts as each individual has to just specify the structure and the generic code transforms the input Idoc structure as specified in the interface. It worked out really fantastic in the project.

Idoc Structure

Interface Specific Code :

MRIGenToHierMap.java

/*****************************************************************************************************

  • Mapping Program to Convert NOM IDOC Master Structure to the Generic structure Expected by

  • the FTP Receiver adapter

******************************************************************************************************/

import com.sap.aii.mapping.api.*;

import java.io.*;

import java.util.Map;

import java.util.Vector;

import javax.xml.parsers.*;

import javax.xml.transform.*;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.*;

import org.xml.sax.*;

//Specify the Hirearchial Structure

class MRIGenToHierMap implements StreamTransformation

{

     public Vector v;

    private Map map;

    /** * method setParamters is required, but we do not anything with it */

     public void setParameter(Map param)

     {

          map = param;

     } /** * method execute is called by the XI mapping program */

public void buildXsd()

{

  Relation  mriRel ;

  v = new Vector();

  mriRel = new Relation();

  mriRel.parents = new String[1];

  mriRel.elements = new String[6];

  mriRel.node =  “A00” ;

  mriRel.parents[0] =   “NULL” ;

  mriRel.elements[0] =  “TRANSACTION_TYPE” ;

  mriRel.elements[1] =  “ORGANISATION_ID” ;

  mriRel.elements[2] =  “FILE_TYPE” ;

  mriRel.elements[3] =  “CREATION_DATE” ;

  mriRel.elements[4] =  “CREATION_TIME” ;

  mriRel.elements[5] =  “GENERATION_NUMBER” ;

  v.add(mriRel) ;

  mriRel = new Relation();

  mriRel.parents = new String[1];

  mriRel.elements = new String[39];

  mriRel.node = “N90”;

  mriRel.parents[0] =   “NULL” ;

  mriRel.elements[0] =  “TRANSACTION_TYPE” ;

  mriRel.elements[1] =  “CONFIRMATION_REFERENCE” ;

  mriRel.elements[2] =  “METER_POINT_REFERENCE” ;

  mriRel.elements[3] =  “EFFECTIVE_DATE” ;

  mriRel.elements[4] =  “METER_LOCATION_CODE” ;

  mriRel.elements[5] =  “METER_LOCATION_DESCRIPTION” ;

  mriRel.elements[6] =  “METER_INSTRUCTIONS” ;

  mriRel.elements[7] =  “BUILDING_NUMBER” ;

  mriRel.elements[8] =  “BUILDING_NAME” ;

  mriRel.elements[9] =  “DEPENDENT_STREET” ;

  mriRel.elements[10] =  “PRINCIPAL_STREET” ;

  mriRel.elements[11] =  “DEPENDENT_LOCALITY” ;

  mriRel.elements[12] =  “POST_TOWN” ;

  mriRel.elements[13] =  “COUNTY” ;

  mriRel.elements[14] =  “METERING_SET_REFERENCE” ;

  mriRel.elements[15] =  “BYPASS_FITTED_INDICATOR” ;

  mriRel.elements[16] =  “METER_SERIAL_NUMBER” ;

  mriRel.elements[17] =  “METER_MODEL_NAME” ;

  mriRel.elements[18] =  “IMPERIAL_METER_INDICATOR” ;

  mriRel.elements[19] =  “METER_NO_OF_DIGITS_OR_DIALS” ;

  mriRel.elements[20] =  “METER_MECHANISM” ;

  mriRel.elements[21] =  “METER_STATUS” ;

  mriRel.elements[22] =  “METER_COLLAR_FITTED_INDICATOR” ;

  mriRel.elements[23] =  “METER_PULSE_VALUE” ;

  mriRel.elements[24] =  “METER_READING_FACTOR” ;

  mriRel.elements[25] =  “CORRECTOR_SERIAL_NUMBER” ;

  mriRel.elements[26] =  “NO_OF_CORRECTED_DIALS” ;

  mriRel.elements[27] =  “NO_OF_UNCORRECTED_DIALS” ;

  mriRel.elements[28] =  “CORRECTION_FACTOR” ;

  mriRel.elements[29] =  “LAST_READ_DATE” ;

  mriRel.elements[30] =  “LAST_INSPECTION_DATE” ;

  mriRel.elements[31] =  “GAS_ACT_OWNERSHIP_TYPE” ;

  mriRel.elements[32] =  “METER_MANUFACTURER_CODE” ;

  mriRel.elements[33] =  “METER_MANUFACTURED_YEAR” ;

  mriRel.elements[34] =  “CONVERTER_MANUFACTURER” ;

  mriRel.elements[35] =  “CONVERTER_MODEL” ;

  mriRel.elements[36] =  “CONVERTER_MANUFACTURED_YEAR” ;

  mriRel.elements[37] =  “CONVERTER_READING_UNITS” ;

  mriRel.elements[38] =  “CORRECTOR_CORRECTION_FACTOR” ;

  v.add(mriRel) ;

  mriRel = new Relation();

  mriRel.parents = new String[1];

  mriRel.elements = new String[39];

  mriRel.node = “U06”;

  mriRel.parents[0] =   “NULL” ;

  mriRel.elements[0] =  “TRANSACTION_TYPE” ;

  mriRel.elements[1] =  “CONFIRMATION_REFERENCE” ;

  mriRel.elements[2] =  “METER_POINT_REFERENCE” ;

  mriRel.elements[3] =  “EFFECTIVE_DATE” ;

  mriRel.elements[4] =  “METER_LOCATION_CODE” ;

  mriRel.elements[5] =  “METER_LOCATION_DESCRIPTION” ;

  mriRel.elements[6] =  “METER_INSTRUCTIONS” ;

  mriRel.elements[7] =  “BUILDING_NUMBER” ;

  mriRel.elements[8] =  “BUILDING_NAME” ;

  mriRel.elements[9] =  “DEPENDENT_STREET” ;

  mriRel.elements[10] =  “PRINCIPAL_STREET” ;

  mriRel.elements[11] =  “DEPENDENT_LOCALITY” ;

  mriRel.elements[12] =  “POST_TOWN” ;

  mriRel.elements[13] =  “COUNTY” ;

  mriRel.elements[14] =  “METERING_SET_REFERENCE” ;

  mriRel.elements[15] =  “BYPASS_FITTED_INDICATOR” ;

  mriRel.elements[16] =  “METER_SERIAL_NUMBER” ;

  mriRel.elements[17] =  “METER_MODEL_NAME” ;

  mriRel.elements[18] =  “IMPERIAL_METER_INDICATOR” ;

  mriRel.elements[19] =  “METER_NO_OF_DIGITS_OR_DIALS” ;

  mriRel.elements[20] =  “METER_MECHANISM” ;

  mriRel.elements[21] =  “METER_STATUS” ;

  mriRel.elements[22] =  “METER_COLLAR_FITTED_INDICATOR” ;

  mriRel.elements[23] =  “METER_PULSE_VALUE” ;

  mriRel.elements[24] =  “METER_READING_FACTOR” ;

  mriRel.elements[25] =  “CORRECTOR_SERIAL_NUMBER” ;

  mriRel.elements[26] =  “NO_OF_CORRECTED_DIALS” ;

  mriRel.elements[27] =  “NO_OF_UNCORRECTED_DIALS” ;

  mriRel.elements[28] =  “CORRECTION_FACTOR” ;

  mriRel.elements[29] =  “LAST_READ_DATE” ;

  mriRel.elements[30] =  “LAST_INSPECTION_DATE” ;

  mriRel.elements[31] =  “GAS_ACT_OWNERSHIP_TYPE” ;

  mriRel.elements[32] =  “METER_MANUFACTURER_CODE” ;

  mriRel.elements[33] =  “METER_MANUFACTURED_YEAR”;

  mriRel.elements[34] =  “CONVERTER_MANUFACTURER” ;

  mriRel.elements[35] =  “CONVERTER_MODEL” ;

  mriRel.elements[36] =  “CONVERTER_MANUFACTURED_YEAR” ;

  mriRel.elements[37] =  “CONVERTER_READING_UNITS” ;

  mriRel.elements[38] =  “CORRECTOR_CORRECTION_FACTOR” ;

  v.add(mriRel) ;

  mriRel = new Relation();

  mriRel.parents = new String[2];

  mriRel.elements = new String[6];

  mriRel.node =  “K15” ;

  mriRel.parents[0] =   “N90” ;

  mriRel.parents[1] = “U06”;

  mriRel.elements[0] =  “TRANSACTION_TYPE” ;

  mriRel.elements[1] =  “METER_INSTALLATION_DATE” ;

  mriRel.elements[2] =  “METER_LINK_CODE” ;

  mriRel.elements[3] =  “GAS_NOMINATION_TYPE_CODE” ;

  mriRel.elements[4] =  “DATA_LOGGER_SERIAL_NUMBER” ;

  mriRel.elements[5] =  “DATA_LOGGER_UNIQUE_NUMBER” ;

  v.add(mriRel) ;

}

public void execute(InputStream in, OutputStream out) throws com.sap.aii.mapping.api.StreamTransformationException

{

     MRIGenToHierMap rel = new MRIGenToHierMap();

     rel.buildXsd();

     new GenToHierMap(in,out,rel.v,”MRI_ABSTRACT”,”urn:horzon:MRI”);

}

public static void main (String[] args) throws Exception

     {

          try

          {

               MRIGenToHierMap rel = new MRIGenToHierMap();

               FileInputStream in = new FileInputStream (“H:/j2sdk1.4.2_07/bin/DOM_IN.xml”);

               FileOutputStream out = new FileOutputStream (“H:/j2sdk1.4.2_07/bin/DOM_OUT.xml”);

               rel.buildXsd();

               new GenToHierMap(in,out,rel.v,”MRI_ABSTRACT”,”urn:horzon:MRI”);

          }catch(Exception e) {e.printStackTrace();}

     }

}

//Transformation of flat structure to hirearchial structure

All the 3 files have to be kept in the same directory and the generic java files should be compiled. Input XML has to be kept in the folder specified in the generic code. I would blog more details about the code depending on the demand for the same.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Stefan Grube
    Hi Ravikumar,

    Thank you for this blog, which is really useful.
    One little thing: The class MRIGenToHierMap must be declared as public, otherwise it cannot be accessed by the mapping runtime.

    Best Regards
    Stefan

    (0) 

Leave a Reply