How to handle optional elements in Simple Transformation

Greetings!
I'm working on an ST that needs to be able to serialize an ABAP itab to XML which may or may not contain certain elements depending on the customer to whom the file is being sent.  Additionally, we receive a file that uses the same schema inbound from these customers as well and so we'd need the ST to process these elements if they exist but ignore them if they don't.
I've done some searching here and found a couple of responses that were close but I think I need more detail.  Could someone provide an example, perhaps?  I'm new to ST, by the way.
Thanks much!

Hello,
You can make use of condition to check if element is initial or not during transformation..
For usage and more details you can refer following link:
http://help.sap.com/saphelp_nw04/helpdata/en/e3/7d4719ca581441b6841f1054ff1326/frameset.htm
Hope this helps!
Enjoy SAP!
-Augustin.

Similar Messages

  • How OSB handling null element?

    hi Guys,
    I having question about how to handling a null node during trasnfortation and mapping using oracle workshop for OSB 10g.
    Well i have a consumer that not sending the element into the proxy, so during the proxy i will need to transform it into null element to the provider. what's in my mind is transform the element tag into something like this
    { if (fn:nilled($getAssetAttribReqParam1/RequestHdr/ns1:RequestId)) then
    <ns1:RequestId xsi:null = "true"/>
    else
    (<ns1:RequestId>{ data($getAssetAttribReqParam1/RequestHdr/ns1:RequestId) }</ns1:RequestId>)
    but when i doing testing it still showing this
    <ns1:RequestId></ns1:RequestId>
    i will need to sent the element something like this to the provider. because if this element is date format it will fail in the validation if i sending *<ns1:RequestId></ns1:RequestId>*
    <ns1:RequestId xsi:null = "true"/>

    I think your case should be addressed like -
    if ($getAssetAttribReqParam1/RequestHdr/ns1:RequestId) then
    <ns1:RequestId>{ fn:data($getAssetAttribReqParam1/RequestHdr/ns1:RequestId) }</ns1:RequestId>
    else
    <ns1:RequestId/>
    Regards,
    Anuj

  • How to escape special characters in Simple Transformation

    Hi Experts,
    I have got a problem to get a well formed xml document from the below simple transformation. The content of maktx contains
    special characters like & <, which are not allowed in a well formed XML-Document. But the result of the Simple Transformation
    contains this charcters even after the transformation as you can the in the result below. Has anyone a hint how to escape the
    characters included in the maktx.
    The transformation for maktx, should be something like
    Before: Material & < TEST
    After: Material &amp &lt TEST
    Report wihich calls the simple transformation
    types:
    BEGIN OF t_mat,
       matnr type matnr,
       maktx type maktx,
    end of t_mat.
    Data:
      mat type t_mat,
      xml_stream type xstring.
    START-OF-SELECTION.
    mat-matnr = '4711'.
    mat-maktx = 'Material & < Test'.
    CALL TRANSFORMATION ztest_st2
            SOURCE mat = mat
            RESULT XML xml_stream.
    CALL FUNCTION 'DISPLAY_XML_STRING'
      EXPORTING xml_string = xml_stream.
    Simple Transformation
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
      <tt:root name="MAT"/>
      <tt:template>
        <Leistungsschild>
            <CHARACT> MATNR </CHARACT>
            <CHARACT_DESCR> Materialnummer </CHARACT_DESCR>
            <VALUE tt:value-ref="MAT.MATNR"/>
            <CHARACT> MAKTX </CHARACT>
            <CHARACT_DESCR> Materialkurztext </CHARACT_DESCR>
            <VALUE tt:value-ref="MAT.MAKTX" />
        </Leistungsschild>
      </tt:template>
    </tt:transform>
    RESULT
    <?xml version="1.0" encoding="utf-8" ?>
    <Leistungsschild>
      <CHARACT>MATNR</CHARACT>
      <CHARACT_DESCR>Materialnummer</CHARACT_DESCR>
      <VALUE>4711</VALUE>
      <CHARACT>MAKTX</CHARACT>
      <CHARACT_DESCR>Materialkurztext</CHARACT_DESCR>
      <VALUE>Material & < Test</VALUE>   </Leistungsschild>

    Hi Sandra,
    First of all thaks for your quick answer to my problem.
    I see what you mean and get the same result, if I am using data-type string instead of xstring. But the recommendation in the XML-Books of SAP is to use XSTRING to save memory and circumflex problems between Codepages, when writing the XML-Stream to a filesystem.
    As you can see in the code abvoe I am using a SAP-FM to display the XML-Stream and this FM works only with XSTRING´s,
    that is one reason why I don´t understand that it displays it in the wrong way.
    Even the Debugger shows me for the XSTRING the wrong result. Does all that mean that the escaping will not be applyed if you are working with XSTING´s??

  • Best way to handle optional elements in XSLT

    Hi All,
    I'v wondering if there are any better ways to handle optional fields in XSLT.
    For example if my Person Type has 5 fields and 3 of them are optional:
    <xs:complexType name="PersonType">
    <xs:element name="PersonID" min="1"/>
    <xs:element name="PIN" min="1"/>
    <xs:element name="FirstName" min="0"/>
    <xs:element name="MiddleName" min="0"/>
    <xs:element name="LastName" min="0"/>
    </xs:complexType>
    In my xslt file, if I do somthing like:
    <Person>
    <FirstName>
    <xsl:value-of select="PersonType/FirstName"/>
    </FirstName>
    </Person>
    I might get an empty FirstName element in my output xml file. (like <FirstName/>) This has caused some very weired behavour with Oracle v2 parser because optional means the node may not be present in the xml not the node is there but empty.
    The only way I can think of solving this is to put <xsl:if test> around every single optional element to test if it exist in the source file. If it does then generate the element in the destination file. But in this way, if the source file is very complicated, then you would have to wrap each element with a <xsl:test> which is very ugly to me.
    Do anyone know if there is a more generic way that we can solve this issue?
    Thanks,
    Larry

    Dharmendra,
    The answer you gave is very very helpful. The only thing that I can think of here is that it might accidentally delete the fields that have been set empty deliberately.
    Maybe, this is one of the grey areas in XML Schema that I do not understand very well yet. In xml, if you define an element to be a string type and mandatory (minOccurs="1"), for exampe the following xml
    <Name></Name>
    will be valid against the schema because the Name element is present in the xml payload. However, it has no value or has a valud of empty string. I know that this is only a problem with string type. If it is boolean, then it has to be either true of false, being empty won't satisfy the schema validator. But with String it is a bit trickier, because String can be empty. Maybe this issue should be stopped when designing your xml schema by specifying the mininum length (>0) in the schema. Any suggestions would be welcomed.
    Cheers,
    Larry

  • How to handle UI elements property

    hi, all
    this is very common problum which every one face. The problum is that how one can handle UI elements(Radio,Label,Input field ) property dynamically.

    hai,
    create UIElements dynamicaly is possible in wdModify method only.
    like this
    public static void wdDoModifyView(IPrivateDynamicAppView wdThis, IPrivateDynamicAppView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
        //@@begin wdDoModifyView
       if(wdContext.currentContextElement().getBoolfor()){
         IWDTransparentContainer tcont1 = (IWDTransparentContainer)view.getElement("TransparentContainer1");
         IWDGridLayout k=(IWDGridLayout)tcont1.getLayout();
        k.setColCount(1);
    IWDLabel lo=(IWDLabel)view.createElement          
    lo.setDesign(WDLabelDesign.LIGHT);
         wdContext.currentContextElement().setBoolfor(false);
        //@@end
    here boolfor is the context attribute of type boolean. you can set it true in whch action do u want to invoke the cod in wdmodifyview.
    all the best.
    regards,
    naga raju

  • How to skip XML tags in Simple transformation

    Hi,
    I am trying to convert an XML file to ABAP code using Simple Transformations.
    I tired converting a small XML file to ABAP using it and it worked fine.
    The problem is that the number of tags in the XML file I now want to parse is huge (over 200).
    Is there any way that for the tag in XML corresponding tag is not created in ST? Is there any conditional tag to achieve this?
    Also, is Simple Transformation a better way of parsing in such a scenario over XSLT and DOM parser?
    Thanks and Regards,
    Neha
    Edited by: Neha Anand on Jun 2, 2008 1:19 PM

    Hi Raja,
    I have already looked through the code snippets and I am able to write a CALL TRANSFORMATION.
    I want to find out if the number of tags is huge then if there is any way that some tags can be skipped for matching tags in XML which anyhow I dont need for manipulation.
    Thanks and Regards,
    Neha

  • How to avoid optional elements

    In a partner wsdl I have a type as follows which is part of the request message:
    <xs:complexType name="JobType">
    <xs:sequence>
    <xs:element name="Addressees" type="tns:AddresseeType"/>
    <xs:element name="EndUserNotification" type="tns:UserNotificationType" minOccurs="0"/>
    <xs:element name="Comments" type="xs:string" minOccurs="0">
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    Before I invoke the partner I do some assignments. Although I have no assign statement for the EndUserNotification I see the emtpy element on the wire:
    <EndUserNotification></EndUserNotification>
    In my case this is not valid XML since the EndUserNotification contains elements which are not optional. In my view the element shouldn't be on the wire because it's defined with minOccurs="0". Any ideas?
    Thanks
    Yves

    Well this is pretty painful. Now I've got 0 elements even when the minOccurs is defaulted to 1. Presumably I'd have to ora:genEmptyElem() for every element I use on both callouts and responses. That's not what I'm looking for anyway. If I can't get an unitialized minOccurs=0 element then I'd prefer to delete the extraneous entry. So from my perspective I still haven't found a viable technique to have my web services respond appropriately.
    BTW, the table defines 'False' as the appropriate value, when it requires 'false' to get the configuration property to be realized.

  • Csv file to d3l, how to handle "optionally enclosed by"

    The data can be:
    "DETAIL","S","0521498686",1,"ADVANCED GRAMMER IN USE WITH ANSWERS","HEWINGS, MARTIN","","N","P","0",0.00,10.15,17.50,8.37,"Y","","","",””
    Comma is the delimiter, but authors can be "HEWINGS, MARTIN" and the comma after last name is not a delimiter!
    In a ctl-file (for sql loader) this works fine with this:
    fields terminated by ',' optionally enclosed by '"'
    This takes care of the commas; they are interpreted as part of the data, not delimiter.
    Anobody know what I write in my D3L?
    This is not enough:
    <field name="author"><termstring endchar=","/> </field>
    Hilde

    Hm, solved it myself....
    The field author actually ends with ", (double quoute and comma)
    so I use this termstring (for the author field only):
    <termstring endchar="#x2C#x22" />
    It works.
    The PlSql procedure can rinse the extra " with replace (it is a dbadapter).

  • Simple Transformation - Optional Tag

    Hi,
    I receive an XML from an called web service. Depending on the ws input I receive a diferent result XML.
    Result 1:
    <LdPat3D>
      <Blocks>
          <Block>
           <Block>
      <Blocks/>
    </LdPat3D>
    Result 2:
    <LdPat3D/>
    The simple transformation works for Result 1, but not for Result 2. In case of Result 2 a CX_ST_MATCH_ELEMENT exception
    occurs mentioning that element-start blocks is expected and element-end: "LdPat3D" [ ] is read.
    Could you please tell me how to handle this in my simple transformation?
    Thank you and best regards, Edgar

    Hi Edgar,
    you should define <blocks> element as optional using <tt:cond>
    More information : http://help.sap.com/saphelp_nw70/helpdata/en/0c/402040abf2c442e10000000a1550b0/frameset.htm
    BR
    Sandra

  • !CDATA[]] in ST (Simple Transformation)

    Hi,
    How to generate a CDATA section in an xml element with simple transformation. in xslt a have already a solution but i need it in st.
    rgds
    ilan

    A workaround would be to create GUIDs and replace them after the transformation with your wanted string...
    " Create GUID
    CALL FUNCTION 'GUID_CREATE'
        IMPORTING
          ev_guid_32 = lv_guid.
    " lv_guid is somewhere in your itab lt_root
    " Call Transformation
    CALL TRANSFORMATION my_transformation
         SOURCE root = lt_root
         RESULT XML lv_xml.
    " Replace GUID
    lv_string = 'my replacement string'.
    REPLACE lv_guid WITH lv_string INTO lv_xml.
        IF sy-subrc NE 0.
          " Error
        ENDIF.
    Hope this helps...

  • Dynamic TAG - Simple Transformation

    Hi All,
    I need work with dynamic TAGS (Elements) on Simple Transformation?
    The tag should be <Invoice> or <DebitNote> depending on a Variable.
    How can I achieve this?
    Thanks and Regards,

    We work with Microsoft Outlook, but I'm sure this could work with any email system.
    This error only came from external emails - what we did in the end is to get the third party to email a particular email (email1) in our company.  This is set up as a regular email account.  On this email put a forward rule to email2 for a particular sender/subject.  email2 is set up as POP3 so that XD1 can poll it - we also block any emails except from email1.
    Doing this accomplishes a couple of things:
    1)  We get around the error because XI polls email2 (which has adapter settings of IMAP4 so we can see MAIL adapter attributes ie. sender, subject etc...When we originally had as POP3 we were not able to see these - but setting as IMAP4 causes the error for external emailers)
    2) We have a SPAM filter - the XI email is clean from SPAM and the adapter will not have errors, as it only receives valid emails to process
    3) We have a central email (email1) which is used to archive all XI emails - we use this for all email scenarios (as we also save to folder and forward in the rule)
    Hope this helps your situation.

  • Simple Transformation XML to ABAP Content of tag with subtrees to string field

    Hi,
    I have an  requirement in which I have to do a transformation from an XML file to an structure.
    I need get the value of a tag that have subtrees and move that to a field in my structure.
    Example:
    <TAG1>value1</TAG1>
    <TAG2>value2</TAG2>
    <TAG3>
         <TAG4>value4</TAG4>
         <TAG5>value5</TAG5>
    </TAG3>
    Result expected in ABAP Structure:
    field1 -> tag1
    field2 -> tag2
    field3 -> <TAG4>value4</TAG4><TAG5>value5</TAG5>
    The contents of the tag TAG3 is variable, so I want to store it as a string.
    Can I make this with Simple Transformation?
    In my tests I can move only the value of each child tag for the given field structure.
    This syntax dont work:
    <TAG3 tt:value-ref="STRUCTURE.FIELD3"/>
    Thanks and Regards,
    Miguel Motta

    Hi Miguel
    Have a look at below snippets. Here I have tried to escape the text inside TAG3 so that it gets treated as single node during transformation.
    ABAP code
    DATA: BEGIN OF result,
            col1 TYPE string,
            col2 TYPE string,
            col3 TYPE string,
          END OF result.
    DATA: xml_string TYPE string VALUE
    '<ROOT> <TAG1>value1</TAG1> <TAG2>value2</TAG2> <TAG3> <TAG4>value4</TAG4> <TAG5>value5</TAG5> </TAG3> </ROOT>',
          part1 TYPE string,
          part2 TYPE string,
          part3 TYPE string.
    *   Escape the text inside TAG3 tag
    FIND REGEX '(.*<TAG3>)(.*)(</TAG3>.*)' IN xml_string SUBMATCHES part1 part2 part3.
    IF sy-subrc EQ 0.
      part2 = escape( val = part2 format = cl_abap_format=>e_xml_text ).
    *      REPLACE ALL OCCURRENCES OF '<' IN part2 WITH '&lt;'.
    *      REPLACE ALL OCCURRENCES OF '>' IN part2 WITH '&gt;'.
      xml_string = part1 && part2 && part3.
    ENDIF.
    TRY.
    * Display xml
        cl_abap_browser=>show_xml( EXPORTING xml_string = xml_string ).
    * Deserialization
        CALL TRANSFORMATION zmtest
          SOURCE XML xml_string
          RESULT para = result.
    * Check result
        WRITE:/ 'COL1=', result-col1,
              / 'COL2=', result-col2,
              / 'COL3=', result-col3.
      CATCH cx_st_error.
    * Error handling
        MESSAGE 'Error in Simple Transformation'
                TYPE 'I' DISPLAY LIKE 'E'.
    ENDTRY.
    Transformation code
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" template="temp" version="0.1">
       <tt:root name="PARA"/>
       <tt:template name="temp">
         <ROOT>
           <TAG1>
             <tt:value ref="PARA.COL1"/>
           </TAG1>
           <TAG2>
             <tt:value ref="PARA.COL2"/>
           </TAG2>
           <TAG3>
             <tt:value ref="PARA.COL3"/>
           </TAG3>
         </ROOT>
       </tt:template>
    </tt:transform>

  • How to handle abstract XML elements with XMLBeans

    Hello,
    I have an xsd that uses abstract elements, and i wanted to ask you how can i create new XML Documents with XMLBeans? My problems is that i don't know how to handle abstaction with XMLBeans.
    Let me show you a very simple example to make you understand my problem :
    Suppose we have the following schema :
    <xsd:schema targetNamespace="http://www.example.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org">
         <xsd:element name="Customer" type="CustomerType" />
         <xsd:complexType name="CustomerType" abstract="true" />
         <xsd:complexType name="PremiumCustomerType">
              <xsd:complexContent>
                   <xsd:extension base="CustomerType">
                        <xsd:sequence>
                             <xsd:element name="CreditCard" type="xsd:string" />
                        </xsd:sequence>
                   </xsd:extension>
              </xsd:complexContent>
         </xsd:complexType>
    </xsd:schema>I use XMLBeans to create a jar with java classes according the xsd above. Then, in order to create a new xml document i use the following code :
    CustomerDocument cd = CustomerDocument.Factory.newInstance();
    CustomerType ct = cd.addNewCustomer();
    PremiumCustomerType pct = PremiumCustomerType.Factory.newInstance();
    ct.changeType(pct.schemaType());With this code i get an XML Document like the following :
    <Customer type="PremiumCustomerType" />But after that, i cannot add an element CreditCard into this Customer element. Can anyone help me?

    In Indesign there is no way you can directly work on the XML-IN footnote, since indesign won't support XML tags in footnote stream.
    To achive that you need to have XSLT/Perl/Indesign Scripting.
    This task is achievable, you can create a auto footnote for XML workflow projects.
    1. Create an XSLT to transform the footnote to the respective places
    2. Change all the "<" ">" to some standard names, since indesign won't accept XML tags in the footnote stream.
    3. Import it in indesign and using script convert it to autofootnote.
    Shaji

  • ABAP Simple Transformation - How to save XML to file with CL_FX_WRITER?

    Hello!
    When calling a Simple Transformation program for transformation from ABAP to XML, it is possible to specify RESULT XML rxml as a class reference variable of type CL_FX_WRITER, which points to an XML writer.
    How to handle CL_FX_WRITER in order to save XML to a file?
    Thanks and regards,
    Andrey

    Hallo Rainer!
    Many thanks. I have checked the profile parameter ztta/max_memreq_MB and it is set to 2048 MB in the development system. I hope, that won't be less on the client's machine. The only thing I did not clearly explained, is that I need to write XML data to the server. I am so sorry. Downloading to the local PC is very helpful for me also, but only for the test purposes.
    Regards,
    Andrey

  • Simple Transformation with very long XML element names

    I am trying to write a program to deserialize XML documents using the Simple Transformation technique.  There are many optional elements in the XML document, so I need to have conditional statements statements to avoid trying to process elements that are not in the document.  The XML document, however, has several Element Names that are greater than 30 characters in length.  The Simple Transformation technique seems to require ABAP data dictionary structures that mirror the schema of the XML document.  But one cannot create structure component names that are greater than 30 characters in length.  We don't have any control over the XML schema as the XML documents come from the US government.  The ST fragment below shows the statement that I want to write, but since the ABAP Structure PlasticCardInformationGroup cannot have a component AuthorizationResponseInformation, the ST syntax checker yields an "Illegal Reference ADDITIONALPLASTICCARDINFORMATION" error message.
    Does anyone know a way to avoid this error?
    <tt:d-cond check="exist(TRS_TradingPartner_Agreement.TRS_FinancialTransaction.PlasticCardInformationGroup.AdditionalPlasticCardInformation)">
    <ns2:AdditionalPlasticCardInformation>
    <tt:attribute name="CardNetworkType" value-ref="TRS_TRADINGPARTNER_AGREEMENT.TRS_FINANCIALTRANSACTION.PLASTICCARDINFORMATIONGROUP.ADDITIONALPLASTICCARDINFORMATI.CARDNETWORKTYPE"/>
    <tt:attribute name="DraftLocatorNumber" value-ref="TRS_TRADINGPARTNER_AGREEMENT.TRS_FINANCIALTRANSACTION.PLASTICCARDINFORMATIONGROUP.ADDITIONALPLASTICCARDINFORMATI.DRAFTLOCATORNUMBER"/>
    </ns2:AdditionalPlasticCardInformation>

    could anyone help me?

