20170331 strans 实现XML解析
简单转换:zml_xml_trans03
<?sap.transform simple?> <tt:transform xmlns:tt="http://www.sap.com/transformation-templates"> <tt:root name="MLMatnrResource"/> <tt:template> <handleIMatnrResourceServiceResponse> <out> <tt:loop name="out" ref=".MLMatnrResource"> <MLMatnrResource> <backup1> <tt:value ref="$ref.backup1"/> </backup1> <backup2> <tt:value ref="$ref.backup2"/> </backup2> <backup3> <tt:value ref="$ref.backup3"/> </backup3> <backup4> <tt:value ref="$ref.backup4"/> </backup4> <backup5> <tt:value ref="$ref.backup5"/> </backup5> <ebeln> <tt:value ref="$ref.ebeln"/> </ebeln> <ebelp> <tt:value ref="$ref.ebelp"/> </ebelp> <lifnrAmount> <tt:value ref="$ref.lifnrAmount"/> </lifnrAmount> <maktx> <tt:value ref="$ref.maktx"/> </maktx> <matnr> <tt:value ref="$ref.matnr"/> </matnr> <proAmount> <tt:value ref="$ref.proAmount"/> </proAmount> <storeAmount> <tt:value ref="$ref.storeAmount"/> </storeAmount> </MLMatnrResource> </tt:loop> </out> </handleIMatnrResourceServiceResponse> </tt:template> </tt:transform>
ABAP参考:
* test strans 2 by wqb 20170331 TYPES:BEGIN OF ty_re, backup1 TYPE string,"备用字段1 backup2 TYPE string,"备用字段2 backup3 TYPE string,"备用字段3 backup4 TYPE string,"备用字段4 backup5 TYPE string,"备用字段5 ebeln TYPE string,"采购订单号 ebelp TYPE string,"采购订单行项目号 lifnramount TYPE string, "供应商库存数量 maktx TYPE string, "物料描述 matnr TYPE string, "物料代码 proamount TYPE string, "生产数量 storeamount TYPE string, "线边仓库存数量 "prodate TYPE datum, "生产日期 END OF ty_re. DATA:gt_re TYPE STANDARD TABLE OF ty_re, wa_re LIKE LINE OF gt_re. DATA: xml TYPE string. DATA: err TYPE string. DATA: o_error TYPE REF TO cx_st_error. CONCATENATE '<?xml version="1.0" encoding="UTF-8"?>' '<handleIMatnrResourceServiceResponse><out>' '<MLMatnrResource><backup1/><backup2/><backup3/><backup4/><backup5/><ebeln>4800064316</ebeln><ebelp>00010</ebelp><lifnrAmount/><maktx>A级冰箱型号标贴_C0414.6-1(A</maktx>' '<matnr>000000000800013563</matnr><proAmount/><storeAmount>12.0</storeAmount></MLMatnrResource>' '<MLMatnrResource><backup1/><backup2/><backup3/><backup4/><backup5/><ebeln>4800064316</ebeln><ebelp>00020</ebelp><lifnrAmount/><maktx>A级冰箱型号标贴_C0414.6-1(A</maktx>' '<matnr>000000000800013563</matnr><proAmount/><storeAmount>12.0</storeAmount></MLMatnrResource>' '<MLMatnrResource><backup1/><backup2/><backup3/><backup4/><backup5/><ebeln>4800064317</ebeln><ebelp>00010</ebelp><lifnrAmount/><maktx>A级冰箱型号标贴_C0414.6-1(A</maktx>' '<matnr>000000000800013563</matnr><proAmount/><storeAmount>12.0</storeAmount></MLMatnrResource>' '</out></handleIMatnrResourceServiceResponse>' INTO xml. WRITE: / xml. TRY. BREAK-POINT. CALL TRANSFORMATION zml_xml_trans03 SOURCE XML xml RESULT mlmatnrresource = gt_re[]. CATCH cx_st_error INTO o_error . err = o_error->get_text( ) . WRITE:/ err. ENDTRY. LOOP AT gt_re INTO wa_re. WRITE:/ wa_re-ebeln. CLEAR wa_re. ENDLOOP.
*&报错记录:------------------------------------------------------------------------------------------------------------------------------------------------------------
20170401:
1.调用cis webservice error
java返回错误:
Fault: java.lang.NullPointerExceptionInternal Server Error
2.解析代码错误导致拿不到源数据!
解析代码错误/ 源xml错误导致!
3.修改后再解析:
Code:
ZML_XML_RESOURCE 解析SRM可用资源清单 错误版本:
<!--
作者:CX
日期:2017-03-30
功能:get srm resource list
项目:合肥美菱SCP项目一期
-->
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="MLMatnrResource"/>
<tt:template>
<!--*&->new code on 20170330-->
<handleIMatnrResourceServiceResponse>
<out>
<!-- <tt:loop name="items" ref=".MLMatnrResource">-->
<tt:loop ref=".MLMatnrResource">
<MLMatnrResource>
<backup1>
<tt:value ref="$ref.backup1"/>
</backup1>
<backup2>
<tt:value ref="$ref.backup2"/>
</backup2>
<backup3>
<tt:value ref="$ref.backup3"/>
</backup3>
<backup4>
<tt:value ref="$ref.backup4"/>
</backup4>
<backup5>
<tt:value ref="$ref.backup5"/>
</backup5>
<ebeln>
<tt:value ref="$ref.ebeln"/>
</ebeln>
<ebelp>
<tt:value ref="$ref.ebelp"/>
</ebelp>
<lifnrAmount>
<tt:value ref="$ref.lifnrAmount"/>
</lifnrAmount>
<maktx>
<tt:value ref="$ref.maktx"/>
</maktx>
<matnr>
<tt:value ref="$ref.matnr"/>
</matnr>
<proAmount>
<tt:value ref="$ref.proAmount"/>
</proAmount>
<storeAmount>
<tt:value ref="$ref.storeAmount"/>
</storeAmount>
</MLMatnrResource>
</tt:loop>
</out>
</handleIMatnrResourceServiceResponse>
<!--*&->-->
</tt:template>
</tt:transform>
以图片形式编辑简单转换:
第二次,Code:
<!-- 作者:CX 日期:2017-03-30 功能:get srm resource list 项目:合肥美菱SCP项目一期 --> <?sap.transform simple?> <tt:transform xmlns:tt="http://www.sap.com/transformation-templates"> <tt:root name="MLMatnrResource"/> <tt:template> <!--*&->new code on 20170330--> <handleIMatnrResourceServiceResponse> <out> <!-- <MLMatnrResource>--> <!-- <tt:loop name="items" ref=".MLMatnrResource">--> <tt:loop neme="MLMatnrResource>" ref=".MLMatnrResource"> <MLMatnrResource> <backup1> <tt:value ref="$ref.backup1"/> </backup1> <backup2> <tt:value ref="$ref.backup2"/> </backup2> <backup3> <tt:value ref="$ref.backup3"/> </backup3> <backup4> <tt:value ref="$ref.backup4"/> </backup4> <backup5> <tt:value ref="$ref.backup5"/> </backup5> <ebeln> <tt:value ref="$ref.ebeln"/> </ebeln> <ebelp> <tt:value ref="$ref.ebelp"/> </ebelp> <lifnrAmount> <tt:value ref="$ref.lifnrAmount"/> </lifnrAmount> <maktx> <tt:value ref="$ref.maktx"/> </maktx> <matnr> <tt:value ref="$ref.matnr"/> </matnr> <proAmount> <tt:value ref="$ref.proAmount"/> </proAmount> <storeAmount> <tt:value ref="$ref.storeAmount"/> </storeAmount> </MLMatnrResource> </tt:loop> <!-- </MLMatnrResource>--> </out> </handleIMatnrResourceServiceResponse> <!--*&->--> </tt:template> </tt:transform>
字符串有值进入strans 进行解析:
本人常年接收SAP运维和远程项目,ECC,S/4HANA,CRM,WDA.
远程人天可谈,终身售后,有活请联系V信:18925782767(问问题免费,欢迎交流!)
!!请关注本人技术分享公众号:SAP翔子(可扫头像二维码)
每天分享新知识,博客文章也会陆续整理并迁移至公众号,与您一起共同学习