Skip to Content

Simple Transformation / initial_components not working as expected

I have created a simple transformation to transform from DDIC structures to XML. The structures mimic the XML hierarchy so the conversion is almost 1 to 1.

The problem I'm having is that although some fields have no value, an element is created for them, even when using the initial_components = 'SUPPRESS' option.

This is a simplified version of the real code that has the same behaviour: In this case, DDIC structure YSTESTS has 2 fields: CHARS type CHAR10, and STR type STRING.

ABAP:

REPORT  y_tests2.

DATA:
      gv_initcomp TYPE string,
      xstr    TYPE xstring,
      struct TYPE ystests.


PARAMETERS:
  p_blanks    TYPE c AS CHECKBOX DEFAULT 'X'.

START-OF-SELECTION.

  IF p_blanks = 'X'.
    gv_initcomp = 'INCLUDE'.
  ELSE.
    gv_initcomp = 'SUPPRESS'.
  ENDIF.

* ABAP > XML

  TRY.
      CALL TRANSFORMATION y_tests
        SOURCE data = struct
        RESULT XML xstr
        OPTIONS initial_components = gv_initcomp.
    CATCH cx_transformation_error.
      MESSAGE 'Error en transformación' TYPE 'A'.
  ENDTRY.

  CALL FUNCTION 'SCOL_TRACE_SHOW_XML'
    EXPORTING
      xdoc = xstr.

ST:

<?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="DATA" type="ddic:YSTESTS"></tt:root>

  <tt:template>
    <data tt:ref="DATA">
        <chars tt:value-ref="CHARS"></chars>
        <str tt:value-ref="STR"></str>
    </data>
  </tt:template>

</tt:transform>

The XML output is like this, even when deselecting the P_BLANKS checkbox:

<?xml version="1.0" encoding="utf-8" ?> 
<data>
  <chars></chars> 
  <str></str> 
</data>

The only solution I've found so far is to post-process the resulting XML using the iXML interfaces (DOM processing) to iterate over all the nodes and remove the empty elements, but I sure hope there is a simpler and cleaner way to achieve this.

Am I right?

Many thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Sep 27, 2011 at 04:58 AM

    Hi Alejandro, try this ST:

    <tt:cond s-check="not-initial(ref('CHARS'))">
      <chars tt:value-ref="CHARS"/>
    </tt:cond>
    <tt:cond s-check="not-initial(ref('STR'))">
      <str tt:value-ref="STR"/>
    </tt:cond>

    Regards Jack

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 26, 2011 at 10:22 PM

    Hi Alejandro,

    How did you solve this?

    I have the same problem and I have no idea what is wrong.

    Any help will be highly appreciated.

    Thanks,

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.