Skip to Content
0
Jun 16, 2016 at 08:13 PM

Trouble using tt:switch / tt:switch-var in simple transformation

561 Views

Hello gurus,

We are performing a simple transformation on an XML string we retrieve from an external source. A typical sample XML is as follows...

<VEHICLE ID="2064015">

<LON>-121.02363</LON>

<LAT>37.650665</LAT>

<DATE>2016-05-13 06:53:10.0</DATE>

<STREETNAME>Lone Palm Ave</STREETNAME>

<STREETNUM>1127</STREETNUM>

<LANDMARK>1707 Pacific Supply Modesto</LANDMARK>

<LANDMARKADDR>1155 North Emerald Ave</LANDMARKADDR>

<CITY>Modesto</CITY>

<STATE>CA</STATE>

<ODOMETER>10466431</ODOMETER>

<PARAMS>

<PARAM name="Name">GPS Antenna</PARAM>

<PARAM name="Status">Connected</PARAM>

</PARAMS>

</VEHICLE>

The PARAMS tag can have immediate level tags with the "name" attributes "Name" and "Status" that I would like to transform into my ABAP internal table, but it can alternatively have a nested deep structure that I need to ignore if the associated "name" attribute is "bus".

<PARAMS>

<PARAM name="bus">

<bus>

<driver></driver>

<trip/>

<event>O</event>

<eid/>

<desc>Active Fault</desc>

<data>

<datum>

<fmi>3</fmi>

<desc>Auxiliary Pressure #1-VOLTAGE ABOVE NORMAL, OR SHORTED TO HIGH SOURCE</desc>

<oc>126</oc>

<spn>1387</spn>

<lampstaus>0</lampstaus>

<source>49</source>

</datum>

</data>

</bus>

</PARAM>

</PARAMS>

The SAP documentation describes the tt:switch and tt:switch-var commands, but the examples are a bit lacking.

I have made several attempts using tt:read, tt:attribute, tt:assign, tt:skip, etc, trying to save the attribute value into a variable for testing, but I am still getting the same rather vague error message, "System expected a value for the type C".

<?sap.transform simple?>

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">

<tt:root name="ROOT"/>

<tt:root name="ROOTPARAMS"/>

<tt:variable name="PARAMNAME"/>

<tt:template name="ZVM_XML_TO_TAB">

<HISTORY>

<tt:loop name="vehicle" ref=".ROOT">

<VEHICLE>

...

<PARAMS>

<tt:loop name="params" ref="$ref.PARAMS">

<PARAM>

<tt:attribute name="name" ref="var(PARAMNAME)"/>

<tt:switch-var>

<tt:cond-var check="var(PARAMNAME) = 'Name' or var(PARAMNAME) = 'Status'">

<tt:attribute name="name" value-ref="var(PARAMNAME)"/>

<tt:value ref="$params.VMPARAMVALUE"/>

</tt:cond-var>

<tt:cond-var>

</tt:cond-var>

</tt:switch-var>

</PARAM>

</tt:loop>

</PARAMS>

...

</VEHICLE>

</tt:loop>

</HISTORY>

</tt:template>

</tt:transform>

Can anyone please tell me what I am doing wrong with the tt:switch-var statement and how it should be corrected?

Essentially, I need to loop through the PARAMS tags, keeping any values where the name attribute is "Name" or "Status" and excluding any values where the name attribute is "bus" and its associated deep structure content.

Thanks,

Bryan