Use of transaction code Strans (XML and ABAP internal tables convert to each other)

Source: Internet
Author: User

ABAP---> XML and XML--->ABAP

The required XML format is as follows:

<out>
<baseReturnHeader>
<returnMsg> order header Data Update success Oh! </returnMsg>
<status>S</status>
<uuid/>
</baseReturnHeader>
<baseReturnHeader>
<returnMsg> order header Data Update success Oh! </returnMsg>
<status>S</status>
<uuid/>
</baseReturnHeader>
<items>
<BaseReturnItem>
<returnMsg> Line Project New success Yo!</returnmsg>
<status>S</status>
<uuid/>
</BaseReturnItem>
<BaseReturnItem>
<returnMsg> Project updated successfully yo!</returnmsg>
<status>S</status>
<uuid/>
</BaseReturnItem>
<BaseReturnItem>
<returnMsg> Project updated successfully yo!</returnmsg>
<status>S</status>
<uuid/>
</BaseReturnItem>
</items>
</out>

Transaction code strans Create transformation Zqbtest_sample3

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

<tt:root name="Basereturnheader"/>
<tt:root name="Basereturnitem"/>

<tt:template>
<out>
<tt:loop name="Headers" ref=". Basereturnheader" >
<baseReturnHeader>
<tt:value ref="$ref. Hresv1"/>
<tt:value ref="$ref. Hresv2"/>
<tt:value ref="$ref. Hresv3"/>
<tt:value ref="$ref. Hresv4"/>
<tt:value ref="$ref. Hresv5"/>
<returnMsg>
<tt:value ref="$ref. Returnmsg"/>
</returnMsg>
<status>
<tt:value ref="$ref. Status"/>
</status>
<uuid>
<tt:value ref="$ref. Uuid"/>
</uuid>
</baseReturnHeader>
</tt:loop>
<items>
<BaseReturnItem>
<tt:loop name="Items" ref=". Basereturnitem ">
<tt:value ref="$ref. Hresv1"/>
<tt:value ref="$ref. Hresv2"/>
<tt:value ref="$ref. Hresv3"/>
<tt:value ref="$ref. Hresv4"/>
<tt:value ref="$ref. Hresv5"/>
<returnMsg>
<tt:value ref="$ref. Returnmsg"/>
</returnMsg>
<status>
                <tt:value  ref="$ref. Status"/>
</status>
<uuid>
<tt:value ref="$ref. Uuid"/>
</uuid>
</tt:loop>
</BaseReturnItem>
</items>
</out>
</tt:template>

</tt:transform>

SE38 Creating a test report program ZQBTEST57

*&---------------------------------------------------------------------*
*& Report ZQBTEST57
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

Report Zqbtest57.

DATA:BEGINof BasereturnheaderOccurs 0,
Hresv1TYPEC LENGTH 20,
Hresv2TYPEC LENGTH 20,
Hresv3TYPEC LENGTH 20,
Hresv4TYPEC LENGTH 20,
Hresv5TYPEC LENGTH 20,
ReturnmsgTYPEC LENGTH 20,
StatusTYPEC LENGTH 20,
UuidTYPEC LENGTH 20,
ENDof Basereturnheader.
Data:basereturnitemLike BasereturnheaderOccurs0WithHEADER line.

Data:xml_stringTYPE string.
Data:lo_orefTYPEREFTo Cx_st_error.
Data:lv_msgTYPE string.


CLEAR Basereturnheader.
BASERETURNHEADER-HRESV1 =' 4500524641 '.
Basereturnheader-returnmsg =' rise to success '.
Basereturnheader-status =' S '.
APPEND Basereturnheader.

CLEAR Basereturnheader.
BASERETURNHEADER-HRESV1 =' 4500524642 '.
Basereturnheader-returnmsg =' rise to success '.
Basereturnheader-status =' S '.
APPEND Basereturnheader.

CLEAR Basereturnitem.
BASERETURNITEM-HRESV1 =' 4500524641 '.
Basereturnitem-hresv2 =' 00010 '.
Basereturnitem-returnmsg =' Line item succeeded '.
Basereturnitem-status =' S '.
APPEND Basereturnitem.

CLEAR Basereturnitem.
BASERETURNITEM-HRESV1 =' 4500524641 '.
Basereturnitem-hresv2 =' 00020 '.
Basereturnitem-returnmsg =' Line item succeeded '.
Basereturnitem-status =' S '.
APPEND Basereturnitem.

CLEAR Basereturnitem.
BASERETURNITEM-HRESV1 =' 4500524642 '.
Basereturnitem-hresv2 =' 00010 '.
Basereturnitem-returnmsg =' Line item failed '.
Basereturnitem-status =' E '.
APPEND Basereturnitem.

TRY.
Break-point.
Call Transformation Zqbtest_sample3
*options xml_header = ' no '
SOURCE Basereturnheader = basereturnheader[]
Basereturnitem = basereturnitem[]
RESULT XML xml_string.

CATCH Cx_st_errorInto Lo_oref.
Lv_msg = Lo_oref->get_text ().
WRITE:/' Error message: ', lv_msg.
Endtry.

WRITE:AT/1 xml_string.

CLEAR basereturnheader[].
CLEAR basereturnitem[].

TRY.
Break-point.
Call Transformation Zqbtest_sample3
SOURCE XML xml_string
RESULT Basereturnheader = basereturnheader[]
Basereturnitem = basereturnitem[].
CATCH Cx_st_errorInto Lo_oref.
Clear:lv_msg.
Lv_msg = Lo_oref->get_text ().
WRITE:/' Error message: ', lv_msg.
Endtry.

write:/ ' * * * Here's header '.
LOOP at Basereturnheader.
write:/basereturnheader-hresv1,basereturnheader-hresv2,basereturnheader-returnmsg.
CLEAR Basereturnheader.
Endloop.
write:/ ' * * * here's items '.
LOOP at Basereturnitem.
write:/basereturnitem-hresv1,basereturnitem-hresv2,basereturnitem-returnmsg.
CLEAR Basereturnitem.
Endloop.

Operation Result:

Use of transaction code Strans (XML and ABAP internal tables convert to each other)

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.