0

I'm having trouble getting a simple transformation for XML to work in ABAP. I keep getting the exception cx_st_match_element when I try to execute it on a test XML document inside of a report.

I have the following XML that I want to transform into an ABAP internal table:

<?xml version="1.0" encoding="UTF-8"?>
<studenten xmlns="http://www.foo.be/bar/preinschrijvingsflow"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.foo.be/bar/preinschrijvingsflow bar_studenten.xsd">
  <student>
    <barGuid>1</barGuid>
    <familienaam>Doe</familienaam>
    <voornaam>John</voornaam>
    <geslacht>1</geslacht>
    <nationaliteit>BE</nationaliteit>
    <geboortedatum>1995-11-18</geboortedatum>
    <geboorteplaats>Antwerpen</geboorteplaats>
    <email>John.Doe@gmail.com</email>
    <straatNummer>Grote Markt 1 bus 0102</straatNummer>
    <postcode>1000</postcode>
    <gemeente>Brussel</gemeente>
    <land>BE</land>
    <telefoonnummer>+32123456789</telefoonnummer>
    <academiejaar>2021</academiejaar>
  </student>
</studenten>

To this end I defined the following simple transformation I called zc_tr_student:

<?sap.transform simple?>
<tt:transform
  xmlns="http://www.foo.be/bar/preinschrijvingsflow"
  xmlns:tt="http://www.sap.com/transformation-templates"
  xmlns:ddic=" http://www.sap.com/abapxml/types/dictionary">

  <tt:root name="studenten" type="ddic:ZCTT_bar_STUDENT"/>
  <tt:template>
    <studenten>
      <tt:loop ref=".studenten" name="studenten">
        <student>
          <barGuid tt:value-ref="$studenten.bar_guid"/>
          <familienaam tt:value-ref="$studenten.familienaam"/>
          <voornaam tt:value-ref="$studenten.voornaam"/>
          <geslacht tt:value-ref="$studenten.geslacht"/>
          <nationaliteit tt:value-ref="$studenten.nationaliteit"/>
          <geboortedatum tt:value-ref="$studenten.geboortedatum"/>
          <geboorteplaats tt:value-ref="$studenten.geboorteplaats"/>
          <email tt:value-ref="$studenten.email"/>
          <straat_nummer tt:value-ref="$studenten.straat_nummer"/>
          <postcode tt:value-ref="$studenten.postcode"/>
          <gemeente tt:value-ref="$studenten.gemeente"/>
          <land tt:value-ref="$studenten.land"/>
          <telefoonnummer tt:value-ref="$studenten.telefoonnummer"/>
          <academiejaar tt:value-ref="$studenten.academiejaar"/>
        </student>
      </tt:loop>
    </studenten>
  </tt:template>
</tt:transform>

In the tt:value-refattributes I refer to the field in the DDIC line type of the ABAP internal table corresponding to the tag in the XML.

If I call this simple transformation from an ABAP report like this:

call transformation zc_tr_student
source xml lv_bxml
result studenten = p_student.

The cx_st_match_element is thrown.

I validated both the syntax of the file and its adherence to the schema. The XML file and the XSD file are present in the same directory on the application server. I have no idea why the ST fails as the cx_st_match_element instance does not have any useful information except that it expected a studenten element. That element is clearly present in the XML file as the root element.

I'm inexperienced with defining simple transformations and I can't spot my error myself. Thank you in advance for your help,
Joshua

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Joshua Schroijen
  • 376
  • 6
  • 23
  • 3
    The only thing wrong I can see is the typo in `straat_nummer`, which maybe causes the error. When something doesn't work, you should always rewrite your code into minimal code, i.e. just 1 component instead of 14, and continue simplifying until something works, then adding code again, then simplifying again when something goes wrong. – Sandra Rossi Apr 15 '22 at 05:59
  • @SandraRossi thanks for your helpful comment. I'll take a look at the mistake and I'll try using your method to narrow down the problem! – Joshua Schroijen Apr 15 '22 at 08:32
  • Simple Transformations are also debugable, so set a breakpoint in the definition and see at which binding it throws the exception. – peterulb Apr 16 '22 at 21:41

0 Answers0