Skip to Content

Create an XML from variables.

Helo Guys I need to create an xml like this:

I have these values on variables:

DATA: uuid type string value 'e9e646b.....',

rfc type string value 'XEXX01010100'.,

total type sring value '0',

fecha type string value '2019-01-28T18:18:30'.

Can anyone tell me what I need to do to create this xml with my values? I think I could do this with CONCATENATE but I think that this solution its not better. Is there an other best way to do this?

thanks.

variables.png (30.7 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Feb 14 at 03:32 PM
    -2

    I solved my problem, here my code:

    <?sap.transform simple?>
    
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
    
      <tt:root name="ROOT" type="?"/>
    
      <tt:root name="CANCELACION" type="ddic:ZSDWA_CANCELACION_FOLIO"/>
    
      <tt:template>
    
        <CANCELACION>
    
          <tt:attribute name="Rfcemisor" value-ref=".CANCELACION.RFCEMISOR"/>
    
          <tt:attribute name="Fecha" value-ref=".CANCELACION.FECHA"/>
    
          <Folios>
    
            <UUID tt:value-ref=".CANCELACION.FOLIOS.UUID"/>
    
            <rfcreceptor tt:value-ref=".CANCELACION.FOLIOS.RFCRECEPTOR"/>
    
            <total tt:value-ref=".CANCELACION.FOLIOS.TOTAL"/>
    
          </Folios>
    
        </CANCELACION>
    
      </tt:template>
    
    </tt:transform>
    Add comment
    10|10000 characters needed characters exceeded

    • Im really confused what are you doing because at first you build a transform with loop so i supposed you want to send a table to transform but at this answer you solved it by remove the loop...So the real solution have been provided to you but your issue is dont know about XML structure, at this point i think you may remove the loop from transform and call the transform in a loop in abap, if this is a case you still dont get that XML structure need a root node...or what are you trying to do is something else.

  • Feb 12 at 07:18 PM

    Create the Simple Transformation ZST (transaction STRANS):

    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ss="cc">
      <tt:root name="RFCROOT"/>
      <tt:root name="UUIDROOT"/>
      <tt:template>
        <Cancelacion>
          <tt:attribute name="RfcEmisor" value-ref=".RFCROOT"/>
          <Folios>
            <UUID tt:value-ref=".UUIDROOT"/>
          </Folios>
        </Cancelacion>
      </tt:template>
    </tt:transform>

    (I let you do the missing parts)

    Create this ABAP code:

    DATA: uuid type string value 'e9e646b.....',
    rfc type string value 'XEXX01010100',
    xml TYPE xstring.
    CALL TRANSFORMATION zst SOURCE rfcroot = rfc uuidroot = uuid RESULT XML xml.

    The encoding is then UTF-8 on Unicode systems (7.5* are Unicode now), but the receiver system should interpret both encodings correctly.

    PS: but why people paste image instead of text, should the people answering have to spend time to convert it to text ?

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 12 at 11:45 PM
    -1

    Hello Sandra, Thanks for you respnse,

    I did a transformation, and I get my XML in this format:

    but I need my xml in the format like follow:

    Can you please help me? My xml code its follow:

    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
      <tt:root name="ROOT" type="?"/>
      <tt:root name="CANCELACION" type="ddic:ZSDTT_XML_CANCELACION"/>
      <tt:template>
        <Cancelacion>
          <tt:loop ref=".CANCELACION">
            <Cancelacion>
              <tt:attribute name="Fecha" value-ref="FECHA"/>
              <tt:attribute name="Rfcemisor" value-ref="RFCEMISOR"/>
              <Folios>
                <UUID tt:value-ref="FOLIOS.UUID"/>
                <rfcreceptor tt:value-ref="FOLIOS.RFCRECEPTOR"/>
                <total tt:value-ref="FOLIOS.TOTAL"/>
              </Folios>
            </Cancelacion>
          </tt:loop>
        </Cancelacion>
      </tt:template>
    </tt:transform>
    

    xml1.png (34.0 kB)
    xml-2.png (30.4 kB)
    Add comment
    10|10000 characters needed characters exceeded

  • Feb 13 at 08:50 PM
    -1

    Hi Sandra,

    Sorry for images, I dont know why I have 2 <Cancelacion> Elements, is there any way to have only one like my reques?

    I am looking for examples like I need but all examples does not have an XML structure like I need, its not possible to do a transformation as I need?

    My transformation:

    <?sap.transform simple?>
    
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
    
    
    
      <tt:root name="CANCELACION" type="ddic:ZSDTT_XML_CANCELACION"/>
    
      <tt:template>
    
        <Cancelacion>
    
          <tt:loop ref=".CANCELACION">
    
            <Cancelacion>
    
              <tt:attribute name="Fecha" value-ref="FECHA"/>
    
              <tt:attribute name="Rfcemisor" value-ref="RFCEMISOR"/>
    
              <Folios>
    
                <UUID tt:value-ref="FOLIOS.UUID"/>
    
                <rfcreceptor tt:value-ref="FOLIOS.RFCRECEPTOR"/>
    
                <total tt:value-ref="FOLIOS.TOTAL"/>
    
              </Folios>
    
            </Cancelacion>
    
          </tt:loop>
    
        </Cancelacion>
    
      </tt:template>
    
    </tt:transform>
    
    

    I need an XML like follow

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <Cancelacion RfcEmisor="AAA010101AAA" Fecha="2019-01-28T18:18:30"><Folios>
    
    <UUID>e9a646bb-f131-4d4e-aa0e-d0cc80e927a6</UUID>
    
    <rfcreceptor>XEXX010101000</rfcreceptor>
    
    <total>0</total>
    
    </Folios>
    
    </Cancelacion>

    Thaks

    Add comment
    10|10000 characters needed characters exceeded