Simple transformation Closing tag
Hi all,
again, i´ve a question concering simple tansformation. The following snippet is part of my ST programm
<tt:loop name="F" ref=".ROOT2">
<Batch>
<tt:attribute name="Number" value-ref="$F.label_lfdnr"></tt:attribute>
<tt:loop name="F1" ref="$F.LABEL_DATA">
<F>
<tt:value ref="$F1.FIELDCONTENT"></tt:value>
</F>
</tt:loop>
</Batch>
</tt:loop>
Everything works fin so far. The only problem is, that if
"$F1.FIELDCONTENT"
is initial. The ST programm outputs .
Anybody has an idea how to achieve this in ST. The ST documents "writes" into an IF_XML_DOCUMENT.
Thanks for any hints,
Andy
Hi Edgar,
you should define <blocks> element as optional using <tt:cond>
More information : http://help.sap.com/saphelp_nw70/helpdata/en/0c/402040abf2c442e10000000a1550b0/frameset.htm
BR
Sandra
Similar Messages
-
Simple Transformation - Optional Tag
Hi,
I receive an XML from an called web service. Depending on the ws input I receive a diferent result XML.
Result 1:
<LdPat3D>
<Blocks>
<Block>
<Block>
<Blocks/>
</LdPat3D>
Result 2:
<LdPat3D/>
The simple transformation works for Result 1, but not for Result 2. In case of Result 2 a CX_ST_MATCH_ELEMENT exception
occurs mentioning that element-start blocks is expected and element-end: "LdPat3D" [ ] is read.
Could you please tell me how to handle this in my simple transformation?
Thank you and best regards, EdgarHi Edgar,
you should define <blocks> element as optional using <tt:cond>
More information : http://help.sap.com/saphelp_nw70/helpdata/en/0c/402040abf2c442e10000000a1550b0/frameset.htm
BR
Sandra -
Closing tag in xml transformation
Hi experts,
I have the following ABAP code:
ABAP itab to XML string
CALL TRANSFORMATION id SOURCE data = ti_stocks[]
RESULT XML ps_output.
The result in ps_output should be an xml like this
<?xml version="1.0" encoding="utf-16" ?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DATA>
<ZTABLE_STO>
<FIELD1 /> ABC</FIELD1>
<FIELD2 />0300</FIELD2>
<FIELD3 />1</FIELD3>
</ZTABLE_STO>
etc.
However, if my internal table ti_stocks contains the field1 with an empty value then the xml is incorrect without its corresponding closing tag:
<?xml version="1.0" encoding="utf-16" ?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DATA>
<ZTABLE_STO>
<FIELD1 />
<FIELD2 />0300</FIELD2>
<FIELD3 />1</FIELD3>
</ZTABLE_STO>
etc.
How can I resolve this problem? I would like to have an open tag and a closing tag for every field.
FIELD1 is a char type field.
Thank you,
Oscar
Edited by: Oscar Arranz on Jan 26, 2012 2:46 PMHello everyone, sorry for my english, I had the same requeriment for the end tag, the simple transformation give this result <xxx/> when the value was empty, and I did something similar to Oscar,
i did the simple transformation and the result whas and xstring, i used a function to pass it to string, and then I make a replacement.
here is some code:
* Genera XML
data: xml_xstring type xstring.
data: w_xml type string.
data: ixml type ref to if_ixml,
streamfactory type ref to if_ixml_stream_factory,
encoding type ref to if_ixml_encoding,
ixml_ostream type ref to if_ixml_ostream.
data: resstream type ref to if_ixml_ostream.
****Create an instance of the Ixml Processor
ixml = cl_ixml=>create( ).
* ****Create the Stream Factory
streamfactory = ixml->create_stream_factory( ).
* ****Create an Endcoding and Byte Order
encoding = ixml->create_encoding( character_set = 'ISO-8859-1' byte_order = 0 ).
* * ****Create the output stream with a pointer to our binary string
ixml_ostream = streamfactory->create_ostream_xstring( xml_xstring ).
* ****Set the Encoding into a stream
ixml_ostream->set_encoding( encoding = encoding ).
****Call simple Transformation
call transformation zdte_libros
source zcaratula = x_doc
result xml ixml_ostream.
*From xstring to string.
call function 'HR_RU_CONVERT_HEX_TO_STRING'
exporting
xstring = xml_xstring
importing
cstring = w_xml.
* <xxx/> to <xxx><xxx/>
replace all occurrences of regex '<([^><\s]+)( [^><]+)?/>' in w_xml with '<$1$2></$1>'.
Hope it helps someone with the same problem . -
Simple Transformation XML to ABAP Content of tag with subtrees to string field
Hi,
I have an requirement in which I have to do a transformation from an XML file to an structure.
I need get the value of a tag that have subtrees and move that to a field in my structure.
Example:
<TAG1>value1</TAG1>
<TAG2>value2</TAG2>
<TAG3>
<TAG4>value4</TAG4>
<TAG5>value5</TAG5>
</TAG3>
Result expected in ABAP Structure:
field1 -> tag1
field2 -> tag2
field3 -> <TAG4>value4</TAG4><TAG5>value5</TAG5>
The contents of the tag TAG3 is variable, so I want to store it as a string.
Can I make this with Simple Transformation?
In my tests I can move only the value of each child tag for the given field structure.
This syntax dont work:
<TAG3 tt:value-ref="STRUCTURE.FIELD3"/>
Thanks and Regards,
Miguel MottaHi Miguel
Have a look at below snippets. Here I have tried to escape the text inside TAG3 so that it gets treated as single node during transformation.
ABAP code
DATA: BEGIN OF result,
col1 TYPE string,
col2 TYPE string,
col3 TYPE string,
END OF result.
DATA: xml_string TYPE string VALUE
'<ROOT> <TAG1>value1</TAG1> <TAG2>value2</TAG2> <TAG3> <TAG4>value4</TAG4> <TAG5>value5</TAG5> </TAG3> </ROOT>',
part1 TYPE string,
part2 TYPE string,
part3 TYPE string.
* Escape the text inside TAG3 tag
FIND REGEX '(.*<TAG3>)(.*)(</TAG3>.*)' IN xml_string SUBMATCHES part1 part2 part3.
IF sy-subrc EQ 0.
part2 = escape( val = part2 format = cl_abap_format=>e_xml_text ).
* REPLACE ALL OCCURRENCES OF '<' IN part2 WITH '<'.
* REPLACE ALL OCCURRENCES OF '>' IN part2 WITH '>'.
xml_string = part1 && part2 && part3.
ENDIF.
TRY.
* Display xml
cl_abap_browser=>show_xml( EXPORTING xml_string = xml_string ).
* Deserialization
CALL TRANSFORMATION zmtest
SOURCE XML xml_string
RESULT para = result.
* Check result
WRITE:/ 'COL1=', result-col1,
/ 'COL2=', result-col2,
/ 'COL3=', result-col3.
CATCH cx_st_error.
* Error handling
MESSAGE 'Error in Simple Transformation'
TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
Transformation code
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" template="temp" version="0.1">
<tt:root name="PARA"/>
<tt:template name="temp">
<ROOT>
<TAG1>
<tt:value ref="PARA.COL1"/>
</TAG1>
<TAG2>
<tt:value ref="PARA.COL2"/>
</TAG2>
<TAG3>
<tt:value ref="PARA.COL3"/>
</TAG3>
</ROOT>
</tt:template>
</tt:transform> -
How to skip XML tags in Simple transformation
Hi,
I am trying to convert an XML file to ABAP code using Simple Transformations.
I tired converting a small XML file to ABAP using it and it worked fine.
The problem is that the number of tags in the XML file I now want to parse is huge (over 200).
Is there any way that for the tag in XML corresponding tag is not created in ST? Is there any conditional tag to achieve this?
Also, is Simple Transformation a better way of parsing in such a scenario over XSLT and DOM parser?
Thanks and Regards,
Neha
Edited by: Neha Anand on Jun 2, 2008 1:19 PMHi Raja,
I have already looked through the code snippets and I am able to write a CALL TRANSFORMATION.
I want to find out if the number of tags is huge then if there is any way that some tags can be skipped for matching tags in XML which anyhow I dont need for manipulation.
Thanks and Regards,
Neha -
Dynamic TAG - Simple Transformation
Hi All,
I need work with dynamic TAGS (Elements) on Simple Transformation?
The tag should be <Invoice> or <DebitNote> depending on a Variable.
How can I achieve this?
Thanks and Regards,We work with Microsoft Outlook, but I'm sure this could work with any email system.
This error only came from external emails - what we did in the end is to get the third party to email a particular email (email1) in our company. This is set up as a regular email account. On this email put a forward rule to email2 for a particular sender/subject. email2 is set up as POP3 so that XD1 can poll it - we also block any emails except from email1.
Doing this accomplishes a couple of things:
1) We get around the error because XI polls email2 (which has adapter settings of IMAP4 so we can see MAIL adapter attributes ie. sender, subject etc...When we originally had as POP3 we were not able to see these - but setting as IMAP4 causes the error for external emailers)
2) We have a SPAM filter - the XI email is clean from SPAM and the adapter will not have errors, as it only receives valid emails to process
3) We have a central email (email1) which is used to archive all XI emails - we use this for all email scenarios (as we also save to folder and forward in the rule)
Hope this helps your situation. -
Create xml tag dynamically within simple transformation
Hi all together,
I'm faceing the following problem:
There is a internal table provided, consisting of name/value-pairs. Something like
ls_struc-name = 'NAME1'.
ls_struc-value = 'XYZ'.
append ls_struc to lt_struc
ls_struc-name = 'CITY1'.
ls_struc-value = 'Munich'.
append ls_struc to lt_struc
and so on.
I have to create this XML (with simple transformation):
<NAME1>XYZ</NAME1>
<CITY1>Munich</CITY1>
Everythings works fine so far (tables, values etc.), but I have problems with creating the XML-Tag, e.g <NAME1> from "$line.name" within the transformation. I don't have any information about the data structure (therefore "call transaction id" does not work).
Any hint is useful!!!
Best regards,
ThomasExaple program for creating XML file from abap
REPORT z_xit_xml_dom_create.
TYPE-POOLS: ixml.
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_ostream TYPE REF TO if_ixml_ostream,
l_renderer TYPE REF TO if_ixml_renderer,
l_document TYPE REF TO if_ixml_document.
DATA: l_element_flights TYPE REF TO if_ixml_element,
l_element_airline TYPE REF TO if_ixml_element,
l_element_flight TYPE REF TO if_ixml_element,
l_element_from TYPE REF TO if_ixml_element,
l_element_to TYPE REF TO if_ixml_element,
l_element_dummy TYPE REF TO if_ixml_element,
l_value TYPE string.
DATA: l_xml_table TYPE TABLE OF xml_line,
l_xml_size TYPE i,
l_rc TYPE i.
DATA: lt_spfli TYPE TABLE OF spfli.
DATA: l_spfli TYPE spfli.
START-OF-SELECTION.
* Fill the internal table
SELECT * FROM spfli INTO TABLE lt_spfli.
* Sort internal table
SORT lt_spfli BY carrid.
* Start filling xml dom object from internal table
LOOP AT lt_spfli INTO l_spfli.
AT FIRST.
* Creating a ixml factory
l_ixml = cl_ixml=>create( ).
* Creating the dom object model
l_document = l_ixml->create_document( ).
* Fill root node with value flights
l_element_flights = l_document->create_simple_element(
name = 'flights'
parent = l_document ).
ENDAT.
AT NEW carrid.
* Create element 'airline' as child of 'flights'
l_element_airline = l_document->create_simple_element(
name = 'airline'
parent = l_element_flights ).
* Create attribute 'code' of node 'airline'
l_value = l_spfli-carrid.
l_rc = l_element_airline->set_attribute( name = 'code' value = l_value ).
* Create attribute 'name' of node 'airline'
SELECT SINGLE carrname FROM scarr INTO l_value WHERE carrid EQ l_spfli-carrid.
l_rc = l_element_airline->set_attribute( name = 'name' value = l_value ).
ENDAT.
AT NEW connid.
* Create element 'flight' as child of 'airline'
l_element_flight = l_document->create_simple_element(
name = 'flight'
parent = l_element_airline ).
* Create attribute 'number' of node 'flight'
l_value = l_spfli-connid.
l_rc = l_element_flight->set_attribute( name = 'number' value = l_value ).
ENDAT.
* Create element 'from' as child of 'flight'
CONCATENATE l_spfli-cityfrom ',' l_spfli-countryfr INTO l_value.
l_element_from = l_document->create_simple_element(
name = 'from'
value = l_value
parent = l_element_flight ).
* Create attribute 'airport' of node 'from'
l_value = l_spfli-airpfrom.
l_rc = l_element_from->set_attribute( name = 'airport' value = l_value ).
* Create element 'to' as child of 'flight'
CONCATENATE l_spfli-cityto ',' l_spfli-countryto INTO l_value.
l_element_to = l_document->create_simple_element(
name = 'to'
value = l_value
parent = l_element_flight ).
* Create attribute 'airport' of node 'from'
l_value = l_spfli-airpto.
l_rc = l_element_to->set_attribute( name = 'airport' value = l_value ).
* Create element 'departure' as child of 'flight'
l_value = l_spfli-deptime.
l_element_dummy = l_document->create_simple_element(
name = 'departure'
value = l_value
parent = l_element_flight ).
* Create element 'arrival' as child of 'flight'
l_value = l_spfli-arrtime.
l_element_dummy = l_document->create_simple_element(
name = 'arrival'
value = l_value
parent = l_element_flight ).
* Create element 'type' as child of 'flight'
CASE l_spfli-fltype.
WHEN 'X'.
l_value = 'Charter'.
WHEN OTHERS.
l_value = 'Scheduled'.
ENDCASE.
l_element_dummy = l_document->create_simple_element(
name = 'type'
value = l_value
parent = l_element_flight ).
ENDLOOP.
IF sy-subrc NE 0.
MESSAGE 'No data into db table ''spfli'', please run program ''SAPBC_DATA_GENERATOR'' with transaction ''SA38''' TYPE 'E'.
ENDIF.
* Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
* Connect internal XML table to stream factory
l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).
* Rendering the document
l_renderer = l_ixml->create_renderer( ostream = l_ostream
document = l_document ).
l_rc = l_renderer->render( ).
* Saving the XML document
l_xml_size = l_ostream->get_num_written_raw( ).
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = l_xml_size
filename = 'c:\temp\flights.xml'
filetype = 'BIN'
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 24.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. -
Self closing tags appearing in xquery
I am working on a migration project where the weblogic is getting migrated from weblogic 8 to 10.x
my application uses xquery and when upgraded to higher version i can see some self closing tags getting created in the transformed xml which is not the case with 8.1.
for example:
I have given a simple declaration as below
let $a := <find an attribute value>
return
<abc:value>{$a}</abc:value>
if the "find an attribute value" returns null then in weblogic 8 the node will not be sent in transformed xml but in weblogic10.x it is parsing the node as self closing one like <abc:value/>
Is this an issue with migration? I know that the xquery upgraded to 2004 and I did took care of that part.So workaround for me in this case would be? as i have number of direct mappings happening in my code of 8.1 and definitely I can't keep an if else block to make it work.
Well, as you've been relying on a bug then I guess you now have to correct your code.
I don't see how you can do it without using a conditional block. -
Simple Transformation XML to ABAP - error CX_ST_MATCH_ELEMENT
Hi all,
I have a problem with a transformation from xml to abap. My XML file (taken from a pdf file) is
<?xml version="1.0" encoding="iso-8859-1" ?>
- <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
- <asx:values>
<NETWORK>E60000000000</NETWORK>
<OPERAZIONE>0010</OPERAZIONE>
- <TABELLA>
- <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">
<MANDT>300</MANDT>
<NETWORK>E60000000000</NETWORK>
<OPERAZIONE>0010</OPERAZIONE>
<ID_ACT>1</ID_ACT>
<DESC_ACT>ATTIVITÀ1</DESC_ACT>
<LONG_TXT></LONG_TXT>
<MAKE_BUY></MAKE_BUY>
<WP></WP>
<EVENTO_TECH></EVENTO_TECH>
<TIPO_LEGAME></TIPO_LEGAME>
<CONSEGNA></CONSEGNA>
</ROW>
- <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">
<MANDT>300</MANDT>
<NETWORK>E60000000000</NETWORK>
<OPERAZIONE>0010</OPERAZIONE>
<ID_ACT>2</ID_ACT>
<DESC_ACT>ATTIVITÀ2</DESC_ACT>
<LONG_TXT>ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2</LONG_TXT>
<MAKE_BUY>M</MAKE_BUY>
<WP></WP>
<EVENTO_TECH></EVENTO_TECH>
<TIPO_LEGAME></TIPO_LEGAME>
<CONSEGNA></CONSEGNA>
</ROW>
</TABELLA>
</asx:values>
</asx:abap>
my transformation is
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"></tt:root>
<tt:root name="NETWORK"></tt:root>
<tt:root name="OPERAZIONE"></tt:root>
<tt:template>
<abap>
<values>
<network>
<tt:value ref="NETWORK"></tt:value>
</network>
<operazione>
<tt:value ref="OPERAZIONE"></tt:value>
</operazione>
<tabella>
<tt:loop ref=".ROOT" name="line">
<mandt>
<tt:value ref="$line.mandt"></tt:value>
</mandt>
<network>
<tt:value ref="$line.network"></tt:value>
</network>
<OPERAZIONE>
<tt:value ref="$line.OPERAZIONE"></tt:value>
</OPERAZIONE>
<ID_ACT>
<tt:value ref="$line.ID_ACT"></tt:value>
</ID_ACT>
<DESC_ACT>
<tt:value ref="$line.DESC_ACT"></tt:value>
</DESC_ACT>
<LONG_TXT>
<tt:value ref="$line.LONG_TXT"></tt:value>
</LONG_TXT>
<MAKE_BUY>
<tt:value ref="$line.MAKE_BUY"></tt:value>
</MAKE_BUY>
<WP>
<tt:value ref="$line.WP"></tt:value>
</WP>
<EVENTO_TECH>
<tt:value ref="$line.EVENTO_TECH"></tt:value>
</EVENTO_TECH>
<TIPO_LEGAME>
<tt:value ref="$line.TIPO_LEGAME"></tt:value>
</TIPO_LEGAME>
<CONSEGNA>
<tt:value ref="$line.CONSEGNA"></tt:value>
</CONSEGNA>
</tt:loop>
</tabella>
</values>
</abap>
</tt:template>
</tt:transform>
when I execute my code
the system dump with this error
ST_MATCH_FAIL
excep. CX_ST_MATCH_ELEMENT
TRY.
CALL TRANSFORMATION ('ZT_NETWORK')
SOURCE XML lv_xml_data_string
RESULT network = l_network
operazione = l_operazione
root = it_data_tmp.
CATCH cx_sy_conversion_data_loss .
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
WRITE:/ xslt_message .
ENDTRY.
Any help?
thanks
enzoEnzo Porcasi wrote:
> I have a problem with a transformation from xml to abap. My XML file (taken from a pdf file) is
>
<?xml version="1.0" encoding="iso-8859-1" ?>
> <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
> <asx:values>
Your XML is strange, it looks like a mix of pdf form content (xfa) and identity transformation (asx).
Could you explain more ?
Anyway, I tried to find out the errors (not only cx_st_match_element, that was just a catch missing), it works with the following program. Here are the main issues I have found :
- always catch exception class cx_st_error when you use simple transformations (it contains cx_st_match_element and all other simple transformation exceptions)
- xml "asx:abap" and "asx:values" in your input XML are useless, they are only used by identity transformation ("ID"); you may keep them if you want, but I advise you to see why they are in the xml !
- Use same case in your tags (if xml contains in the transformation so that it corresponds to the input XML
- I renamed all abap names with prefix ABAP_ so that to clearly differentiate xml tags and abap field names (so that it is more easy to understand, for every sdn reader; I hope it will help as I didn't find many threads in the forum).
Simple transformation :
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ABAP_NETWORK"></tt:root>
<tt:root name="ABAP_OPERAZIONE"></tt:root>
<tt:root name="ABAP_TABELLA"></tt:root>
<tt:template>
<ROOT>
<NETWORK>
<tt:value ref=".ABAP_NETWORK"></tt:value>
</NETWORK>
<OPERAZIONE>
<tt:value ref=".ABAP_OPERAZIONE"></tt:value>
</OPERAZIONE>
<TABELLA>
<tt:loop ref=".ABAP_TABELLA" name="line">
<ROW>
<MANDT>
<tt:value ref="$line.ABAP_MANDT"></tt:value>
</MANDT>
<NETWORK>
<tt:value ref="$line.ABAP_NETWORK"></tt:value>
</NETWORK>
<OPERAZIONE>
<tt:value ref="$line.ABAP_OPERAZIONE"></tt:value>
</OPERAZIONE>
<ID_ACT>
<tt:value ref="$line.ABAP_ID_ACT"></tt:value>
</ID_ACT>
<DESC_ACT>
<tt:value ref="$line.ABAP_DESC_ACT"></tt:value>
</DESC_ACT>
<LONG_TXT>
<tt:value ref="$line.ABAP_LONG_TXT"></tt:value>
</LONG_TXT>
<MAKE_BUY>
<tt:value ref="$line.ABAP_MAKE_BUY"></tt:value>
</MAKE_BUY>
<WP>
<tt:value ref="$line.ABAP_WP"></tt:value>
</WP>
<EVENTO_TECH>
<tt:value ref="$line.ABAP_EVENTO_TECH"></tt:value>
</EVENTO_TECH>
<TIPO_LEGAME>
<tt:value ref="$line.ABAP_TIPO_LEGAME"></tt:value>
</TIPO_LEGAME>
<CONSEGNA>
<tt:value ref="$line.ABAP_CONSEGNA"></tt:value>
</CONSEGNA>
</ROW>
</tt:loop>
</TABELLA>
</ROOT>
</tt:template>
</tt:transform>
Program and XML included :
REPORT zsro2.
DATA l_network TYPE string.
DATA l_operazione TYPE string.
DATA : BEGIN OF lt_data_tmp OCCURS 0,
abap_mandt TYPE string,
abap_network TYPE string,
abap_operazione TYPE string,
abap_id_act TYPE string,
abap_desc_act TYPE string,
abap_long_txt TYPE string,
abap_make_buy TYPE string,
abap_wp TYPE string,
abap_evento_tech TYPE string,
abap_tipo_legame TYPE string,
abap_consegna TYPE string,
END OF lt_data_tmp.
DATA xslt_error TYPE REF TO cx_xslt_exception.
DATA lo_st_error TYPE REF TO cx_st_error.
DATA lv_xml_data_string TYPE string.
DATA xslt_message TYPE string.
DEFINE conc.
concatenate lv_xml_data_string &1 into lv_xml_data_string.
END-OF-DEFINITION.
*conc '<?xml version="1.0" encoding="iso-8859-1" ?>'.
*conc '<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">'.
*conc ' <asx:values>'.
conc ' <ROOT>'.
conc ' <NETWORK>E60000000000</NETWORK> '.
conc ' <OPERAZIONE>0010</OPERAZIONE> '.
conc ' <TABELLA>'.
conc ' <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">'.
conc ' <MANDT>300</MANDT> '.
conc ' <NETWORK>E60000000000</NETWORK> '.
conc ' <OPERAZIONE>0010</OPERAZIONE> '.
conc ' <ID_ACT>1</ID_ACT> '.
conc ' <DESC_ACT>ATTIVITÀ1</DESC_ACT> '.
conc ' <LONG_TXT></LONG_TXT> '.
conc ' <MAKE_BUY></MAKE_BUY> '.
conc ' <WP></WP> '.
conc ' <EVENTO_TECH></EVENTO_TECH> '.
conc ' <TIPO_LEGAME></TIPO_LEGAME> '.
conc ' <CONSEGNA></CONSEGNA> '.
conc ' </ROW>'.
conc ' <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">'.
conc ' <MANDT>300</MANDT> '.
conc ' <NETWORK>E60000000000</NETWORK> '.
conc ' <OPERAZIONE>0010</OPERAZIONE> '.
conc ' <ID_ACT>2</ID_ACT> '.
conc ' <DESC_ACT>ATTIVITÀ2</DESC_ACT> '.
conc ' <LONG_TXT>ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2</LONG_TXT> '.
conc ' <MAKE_BUY>M</MAKE_BUY> '.
conc ' <WP></WP> '.
conc ' <EVENTO_TECH></EVENTO_TECH> '.
conc ' <TIPO_LEGAME></TIPO_LEGAME> '.
conc ' <CONSEGNA></CONSEGNA> '.
conc ' </ROW>'.
conc ' </TABELLA>'.
conc ' </ROOT>'.
*conc ' </asx:values>'.
*conc '</asx:abap>'.
DATA lv_xml_data_string_2 TYPE string.
TRY.
CALL TRANSFORMATION zsro
SOURCE
XML lv_xml_data_string
RESULT
abap_network = l_network
abap_operazione = l_operazione
abap_tabella = lt_data_tmp[].
CATCH cx_sy_conversion_data_loss .
CATCH cx_st_error INTO lo_st_error.
xslt_message = lo_st_error->get_text( ).
WRITE:/ xslt_message .
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
WRITE:/ xslt_message .
ENDTRY.
BREAK-POINT. -
Problem with Simple Transformation
Hi to all
I am working with ST, and have the following issue:
I have a highly nested xml structure, and, when I execute a abap program with a myself ST, only the last one data is passed to internal tables.
I want to know: how can I do to get that all the information from xml file to store to internal tables but not only the latest information structure?
For example I have the following xml file, and only the last occurence of <PSMService> is update in internal tables.
Thank you very much for your help.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvoicingInformation>
<Services>
<PSMServices>
<PSMService ContractCode="STF0996" InvoicePeriod="2011-01-31T00:00:00-06:00" ReceiptPointCode="347">
<Transactions>
<Transaction ReceiptPointCode="347" DeliveryPointCode="167" ExitTramoCode="15" SectorCode="SECTP_GNV">
</Transaction>
</Transactions>
<DailyCharges>
<DailyCharge ChargeCode="CHRGS_FIJO" Date="2011-01-01T00:00:00-06:00" Quantity="93" QuantityUnit="KPC">
</DailyCharge>
<DailyCharge ChargeCode="CHRGS_FIJO_COP" Date="2011-01-01T00:00:00-06:00" Quantity="93" QuantityUnit="KPC">
</DailyCharge>
</DailyCharges>
<AggregateCharges>
<AggregateCharge ChargeCode="CHRGS_DESVIO" IsTiered="false" Quantity="0" QuantityUnit="KPC" CurrencyCode="COP">
</AggregateCharge>
<AggregateCharge ChargeCode="CHRGS_DESVIO_US$" IsTiered="false" Quantity="0" QuantityUnit="KPC" CurrencyCode="USD">
</AggregateCharge>
</AggregateCharges>
</PSMService>
<PSMService ContractCode="STF0996" InvoicePeriod="2011-01-31T00:00:00-06:00" ReceiptPointCode="347">
<Transactions>
<Transaction ReceiptPointCode="347" DeliveryPointCode="192A" ExitTramoCode="16" SectorCode="SECTP_GNV">
</Transaction>
</Transactions>
<DailyCharges>
<DailyCharge ChargeCode="CHRGS_FIJO" Date="2011-01-01T00:00:00-06:00" Quantity="112" QuantityUnit="KPC">
</DailyCharge>
<DailyCharge ChargeCode="CHRGS_FIJO_COP" Date="2011-01-01T00:00:00-06:00" Quantity="112" QuantityUnit="KPC">
</DailyCharge>
</DailyCharges>
<AggregateCharges>
<AggregateCharge ChargeCode="CHRGS_FIJO" IsTiered="false" Quantity="560" QuantityUnit="KPC" CurrencyCode="USD">
</AggregateCharge>
<AggregateCharge ChargeCode="CHRGS_FIJO_COP" IsTiered="false" Quantity="560" QuantityUnit="KPC" CurrencyCode="COP">
</AggregateCharge>
</AggregateCharges>
</PSMService>
<PSMService ContractCode="STF0996" InvoicePeriod="2011-01-31T00:00:00-06:00" ReceiptPointCode="360">
<Transactions>
<Transaction ReceiptPointCode="260A" DeliveryPointCode="167" ExitTramoCode="15" SectorCode="SECTP_GNV">
</Transaction>
<Transaction ReceiptPointCode="260B" DeliveryPointCode="168" ExitTramoCode="15" SectorCode="SECTP_GNV">
</Transaction>
</Transactions>
<DailyCharges>
<DailyCharge ChargeCode="CHRGS_DESVIO" Date="2011-01-01T00:00:00-06:00" Quantity="0" QuantityUnit="KPC">
</DailyCharge>
<DailyCharge ChargeCode="CHRGS_DESVIO_US$" Date="2011-01-01T00:00:00-06:00" Quantity="0" QuantityUnit="KPC">
</DailyCharge>
</DailyCharges>
<AggregateCharges>
<AggregateCharge ChargeCode="CHRGS_DESVIO" IsTiered="false" Quantity="0" QuantityUnit="KPC" CurrencyCode="COP">
</AggregateCharge>
<AggregateCharge ChargeCode="CHRGS_DESVIO_US$" IsTiered="false" Quantity="0" QuantityUnit="KPC" CurrencyCode="USD">
</AggregateCharge>
</AggregateCharges>
</PSMService>
</PSMServices>
</Services>
</InvoicingInformation>
Edited by: Thomas Zloch on May 10, 2011 12:46 PM - code tags addedHi Charles.
Thank you.
This is a piece of the simple transformation:
<Services>
<!-- PSM Services -->
<PSMServices tt:extensible="deep-dynamic">
<tt:loop name="PSMService" ref="TABLA_PSM_SERVICES">
<PSMService tt:extensible="deep-dynamic">
<tt:attribute name="ContractCode" value-ref="$PSMService.ContractCode"/>
<tt:attribute name="InvoicePeriod" value-ref="$PSMService.InvoicePeriod"/>
<tt:attribute name="ReceiptPointCode" value-ref="$PSMService.ReceiptPointCode"/>
<tt:attribute name="DeliveryPointCode" value-ref="$PSMService.DeliveryPointCode"/>
<tt:attribute name="ExitTramoCode" value-ref="$PSMService.ExitTramoCode"/>
<tt:attribute name="SectorCode" value-ref="$PSMService.SectorCode"/>
<tt:attribute name="MarketCode" value-ref="$PSMService.MarketCode"/>
<tt:attribute name="TransportMarketCode" value-ref="$PSMService.TransportMarketCode"/>
<tt:attribute name="InvoiceBy" value-ref="$PSMService.InvoiceBy"/>
<tt:attribute name="MarketCapacity" value-ref="$PSMService.MarketCapacity"/>
<tt:attribute name="MarketCapacityUnitCode" value-ref="$PSMService.MarketCapacityUnitCode"/>
<tt:attribute name="SAPMaterialCode" value-ref="$PSMService.SAPMaterialCode"/>
<Transactions tt:extensible="deep-dynamic">
<tt:loop name="Transaction" ref=".TABLA_PSM_TRANSACTIONS">
<Transaction tt:extensible="deep-dynamic">
<tt:attribute name="ReceiptPointCode" value-ref="$Transaction.ReceiptPointCode"/>
<tt:attribute name="DeliveryPointCode" value-ref="$Transaction.DeliveryPointCode"/>
<tt:attribute name="ExitTramoCode" value-ref="$Transaction.ExitTramoCode"/>
<tt:attribute name="SectorCode" value-ref="$Transaction.SectorCode"/>
<tt:attribute name="MarketCode" value-ref="$Transaction.MarketCode"/>
<tt:attribute name="MarketCapacity" value-ref="$Transaction.MarketCapacity"/>
<tt:attribute name="Firm" value-ref="$Transaction.Firm"/>
<tt:attribute name="Overrun " value-ref="$Transaction.Overrun "/>
<tt:attribute name="UnitCode" value-ref="$Transaction.UnitCode"/>
<tt:attribute name="SAPMaterialCode" value-ref="$Transaction.SAPMaterialCode"/>
</Transaction>
</tt:loop>
</Transactions>
<DailyCharges tt:extensible="deep-dynamic">
<tt:loop name="DailyCharge" ref=".TABLA_PSM_DAILYCHARGES">
<DailyCharge tt:extensible="deep-dynamic">
<tt:attribute name="ChargeCode" value-ref="$DailyCharge.ChargeCode"/>
<tt:attribute name="Date" value-ref="$DailyCharge.Date"/>
<tt:attribute name="Quantity" value-ref="$DailyCharge.Quantity"/>
<tt:attribute name="QuantityUnit" value-ref="$DailyCharge.QuantityUnit"/>
</DailyCharge>
</tt:loop>
</DailyCharges>
<AggregateCharges tt:extensible="deep-dynamic">
<tt:loop name="AggregateCharge" ref=".TABLA_PSM_AGGREGATECHARGES">
<AggregateCharge tt:extensible="deep-dynamic">
<tt:attribute name="ChargeCode" value-ref="$AggregateCharge.ChargeCode"/>
<tt:attribute name="IsTiered" value-ref="$AggregateCharge.IsTiered"/>
<tt:attribute name="Quantity" value-ref="$AggregateCharge.Quantity"/>
<tt:attribute name="QuantityUnit" value-ref="$AggregateCharge.QuantityUnit"/>
<tt:attribute name="CurrencyCode" value-ref="$AggregateCharge.CurrencyCode"/>
<tt:attribute name="TariffRate" value-ref="$AggregateCharge.TariffRate"/>
<tt:attribute name="TariffRateUnit" value-ref="$AggregateCharge.TariffRateUnit"/>
</AggregateCharge>
</tt:loop>
</AggregateCharges>
</PSMService>
</tt:loop>
</PSMServices>
</Services>
Edited by: Thomas Zloch on May 10, 2011 12:47 PM - code tags added -
Simple Transformation - Conditions
Hello,
I'm stuck with my Simple Transformation and hope to find some help here. The following XML is a short example of my input.
<ONIXmessage>
<product>
<a001>A5769069</a001>
<a002>01</a002>
<productidentifier>
<b221>02</b221>
<b244>1934435112</b244>
</productidentifier>
<productidentifier>
<b221>03</b221>
<b244>9781934435113</b244>
</productidentifier>
</product>
<product>
<a001>A5769126</a001>
<a002>03</a002>
<productidentifier>
<b221>02</b221>
<b244>383101213X</b244>
</productidentifier>
<productidentifier>
<b221>03</b221>
<b244>9783831012138</b244>
</productidentifier>
<productidentifier>
<b221>01</b221>
<b233>LI</b233>
<b244>3429113</b244>
</productidentifier>
</product>
</ONIXmessage>
As you can see there are several <productidentifier> tags for each product. I need to store the value of the <b244> tag but only if the value of the <b221> tag is '03'.
I guess I need to work with the <tt:cond> statement but I don't manage to create the transformation.
Any suggestions?
Regards
StephanHI Anna,
In alphabetic sequence 210 falls in between 2000 ans 3000.
You can use a numeric field to get the required result.
<b>data: v_numc(4) type n.
v_numc = p0001-btrtl.</b>
IF p0001-btrtl = '1000' OR <b>v_numc</b> BETWEEN '2000' AND '2999'.
IF p0001-kostl in p_rccode.
MOVE p0001-kostl TO stab-kostl.
move: 1 to ok1.
ENDIF.
ELSEIF p0001-btrtl in p_btrtl.
move: 1 to ok1.
concatenate '0000000' p0001-btrtl into stab-kostl.
condense stab-kostl.
ENDIF.
Regards,
ravi
P.S: check this sample program to demonstrate the same
data: v_char(4) type n value '210'.
if v_char between '2000' and '3000'.
Write:/ 'Lies'.
else.
write:/ 'Doesnt fall'.
endif.
output: 'Doesnt fall' -
Simple Transformation Exception
Hello,
I am tying to map XML to ABAP(deserialize) but receive a CX_ST_MATCH_ELEMENT Exception.
Below is my Simple Transformation, the calling method, and the XML snippet I am tying to deserialize.
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<SndgInst>
<tt:value ref="ROOT"/>
</SndgInst>
</tt:template>
</tt:transform>
method PARSE_XML.
DATA:
sndginst(10) type c value ' ',
l_exception_error TYPE REF TO cx_st_error.
parse the xml content
TRY.
CLEAR: l_exception_error.
CALL TRANSFORMATION (i_st_name)
SOURCE XML i_xml_string
RESULT root = sndginst.
catch exception
CATCH: cx_st_error INTO l_exception_error.
ENDTRY.
endmethod.
<S2SCTScf:SndgInst ymlns:S2SCTScf="urn:S2SCTScf:xsd:$SCTScfBlkCredTrf">ZYDOFRP0</S2SCTScf:SndgInst>
I have tried adding a reference for the namespace 'S2SCTScf' but receive the same exception.
I think it must have something to do with the namespace prefix and I have tried several different versions of the Simple transformation, such as <S2SCTSCF:SndgInst> as my tag reference, to no avail.
The exception class does not provide a lot of useful information and since you cannot debug a Simple Transformation it is a guessing game.
Thanks in advance for your help.
Best Regards,
Mark Lengel
Edited by: Mark Lengel on Mar 31, 2009 11:32 AMI've exactly the same problem.
My XML Input Stream contains Namespaces in the root element for e.g.
<Measurement xmlns="es.xxx.com" xmlns:ns2="http://www.w3.org/1999/xlink" xmlns:ns3="http://www.w3.org/1998/Math/MathML">
The Simple Transformation always raise an CX_ST_MATCH_ELEMENT Exception.
If i delete the xmlns declarations, the Element will be found and everything is o.k.
I've also tried to avoid this by adding the tt:extensible="deep-dynamic" attribute but it doesn't matter.
<tt:template>
<Measurement tt:extensible="deep-dynamic">
I use WebAS 6.40, ERP 2004.
I hope the Community could help us. Maybe it's bug in the XML Libraries.. etc..
Kind Regards
Chris -
Simple transformation: dump ST_MATCH_FAIL
Hello,
I have written a simple transformation which works fine.
However, I get the dump ST_MATCH_FAIL whenever the tags in the XML are not in the order specified in the ST or if the XML contains tags other than the tags specified in the ST.
Is there a way to prevent this dump? The ST should just ignore order of fields and fields which are not stated in the ST.
This is the ST
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="DocRoot"/>
<tt:template>
<DocRoot>
<tt:loop name="wa_iram" ref=".DocRoot">
<entry>
<personnel_num>
<tt:value ref="$wa_iram.pernr"/>
</personnel_num>
<email>
<tt:value ref="$wa_iram.email"/>
</email>
<ldap_id>
<tt:value ref="$wa_iram.ldap_id"/>
</ldap_id>
</entry>
</tt:loop>
</DocRoot>
</tt:template>
</tt:transform>
Thanks
KoenThat particular example has no conditional operators specified in the template. You have to identify the conditional frequency of the elements in order to stop dumps like that...
-
Questions concerning ST Simple Transformations
I got some questions concerning Simple Transformations:
1.) When editing a simple transformation, how to insert comments? In pure ABAP, a comment line must have as asterisk in the first column...
2.) I use <tt:loop>...</tt:loop> and want to use the index of the currently processed entry, like SY-TABIX when implementing a "LOOP AT itab" in ABAP. Is there a way?
Thanks for your answer, points will be rewared...
-MIKEHi Jack, please find some sample coding below that will solve your issue:
<tt:cond check="not-initial(ref('E1EDL20.INCO1'))">
<INCO1 tt:value-ref="E1EDL20.INCO1"/>
</tt:cond>
With the simple transformation tt cond statment you can make an XML tag optional. In below example during deserialisation xml tag <INCO1> will be skipped when not availabke in the xml and SAP data E1EDL20.INCO1 will not be filled by the transformation.
Regards. Please give points when usefull ! -
Optional XML fields in Simple transformations (ST)
Hi, I am using Simple Transformation (ST) to convert an XML file into ABAP data. In my XML file some XML tags are optional: sometimes they are available in the file, sometimes they are not. I can not find out how to define a ST for this.
Either the XML fields are in the ST definition and then these field should also be in the XML file or
the XML fields are not in the ST definition and then these fields are not allowed in the XML.
Regards jackHi Jack, please find some sample coding below that will solve your issue:
<tt:cond check="not-initial(ref('E1EDL20.INCO1'))">
<INCO1 tt:value-ref="E1EDL20.INCO1"/>
</tt:cond>
With the simple transformation tt cond statment you can make an XML tag optional. In below example during deserialisation xml tag <INCO1> will be skipped when not availabke in the xml and SAP data E1EDL20.INCO1 will not be filled by the transformation.
Regards. Please give points when usefull !
Maybe you are looking for
-
Problem in gettig log text from SRM Items to PO Items
Hi all, We have a problem in SRM we have extended classic scenario at the time of PO creation in SRM the same is created in R3 also but our requirement is the Long text of Item form SRM PO should also copy to R/3 PO line item long text
-
I am using JTable. The problem I am facing is about the header. When you resize the column, you can continue dragging the column beyond the boundry of the table and remaining columns disappeared. The columns need to be resizable. Solution will be app
-
Show/Hide Content of Homescreen
Hello, to hide the content you can just slide for finger sideways on the screen which looks like a linux style cube but with only 2 desktops. Is this really the case? Can I have two homescreens and switch between them in the above fashion. If not wha
-
I have a strange Safari bug... After about a day of using Safari 2.0.4 (the latest stable version), the main Safari menu stops working. I can still pull it down, but selecting anything in it does nothing. For example, I can pull down the Safari menu
-
Block of text to fill screen... starts in middle not top
I am trying to create a text-generator clip that includes a lot of copyright/credits info, and I want to fill the screen with it, top to bottom, left to right. When I enter all the txt in a text generator (Controls), and then look at the Video displa