Maybe you are looking for

  • How to open hyperlink of PDF file uploaded at SharePoint(hosted at Office365) in 'Adobe Acrobat' for annotation and comments.

    Hi, I've a hyperlink of PDF file which is uploaded under SharePoint Document library(hosted at Office365 E1) on my custom '../SitePages/Approver.aspx'. Once user click on that hyperlink it should ask me to "Check-Out & Open' pdf file directly from sh

  • System Restore loop

    I just got an 80 GB Ipod for Christmas and things had been going well. I had iTunes all set up and was getting things downloaded onto it. 2 days ago, when I hooked my Ipod up to the computer, it gave me the system recovery message and said I had to r

  • Anybody know about Contact Forms

    Anybody on here know how to configure a contact form from a template i am working on. I can email you the files that i am worknig on, jsut drop me a pm with your email address. Lee Thank you in advance

  • 4.2 Windows reporting free space incorrectly

    I "upgraded" to 4.2 now my Windows Vista 64bit is reporting a 52.5 GB iPad. I purchased a 32 GB iPad.... Why is it reporting as 52.5GB total capacity? I have not yet tried other computers. I have a screen shot but I do not see how I can post it here.

  • Feature request: local noise reduction...

    I love the local corrections in LR2, and I'm using especially the local sharpening feature a lot. But I'm really missing a local noise correction feature (at least for luminance noise). It's such a shame to be able to do about any correction that I n