基于PI的Webservice发布实例

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

基于PI的Webservice发布实例分类:ABAPPI2011-08-2121:221442人阅读评论(1)收藏举报最近的项目中,接口较多,而Webservice技术是主要实现方式之一。下面以项目中的一个具体实例来体验一下基于PI的Webservice发布。业务场景SAP系统实时接收一个外围接口系统(基于Web的电子商务平台)回传的数据。技术分析由于同步要求较高,数据量偏小,采用Webservice实现较为合理。实例演示创建好自建表,用于接收回传的数据:TC:SPROXY根据集成组在PI配置的服务名创建ServiceInterface在实现类中,根据传入的XML字符串,解析后更新到自建表:data:ls_field_datalikezmmjyh_cdif,lt_field_dataliketableofls_field_data,ls_zmmjyh_ht_0007likezmmjyh_ht_0007,lt_zmmjyh_ht_0007liketableofls_zmmjyh_ht_0007,l_retcodetypei,l_fieldnametypestring,l_floattypef.field-symbols:fs_fieldnametypeany,fs_fieldvaluetypeany.解析XML数据到通用内表type-pools:ixml.types:beginoft_xml_line,data(256)typex,endoft_xml_line.data:l_ixmltypereftoif_ixml,l_streamfactorytypereftoif_ixml_stream_factory,l_parsertypereftoif_ixml_parser,l_istreamtypereftoif_ixml_istream,l_documenttypereftoif_ixml_document,l_nodetypereftoif_ixml_node,l_xmldatatypestring.data:l_elemtypereftoif_ixml_element,l_root_nodetypereftoif_ixml_node,l_next_nodetypereftoif_ixml_node,l_nametypestring,l_iteratortypereftoif_ixml_node_iterator.data:l_xml_tabletypetableoft_xml_line,l_xml_linetypet_xml_line,l_xml_table_sizetypei.*CreatingthemainiXMLfactoryl_ixml=cl_ixml=create().*Creatingastreamfactoryal_streamfactory=l_ixml-create_stream_factory().l_istream=l_streamfactory-create_istream_string(string=input).*Creatingadocumentl_document=l_ixml-create_document().*CreateaParserl_parser=l_ixml-create_parser(stream_factory=l_streamfactoryistream=l_istreamdocument=l_document).*Parsethestreamifl_parser-parse()ne0.l_retcode=0.return.endif.*Processthedocumentifl_parser-is_dom_generating()eq'X'.performprocess_domtableslt_field_datausingl_document.endif.*&--------------------------------------------------------------------**&Formprocess_dom*&--------------------------------------------------------------------*formprocess_domtablesp_i_zxmlstructurezmmjyh_cdifusingdocumenttypereftoif_ixml_document.data:nodetypereftoif_ixml_node,iteratortypereftoif_ixml_node_iterator,nodemaptypereftoif_ixml_named_node_map,node_parenttypereftoif_ixml_node,attrtypereftoif_ixml_node,nametypestring,name1typestring,prefixtypestring,valuetypestring,indenttypei,counttypei,indextypei.node?=document.checknotnodeisinitial.ifnodeisinitial.exit.endif.*createanodeiteratoriterator=node-create_iterator().*getcurrentnodenode=iterator-get_next().*loopoverallnodeswhilenotnodeisinitial.indent=node-get_height()*2.indent=indent+20.casenode-get_type().whenif_ixml_node=co_node_element.*elementnodename=node-get_name().nodemap=node-get_attributes().ifnotnodemapisinitial.*attributescount=nodemap-get_length().docounttimes.index=sy-index-1.attr=nodemap-get_item(index).name=attr-get_name().prefix=attr-get_namespace_prefix().value=attr-get_value().记录字段名、字段值p_i_zxml-fieldname=name.p_i_zxml-fieldvalue=value.appendp_i_zxml.enddo.endif.whenif_ixml_node=co_node_textorif_ixml_node=co_node_cdata_section.*textnodevalue=node-get_value().node_parent=node-get_parent().name1=node_parent-get_name().记录字段名、字段值p_i_zxml-fieldname=name1.p_i_zxml-fieldvalue=value.appendp_i_zxml.endcase.node=iterator-get_next().endwhile.endform.process_dom准备数据到数据库更新内表loopatlt_field_dataintols_field_data.clearl_fieldname.assignls_field_data-fieldvaluetofs_fieldvalue.concatenate'LS_ZMMJYH_HT_0007-'ls_field_data-fieldnameintol_fieldname.assign(l_fieldname)tofs_fieldname.iffs_fieldnameisassigned.ifls_field_data-fieldname='CONTRAMOUNTNUM'orls_field_data-fieldname='APPLYAMOUNT'.金额字段中科学计数法的处理clearl_float.l_float=fs_fieldvalue.fs_fieldname=l_float.else.fs_fieldname=fs_fieldvalue.endif.else.it_return-zresult='0'.it_return-description='程序异常,字段名不匹配!'.appendit_return.return.endif.到达一条数据末尾ifls_field_data-fieldname='PREPAYID'.appendls_zmmjyh_ht_0007tolt_zmmjyh_ht_0007.clearls_zmmjyh_ht_0007.endif.endloop.更新到自建表iflines(lt_zmmjyh_ht_0007)0.modifyzmmjyh_ht_0007fromtablelt_zmmjyh_ht_0007.ifsy-subrc=0.commitworkandwait.it_return-zresult='1'.it_return-description='回传成功!'.appendit_return.else.rollbackwork.it_return-zresult='0'.it_return-description='回传失败,数据库更新异常!'.appendit_return.endif.else.it_return-zresult='0'.it_return-description='无数据可传输!'.appendit_return.endif.把结果回传给外围系统,先创建好Transformation然后把返回值封装成XML串:data:l_xstrtypexstring.calltransformationzmmjyhmesgjdzswsourceroot=it_return[]*RESULTXMLoutputresultxmll_xstroptionsxml_header='no'.types:beginofty_bin,bin_data(1024)typex,endofty_bin.data:lt_bintypetableofty_bin.文件二进制内表data:l_lentypei.checkinputisnotinitial.callfunction'SCMS_XSTRING_TO_BINARY'exportingbuffer=l_xstr*APPEND_TO_TABLE=''importingoutput_length=l_lentablesbinary_tab=lt_bin.callfunction'SCMS_BINARY_TO_STRING'exportinginput_length=l_len*FIRST_LINE=0*LAST_LINE=0*MIMETYPE=''*ENCODING=importingtext_buffer=output-zmmjyht010response-output*OUTPUT_LENGTH=tablesbinary_tab=lt_bin*EXCEPTIONS*FAILED=1*OTHERS=2.ifsy-subrc0.*MESSAGEIDSY-MSGIDTYPESY-MSGTYNUMBERSY-MSGNO*WITHSY-MSGV1SY-MSGV2SY-MSGV3SY-MSGV4.endif.由于是基于PI创建的,此时的Webservice还没有注册,TC:SOAMANAGER进入singleserviceadministration,搜索刚才创建的webservice:Zmmjyht010,

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功