简体   繁体   English

SAP R / 3从IDoc XML文件中删除尾随空格

[英]SAP R/3 removes trailing spaces from IDoc XML files

I have a Java application that uses SAP JCo 3 libraries. 我有一个使用SAP JCo 3库的Java应用程序。 One of the use cases consists of receiving a IDoc file from the SAP instance (R/3, ERP 6.0 EhP 7) and convert it to XML. 其中一个用例包括从SAP实例(R / 3,ERP 6.0 EhP 7)接收IDoc文件并将其转换为XML。 The problem is that, during the conversion (executed by the IDoc library), the right spaces at the end of the fields get trimmed. 问题是,在转换过程中(由IDoc库执行),字段末尾的右侧空格会被修剪。 Apparently, to reduce the message size. 显然,减少邮件大小。 So far, I haven't found any configuration that can be done from the Java side. 到目前为止,我还没有找到任何可以从Java端完成的配置。

Searching the net, I found the following suggestions from the SAP side: 在网上搜索,我从SAP方面找到了以下建议:

  • setting whiteSpace=preserve from the XSD Editor 从XSD编辑器设置whiteSpace=preserve
  • setting xml.fieldContentFormatting=nothing in the Sender File/FTP Adapter 在发件人文件/ FTP适配器中设置xml.fieldContentFormatting=nothing

However, I haven't been able to find those tools nor configure them accordingly. 但是,我无法找到这些工具,也没有相应地配置它们。

I would appreciate any insights on these two approaches or any other solution. 我将非常感谢对这两种方法或任何其他解决方案的任何见解。

The SAP Java IDoc Class Library does not offer an option to preserve trailing SPACES in the IDoc fields. SAP Java IDoc类库不提供在IDoc字段中保留尾随SPACES的选项。

Trailing SPACE characters in IDoc fields do not serve any purpose as long as the IDoc will be sent to another SAP system in the end again. 只要IDoc最终再次发送到另一个SAP系统,IDoc字段中的尾随SPACE字符就不起任何作用。 In this case they really would only enlarge the XML message size without adding any value. 在这种情况下,他们实际上只会扩大XML消息大小而不添加任何值。

I currently cannot imagine for what reason you would like to keep those trailing SPACES? 我目前无法想象你想保留那些尾随空间的原因是什么? SPACE characters are the default initial value for ABAP CHAR type fields, so you also cannot know if some of these characters would have been set by intention or not. SPACE字符是ABAP CHAR类型字段的默认初始值,因此您也无法知道是否已根据意图设置了其中某些字符。

You can have a check where the total length of the field will be equal to that particular segment length. 您可以检查字段的总长度是否等于特定的段长度。 You can use RFC IDOCTYPE_READ_COMPLETE. 您可以使用RFC IDOCTYPE_READ_COMPLETE。 In this pass IDOC type ,say MATMAs01. 在这个传递IDOC类型中,比如说MATMAs01。 In table PT_SEGMENTS you can get the segment length. 在表PT_SEGMENTS中,您可以获得段长度。

You can pass this segment length to get the complete field length. 您可以传递此段长度以获得完整的字段长度。

When working with the XML in ABAP, what you need to look at is the if_ixml_renderer (or if_ixml_parser ) call set_normalizing . 在ABAP中使用XML时,需要注意的是if_ixml_renderer (或if_ixml_parser )调用set_normalizing This is on by default, and you need to disable this. 默认情况下处于启用状态,您需要禁用此功能。

"Convert XML to string: l_string
lif_ostream = sif_streamfactory->create_ostream_cstring( l_string ).
lif_renderer = sif_xml->create_renderer( ostream  = lif_ostream
                                         document = mif_xml_document ).
" this stops SAP from removing whitespace and doing spurious edits:
lif_renderer->set_normalizing( false ).

lif_renderer->render( ).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM