Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Create an XML from variables.

0 Kudos

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.

1 ACCEPTED SOLUTION

0 Kudos

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>
12 REPLIES 12

Sandra_Rossi
Active Contributor
0 Kudos

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 ?

0 Kudos

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>

so why dont you remove that tag in transformation? you are wrapping loop inside that tag.

Again, why do you paste image instead of text? (moreover, the image doesn't exactly correspond to the result of your transformation because of the order of attributes, anyway I'm nitpicking...)

You are adding a "tt:loop", so it would be better to show the expected XML with 2 lines, no?

I guess I understand what you want, but it's impossible with XML, it must always have exactly ONE root element,

i.e. this XML is NOT ALLOWED, because it has more than one root element (two) :

<?xml version="1.0" encoding="ISO-8859-1"?>
<Cancelacion Fecha="..." Rfcemisor="...">
  ...
</Cancelacion>
<Cancelacion Fecha="..." Rfcemisor="...">
  ...
</Cancelacion><br>

Instead, you must have ONE root element, for instance, this XML is valid:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Cancelacions>
  <Cancelacion Fecha="..." Rfcemisor="...">
    ...
  </Cancelacion>
  <Cancelacion Fecha="..." Rfcemisor="...">
    ...
  </Cancelacion>
</Cancelacions>

PS: in your transformation, <tt:root name="ROOT" type="?"/> is useless.

0 Kudos

Hello, Its me again, 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?

0 Kudos

If you want only one <Cancelacion>, then remove <tt:loop>

0 Kudos

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

0 Kudos

Please stop using the button "Answer" which means "Solution" in this forum. Instead, use "Comment" (there, you can also use the CODE button).

0 Kudos

cf my comment in your first "answer". Cf my "answer" for only one "Cancelacion" which answers exactly your question.

0 Kudos

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>

0 Kudos

This "solution" is not in line with the question : in the question you have elementary variables, in the solution you use a structure.

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.