2010 Feb 24 9:03 PM
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
2011 Sep 27 5: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
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
2011 Sep 26 11: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,
2011 Sep 27 5: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
2011 Sep 27 5:31 PM
Hi Jack,
Thank you very much for this, it is working, all the initial fields are not displayed. Now is it possible do this for tags with no reference? for instance
<RCPNT_CORP_NM>
<tt:cond s-check="not-initial(ref('L1_NM'))">
<l1_nm>
<tt:value ref="$line.L1_CORP_NM"/>
</l1_nm>
</tt:cond>
<RCPNT_CORP_NM>My tag L1_NM is not displayed if initial, but the parent <RCPNT_CORP_NM> is displayed even when it doesnt have elements. I tried
<tt:cond s-check="not-initial('RCPNT_CORP_NM')">
but didn't work
Edited by: carlosrv on Sep 27, 2011 6:31 PM
2011 Sep 28 2:32 AM
Hi, try this
<tt:cond s-check="not-initial(ref('L1_NM')) or ...">
<RCPNT_CORP_NM>
<tt:cond s-check="not-initial(ref('L1_NM'))">
<l1_nm>
<tt:value ref="$line.L1_CORP_NM"/>
</l1_nm>
...
</tt:cond>
<RCPNT_CORP_NM>
</tt:cond>Regards Jack
2011 Nov 09 11:38 PM
Sorry, haven't received response notifications, and I did this long ago.
What I did was something similar, I used:
<tt:cond check="not-initial(CHARS)">
<chars tt:value-ref="CHARS"/>
</tt:cond>
Regards
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |