Splitting XML string as separate fields in message mapping

Hi Experts,
I am getting XML string in one field from source message, i need to separate those fields and map it to target fields.
Sorce message:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:test_source xmlns:ns0="urn:gp:prototype">
   <Document>
      <store>3021</store>
      <date>2011-03-24</date>
      <type>3002</type>
      <till>32</till>
      <transaction>1478</transaction>
      <data><![CDATA[<buy><merchantID>006001007031992</merchantID><laneID>29</laneID><referenceID>PP0323095107</referenceID><localDate>2011-03-2302:00</localDate><localTime>09:51:0702:00</localTime></buy>]]></data>
   </Document>
</ns0:test_source>
Target Message:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:test_target xmlns:ns0="urn:gp:prototype">
   <item>
      <storeID>3021</storeID>
      <businessdate>2011-03-24</businessdate>
      <Typecode>3002</Typecode>
      <workstation>32</workstation>
      <SeqNum>1478</SeqNum>
      <XX>006001007031992</XX>
      <YY>29</YY>
      <PP>PP0323095107</PP>
      <QQ>2011-03-23+02:00</QQ>
      <RR>09:51:07+02:00</RR>
   </item>
</ns0:test_target>
Can anyone please suggest me how can we do this???

You can easily do both using standard function or simple udf
Use indexOf  and substring to achieve this...
Simple UDF
String var1="><![CDATA<buy><merchantID>006001007031992</merchantID><laneID>29</laneID><referenceID>PP0323095107</referenceID><localDate>2011-03-23+02:00</localDate><localTime>09:51:07+02:00</localTime></buy>]>";
String search = "<merchantID>";
if(var1.indexOf(search) != -1){
int pointer = var1.indexOf(search);
return var1.substring(pointer+12, pointer+27);
}else{
return "";
similarly for laneid
search ="<laneID>";
if(var1.indexOf(search)!= -1){
   int pointer = var1.indexOf(search);
    return var1.substring(pointer+8,pointer+10);
}else{
   return "";                         
Same way you can do for all the elements creating seperate method for each element or just use standard function to achieve this.
Edited by: Baskar Gopal on Mar 24, 2011 10:13 AM

Similar Messages

  • Send Multiple field values to Single Target field in Message Mapping

    Hi,
    My  Requirement is to Map Multiple fields to Single field in Target side.I have to send all the values concatenated and pass the same to target Field in Message Mapping.
    We can use Concat function,but more that 15 fields are there.If using concat,the mapping will be complex.
    Is there any way to simplify this requirement or we can use any UDF for this,kindly suggest.
    Regards,
    Madhu

    >>>We can use Concat function,but more that 15 fields are there.If using concat,the mapping will be complex.
    I don't think it's complex but  just that it occupies more mapping area
    Just write a simple UDF - a one line code and pass all your input variables.
    return var1+var2+var3+var4+...+var15;

  • Splitting a string into respective fields of dynamic internal table

    Hi,
        I've a string concatenated with a separator. I've to split the string and assign it to the respective fields of an internal table, which is dynamic.
    Table name will be passed through selection screen. The data is coming from another system via RFC.
    Eg : String ITAB :
                                100;89001;EN;Material1;MATERIAL1
                                100;89002;EN;Material2;MATERIAL2
    The String ITAB may contain any master data. Let's say the above data is from MAKT table. So, I want to assign the above data to the respective fields of MAKT internal table(Dynamic).
    I heard, this requirement can be achieved using some standard CLASS.
    Please help me in doing this task.
    Regards,
    Sunny

    Hello,
    you can use dynamic programming for this issue, i.e.:
    DATA: gv_table_name   TYPE string,
          gr_type_desc    TYPE REF TO cl_abap_typedescr,
          gr_struct_desc  TYPE REF TO cl_abap_structdescr,
          gr_table_desc   TYPE REF TO cl_abap_tabledescr,
          gv_t            TYPE c,
          gv_comp         TYPE i,
          gr_table_ref    TYPE REF TO data,
          gr_struc_ref   TYPE REF TO data.
    DATA: gt_itab   TYPE TABLE OF string,
          gt_split  TYPE TABLE OF string,
          gv_str    TYPE string.
    FIELD-SYMBOLS: <table>    TYPE ANY TABLE,
                   <struct>   TYPE ANY,
                   <comp>     TYPE ANY.
    APPEND '100;89001;EN;Material1;MATERIAL1' TO gt_itab.
    APPEND '100;89002;EN;Material2;MATERIAL2' TO gt_itab.
    "go!
    gv_table_name = 'MAKT'.
    cl_abap_tabledescr=>describe_by_name(
          EXPORTING p_name = gv_table_name
          RECEIVING p_descr_ref = gr_type_desc
          EXCEPTIONS type_not_found = 4 ).
    gr_struct_desc ?= gr_type_desc.
    gr_table_desc = cl_abap_tabledescr=>create( gr_struct_desc ).
    CREATE DATA gr_table_ref TYPE HANDLE gr_table_desc.
    CREATE DATA gr_struc_ref TYPE HANDLE gr_struct_desc.
    ASSIGN gr_table_ref->* TO <table>.
    ASSIGN gr_struc_ref->* TO <struct>.
    DESCRIBE FIELD <struct> TYPE gv_t COMPONENTS gv_comp.
    LOOP AT gt_itab INTO gv_str.
      CLEAR: gt_split.
      SPLIT gv_str AT ';' INTO TABLE gt_split.
      DO gv_comp TIMES.
        READ TABLE gt_split INTO gv_str INDEX sy-index.
        ASSIGN COMPONENT sy-index OF STRUCTURE <struct> TO <comp>.
        <comp> = gv_str.
        CLEAR gv_str.
      ENDDO.
      INSERT <struct> INTO TABLE <table>.
    ENDLOOP.
    After this code you will have all data in <table> field symbol in proper type.
    Regards,
    Jacek

  • How to check a field in Message mapping wether it is Non Numeric?

    Hi XI Guru's
    I am totally new to XI world, Kindly help hopw can I chexk a field while doing message mapping whether the field is non numeric or not.
    I dont find any built in function for the same.
    If it is using UDF can some body help me in providoing a UDF for this.
    Many Thanks
    Arun

    Hi Arun,
    In SAP PI, all the XML contents by default treated as STRINGS.
    So if u want to check whether the incoming field is numeric or not... the only way is to write a UDF code for the same.
    the UDF will be,
    1. At first
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    in functions.
    2.UDF content:
    input: field,container
    output:boolean
    Code
    boolean return_Value;
    Pattern p = Pattern.compile("[0-9]*");          // If u are using the decimals please change the regular expression accordingly.
    Matcher m = p.matcher(field);
    if(m.matches())
    retuen_Value = true;
    else
    return_Value = false;
    return return_Value ;
    I hope this will solve ur problem....
    Babu

  • Display queue for Target field in Message Mapping

    Hi Folks,
    If i check my Target Field (DT_Req) (Display queue) in Message Mapping, I am getting 2 values like ie [] that means ....in my test result in MM, i should get 2 times DT_Req field.
    Is it right?
    Plz give some idea how this display queue works on each field?
    Thanks
    Prabaharan
    Edited by: Prabaharan on Sep 10, 2008 12:22 AM
    Edited by: Prabaharan on Sep 10, 2008 12:24 AM

    Hi,
    In my scenario occurrence of that
    target field is    0...unbounded
    and in my display queue.. Initially it is
    suppress, [], suppress, suppress, suppress,suppress,suppress,suppress,suppress,suppress, [],suppress
    in my result i could get only one DT_req field.
    Plz throw some idea on this?
    thanks

  • Splitting a string into separate values, but the array length is variable

    We are a cabinet manufacturer.  I'm trying to write a report to show the location of individual hinges on a door.  I have a string that will look something like these examples:
    60, 540
    60, 540, 956
    60, 540, 956, 1340
    It may have 2, 3, 4, or 5 locations.  (Don't think I've ever seen one over 5).
    So I have a formula that says:
    Split({Doors.HingeCenterLines},',')[1]
    This will return 60 - the first figure in my string.
    I need to have all of them separated, but the critical thing is the last measurement.  I need it to be the height of the door minus the last hinge location.  So for an example, if I have a 1400mm tall door, the 4th example string listed above would be generated.  I want my entries to look like this:
    60
    540
    956
    60
    My string always references the hinge relationship to the bottom of the door, but for the top hinge only, I need it to be based on the distance from the top of the door.
    Can anyone help with this?  Thanks in advance!

    Try this code please:
    whileprintingrecords;
    local stringvar array arr := Split({Doors.HingeCenterLines},',');
    local numbervar temp;
    local stringvar fin_string;
    local numbervar i;
    For i := 1 to ubound(arr) do
         If i = ubound(arr) then
              temp := {Door_height} - tonumber(arr[i]);
              fin_string := fin_string + totext(temp,0,"");
         else
              fin_string := fin_string + arr[i] + chr(13);
    fin_string;
    You can then right-click the field > Format Field > Common tab > Check the 'Can Grow' option.
    -Abhilash

  • Adding Zeros infront of a field in Message Mapping

    Hi,
    I need to add zeros infront of my target field (eg Target Field length is fixed (10). If incoming field is having only 3 digits (123), I need to add 7 (10-3) zeros infront of my target field (0000000123). How to go about it. Is there any standard functions to do this ?
    Thanks in advance,
    Jose Augastine

    Try using this UDF
    double d = Double.parseDouble(a);
    DecimalFormat df=new DecimalFormat("0000000000");
                   StringBuffer sb=new StringBuffer();
                    df.format(d,sb,new
    FieldPosition(NumberFormat.INTEGER_FIELD));
                   return(sb.toString());
    Regards,
    Jai Shankar.
    Message was edited by: Jai Shankar

  • How to transform common object to xml string

    I know that I can import xml dtd a the common data type in iStudio. However, does anyone know how to serialize it back to the xml string during the field mapping? Is it even possible?
    Thanks,
    Edward

    Thanks Stuart for your reply. What I'm trying to do is to convert the xml message from the common view object to JMS Text Message. I declared the application data type as AQ$JMS_TEXT_MESSAGE and I try to map the common data type which is I imported from dtd to the application JMS type. During the mapping I need to serialize the common data type object back to xml string, so I can copy it to text_vc field defined in JMS Text Message (String type).
    Or do you know any other alternative to convert from RAW XML payload type to JMS payload type in iStudio?
    Thanks,
    Edward

  • Message Mapping Problem with UTF-16LE Encoded XML

    Hello,
    we have the following scenario:
    IDoc > BPM > HTTP Sync Call > BPM > IDoc
    Resonse message of the HTTP call is a XML file with UTF-16LE processing instruction. This response should then be mapped to a SYSTAT IDoc. However the message mapping fails "...XML Parser: No data allowed here ...".
    So obviously the XML is not considered as well-formed.
    When taking a look at SXMB_MONI the following message appears: "Switch from current encoding to specific encoding not supported.....".
    Strange thing however is if I save the response file as XML and use the same XML file in the test tab message mapping is executed successfully.
    I also tried to use a Java Mapping to switch encodings before executing message mapping, but the error remains.
    Could the problem be, that the codepage UTF-16LE is not installed on the PI system ? Any idea on that ?
    Thank you!
    Edited by: Florian Guppenberger on Feb 2, 2010 2:29 PM
    Edited by: Florian Guppenberger on Feb 2, 2010 2:29 PM

    Hi,
    thank your for your answer.
    This is what I have tried to achieve. I apply the java conversion mapping when receiving the response message - i tried to convert the response to UTF-16, UTF-8 but none of them has helped to solve the problem.
    I guess that using adapter modules is not an option either as it would modify the request message, but not the response, right?

  • Is there a way to get the actual XML string when using the JAXP SAX Parser?

    Hi All,
    I am using a JAXP SAX xml parser and am looking for a way to get the actual line of xml that is being parsed from within a content handler.
    Here's my scenario. Consider the following example xml document.
    <formCollection>
       <form name="myForm">
          <text/>
          <selection/>
       </form>
       <form name="anotherForm">
          <text/>
       </form>
    </formCollection>My hope is to validate the entire document and then insert an xml string containing each "form" element (and its sub-elements) into a map for later use. My thought was to create a String as each "form" element is being parsed (begining with the form's startElement event and concatenating until the form's endElement event is reached) and then inserting this string into the map. Is there a way to get the actual line of xml that is being parsed, rather than just the element name and attribute values?

    DrClap wrote:
    YouRang wrote:
    2. The first handler would validate the entire XML document, extract the "type" attribute from each <form> element, and place each <form> element and its sub-elements into the map of Strings, using the "type" attribute as the key. The second handler would take a <form> element and parse it into a Form object for the display. This option was the impetus for my question because it relies on the first handler being able to access the entire <form> element XML String and write it to a map.I don't see why you need the raw data from the XML document here. You should already be abstracting your data into Java classes in the first handler, instead of making the second handler do the parsing all over again.Correct, I am not referring to XForms. In this case, it happens that I am using the XML to generate an SWT ScrolledForm object and, thus, the XML element name happens to be named "form." However, the concept/design problem could apply to any type of object and the XML element could be appropriately renamed.
    My experience with XSLT is limited and I haven't done anything with it for several years. With that said, it seems that it is primarily used for generating web content, which wouldn't apply in this case because this is for a client-server application. I could be off base on this one -- if XSLT applies to much broader translations and would be more appropriate for generating Java objects than my current methodology, I could certainly look into it further.
    I apologize that option two didn't make more sense; it is difficult to explain. Yes, optimally the data should be abstracted into Java classes in the first handler. This is really an elaboration that I failed to specify when explaining option one. The problem is that the user can choose to create any number of "forms" of any type. For instance, let's say that from the File -> New menu there are options for seven different types of forms and each form is used to send completely different data. The user can select form1, select form1 again, select form4, and select form7 (or any other combination) and bring up tabs that display the different forms. The user can then enter data and submit each form separately. When the user selects File -> New -> FormX, a SWT ScrolledForm object that corresponds with FormX must be given to the display. Because SWT ScrolledForm objects do not allow a deep copy, I cannot simply read the XML <form> elements at initialization, parse them into ScrolledForm objects, and pass deep copies of the ScrolledForm objects to the display each time the user clicks File -> New -> FormX. The only simple way I see of getting a new copy of a ScrolledForm object is to reparse the appropriate XML <form> element in order to create one each time the user selects File -> New -> FormX. As such, one handler would need to read the entire XML document and parse the <form> elements into a map (or some other data structure) and another handler would need to parse individual <form> elements into SWT ScrolledForm objects. The first handler would be called at initialization and the second handler would be called each time a user clicked on File -> New -> FormX. Once again, this isn't exactly my favorite implementation... but seems the simplest given that there is no way to do a deep copy of an SWT ScrolledForm object. Hopefully that makes a little more sense. No worries if it doesn't -- I just figured I'd throw this out there and see if anyone had a better idea.

  • Message ID in Message Mapping

    Hello everyone,
    I have a BPM that executes an ABAP Proxy, my problem is that I need to send in the ABAP Proxy strcuture the Unique Message Id that the BPM has in XI, I don't know if I can obtain this field in Message Mapping and map it to the ABAP Proxy structure, can anyone help me? thanks in advance for your answers.
    Regards,
    Julio Cesar

    Hi Julio,
    You can get the message id through java UDF. Here is the code
    String headerField;
    java.util.Map map;
    // get runtime constant map
    map = container.getTransformationParameters();
    // get value of header field by using variable key
    headerField = (String) map.get(StreamTransformationConstants.MESSAGE_ID);
    return headerField;
    Thanks
    -Kulwant
    If helpful, assign score please

  • Message mapping: Passing data at the node level

    Hi,
    I have a question/requirement, XI Message Mapping program need to read the incoming xml and map to a diffrerent target structure. Incoming xml has a parent node called Description and it has a value "Frauen Hemd Shoes", we need to map this value to target LongText Field but message mapping is ignoring this data while mapping.
    A parent node can't hold the value/data while a child node is present. So is there any workaround to read this data to target str?
    <Description>
    <ShortName>Shoes</ShortName>
    Frauen Hemd Shoes
    </Description>
    Expected result:
    <Comments>
    <ShortText>Shoes</ShortText>
    <LongText>Frauen Hemd Shoes</LongText>
    </Comments>
    Please let me any clues to resolve the issue.
    thanks,
    Laxman

    I agree , the soruce structure is not a valid one..
    The source structure should look like the below:
    <Description ShortName='Shoes'>
    Frauen Hemd Shoes
    </Description>
    where ShortName is attribute for the Element "Description".
    You add attribute to the element the same way you add subElement, Just choose attribute instead of subelement.
    In this case the Mapping would be
    Descriprion -
    > LongText (target)
    ShortName -
    > ShortText (target)
    This Should work.
    Regards.
    Jeet.

  • Need help on message mapping screen

    Hi folks,
    I am working on file to idoc scenario.   I Imported the IDOC to my scenario. In Messaga Mapping IDOC structure displaying fields as a documention. but i need techincal names of those fields.
    for Example:   In my IDOC 1 field is showing companycode but I want to see that field as a BUKRS.
    How to see the technical names of IDOC fields in Message Mapping.
    Your help is highly apprecia

    Hi,
    I dont think we would be able to see the data element names of the IDOC in XI. Even the imported XSD of Idoc doesnot contain data element name.
    We would be only dealing with the field names/ structure of the IDOC for field message mappings. The field names are internally mapped to the data element names in SAP R3 system.
    To view the internal mapping between field names and data element names of the Idoc fields, you can go to the transaction 'WE30'. Give the basic type of the Idoc and go to the segment editor. You can find the data element names for each field name  there.
    Thank you.
    Regards,
    Subbu

  • Exchanging data between interface mapping and message mapping possible?

    Hi,
    please have a look at my interface mapping:
    source message -
    >
    mapping programs
    1. Java mapping
    2. XSL mapping
    3. message mapping
    > target message
    in my scenario a Java Class (1) is called for the interface mapping. There, some information ist read from the xml structure. Next, a xslt mapping (2) takes place that strips some information. The remaining data is passed to the message mapping (3)
    The reason for this is that the source message consists of a xml message inside an xml message.
    I am looking for a way to access the informationen gained in step 1 (Java class) in the message mapping (step 3). I was hoping that the global container (used by user-defined function within message mapping) is accessible from the java mapping, but I could not find out how.
    Anybody with some ideas how to pass information from step 1 to step 3? I cannot put the Information in the xml that is passed to the message mapping, because the schema of the inner xml cannot be changed.
    Thanks very much, best regards,
    Wolfgang

    Hi Wolfgang!
    I have used the "Dynamic Configuration" section in the XI Message header for this issue. You could write something into the Dynamic Configuration Section in step 1 (Java-Mapping) and read it out again in steps 2 or 3. You could use a section for a adapter you are not using in your interface for the real receiver. So if you have a File-Receiver Adapter at the "end" you could use some section of the e.g. SOAP adapter not to interfere with your receiver-adapter when using Dynamic Configuration Settings there ...
    See also: http://help.sap.com/saphelp_nw04/helpdata/de/43/09b16006526e72e10000000a422035/content.htm
    or
    http://help.sap.com/saphelp_nw04/helpdata/de/43/0a7d1be4e622f3e10000000a1553f7/content.htm
    Best regards,
    Andi

  • IDOC in Message mapping

    Hi folks,
    I am working on file to idoc scenario.   I Imported the IDOC to my scenario. In Messaga Mapping IDOC structure displaying fields as a documention. but i need techincal names of those fields.
    for Example:   In my IDOC 1 field is showing companycode but I want to see that field as a BUKRS.
    How to see the technical names of IDOC fields in Message Mapping.
    Your help is highly appreciated.
    Thanks,
    Anitha.

    Hi bavesh...
    thank you so much for very your quick responses..
    i got xsd as source..based on xsd i created external definition for source xsd  and  i created outbound interface based on source external deifinition <b>MI_OUT_WearUnits</b>.
    and i imported Idoc and exported as xsd and changed occurance to unbounded and again imported as external definition.
    i did mapping between these two external definitions.
    and i selected standard idoc for source and target interface for interface mapping  and given message mapping of previous step.
    In ID
    sender agreement :
                    sender service :BS_external
                    sender interface :<b>MI_OUT_WearUnits</b>
    receiver agreement:
                  receiver service :R/3
                  receiver interface :  standard Idoc
    Interface determination:
    sender service :BS_external
    sender interface :<b>MI_OUT_WearUnits</b>
    reciever service :R/3
    and clicked create
    inbound interface : Standard IDOc
    i am not getting Interface mapping which i created in IR.
    i tried Enhance interface determination also..
    please guide me....
    waiting for your help.
    regards
    ram

Maybe you are looking for

  • Can't view my data on my table in EM

    Can anyone tell me why I am getting the error below after executing my control file and also why I can't view that data which was loaded. SQL*Loader: Release 10.2.0.1.0 - Production on Thu Jul 12 16:28:57 2007 Copyright (c) 1982, 2005, Oracle. All ri

  • 10g Installation and Error : ORA-12514 : Listerner cant recog. service requ

    Hi, I installed 10g, and trying to start sql plus. I entered username: orcl password: my own password host string: name of my computer I am getting the error: ORA-12514: TNS: Listener does not currently know of service orequested in connect descripto

  • Call of Duty 2 no longer works

    Have been playing this for some time now. Suddenly, anytime I try to start the game I get the 'Call of Duty 2 has unexpectedly quit' message. What's weird is multiplayer seems to start up fine. I've repaired permissions, booted into single user mode

  • I was able to switch between tab groups on Firefox 4 with ctrl-`, but not on Firefox 5; why?

    I updated yesterday from the most recent version of Firefox 4 to Firefox 5 on Mac OS 10.6.7. On Firefox 4 I was able to switch between tab groups using ctrl-` (I loved this feature-I find the mouse-based interface clunky). Now that shortcut either do

  • IPhoto 8 Photos Corrupted or Disappeared

    Using iPhoto 7.0.2 (341) I've now had two separate iPhoto libraries where photos were either corrupted or lost. In the first instance I noticed a problem trying to do a Retrospect Back-up and the procedure simply hung the program. Then when I tried t