Transformation XML Conversion

Source: Internet
Author: User
Tags xml attribute xslt
[XML] about XML (part 3)

In the first two articles ([XML] about XML (Part 1), [XML] about XML
(Part 2). We use the XML proxy class to read and write XML. SAP provides the call transformation <ID> method, which is the most commonly used method in our daily work.

After call transformation is used, our ABAPProgramIt is no longer as simple and convenient to process XML nodes as previously. But at the same time, we need to develop transformation in advance.

The call transformation method is complex and contains many non-ABAP contents. Here, we only record the content used in our work to prevent forgetting.

Use call transformation to operate XML

Tcode:Strans

There are two types of Transformation: simple transformation and XSLT.

Simple transformation.

Program:

Report ztest_transofrmation_1.

Data:
Ls_lfa1 type lfa1,
Lt_lfa1 type table of lfa1,
Lv_xml type string,
Lv_string type string,
W_len type I,
It_xml type table of string.

Start-of-selection.

Select * From lfa1 into Table lt_lfa1
Up to 20 rows.

* Call XML
Call transformation ztest_01
Source vendor = lt_lfa1
Result XML lv_xml.
Write: lv_xml.

TransformationZtest_01Is:

Result:

The XML file is generated correctly.

In addition, transformation can be used in two directions, namely, deserialization (parsing XML) and serialization (generating XML ). Test as follows:

*&-----------------------*
* & Report ztest_xml_attribute
*&
*&-----------------------*
* & Parse XML Attribute
*&
*&-----------------------*

Report ztest_xml_attribute.

Data:
W_attr1 type string,
W_attr2 type string.

Data:
W_xml type string.

* ------ Deserialization -------
* From XML
W_xml = '<X attr1 = "text1" attr2 = "text2"/> '.

* Deserialization of XML
Call transformation ztest_02
Source XML w_xml
Result root1 = w_attr1
Root2 = w_attr2.

Write:/'attribute 1: ', 20 w_attr1,
/'Attribute 2: ', 20 w_attr2.

* ------ Serialization -------
Skip 2.
Clear: w_xml, w_attr1, w_attr2.
"Form data
W_attr1 = '[2nd] text1 ′.
W_attr2 = '[2nd] text2 ′.
"Serialization
Call transformation ztest_02
Source root1 = w_attr1
Root2 = w_attr2
Result XML w_xml.
Write: w_xml.

Here, Transformation:

Result:

UsageXSLTType, here is a simple example, which is also applied in our actual work:

Write XML:

Call transformation ID
Source XML iv_xml_stream
Result sap_business_all_epa_proc = lt_proc_state_epa.

Read XML:

Call transformation ID
Source sap_business_all_epa_proc = lt_proc_state_epa
Result XML ev_xml_stream.

XML format:

Note: For transformation, only a few simple cases used in your work are recorded here. Transformation is a complex and rich point, which requires more in-depth study. Link:

SAP help: http://help.sap.com/abapdocu_70/en/ABAPCALL_TRANSFORMATION.htm

A foreigner's Blog contains equivalent XML content: http://www.sdn.sap.com/irj/scn/weblogs? Blog =/pub/u/35460

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.