290.10. IDoc 的消息正文
idoc 消息类型
当使用其中一个 IDoc Camel SAP 端点时,消息正文的类型取决于您使用的特定端点。
对于 sap-idoc-destination 端点或 sap-qidoc-destination 端点,消息正文是 Document 类型:
org.fusesource.camel.component.sap.model.idoc.Document
对于 sap-idoclist-destination 端点、sap-qidoclist-destination 端点或 sap-idoclist-server 端点,消息正文是 DocumentList 类型:
org.fusesource.camel.component.sap.model.idoc.DocumentList
IDoc 文档模型
对于 Camel SAP 组件,IDoc 文档使用 Eclipse Modelling Framework (EMF)建模,它围绕底层 SAP IDoc API 提供打包程序 API。这个模型中最重要的类型是:
org.fusesource.camel.component.sap.model.idoc.Document org.fusesource.camel.component.sap.model.idoc.Segment
文档 类型代表 IDoc 文档实例。简而言之,Document 接口会公开以下方法:
// Java
package org.fusesource.camel.component.sap.model.idoc;
...
public interface Document extends EObject {
// Access the field values from the IDoc control record
String getArchiveKey();
void setArchiveKey(String value);
String getClient();
void setClient(String value);
...
// Access the IDoc document contents
Segment getRootSegment();
}
以下方法由 Document 接口公开:
- 访问控制记录的方法
- 大多数方法都用于访问或修改 IDoc 控制记录的字段值。这些方法是 AttributeName,AttributeName,其中 AttributeName 是字段值的名称(请参阅 表 290.2 “idoc 文档属性”)。
- 访问文档内容的方法
getRootSegment方法提供对文档内容(IDoc 数据记录)的访问,将内容返回为Segment对象。每个分段对象可以包含任意数量的子片段,片段可以嵌套到任意程度。注意片段层次结构的精确布局由文档的特定 IDoc 类型定义。在创建(或读取)片段层次结构时,您必须确保遵循 IDoc 类型定义的确切结构。
分段类型用于访问 IDoc 文档的数据记录,其中片段根据文档的 IDoc 类型定义的结构而定。简而言之,分段 接口会公开以下方法:
// Java
package org.fusesource.camel.component.sap.model.idoc;
...
public interface Segment extends EObject, java.util.Map<String, Object> {
// Returns the value of the '<em><b>Parent</b></em>' reference.
Segment getParent();
// Return a immutable list of all child segments
<S extends Segment> EList<S> getChildren();
// Returns a list of child segments of the specified segment type.
<S extends Segment> SegmentList<S> getChildren(String segmentType);
EList<String> getTypes();
Document getDocument();
String getDescription();
String getType();
String getDefinition();
int getHierarchyLevel();
String getIdocType();
String getIdocTypeExtension();
String getSystemRelease();
String getApplicationRelease();
int getNumFields();
long getMaxOccurrence();
long getMinOccurrence();
boolean isMandatory();
boolean isQualified();
int getRecordLength();
<T> T get(Object key, Class<T> type);
}
getChildren (String segmentType) 方法对于向段添加新(嵌套)子级特别有用。它返回一个类型为( SegmentList )的对象,它定义如下:
// Java
package org.fusesource.camel.component.sap.model.idoc;
...
public interface SegmentList<S extends Segment> extends EObject, EList<S> {
S add();
S add(int index);
}
因此,要创建 E1SCU_CRE 类型的数据记录,您可以使用 Java 代码,如下所示:
Segment rootSegment = document.getRootSegment();
Segment E1SCU_CRE_Segment = rootSegment.getChildren("E1SCU_CRE").add();IDoc 如何与 Document 对象相关
根据 SAP 文档,IDoc 文档由以下主要部分组成:
- 控制记录
-
控制记录(包含 IDoc 文档的元数据)由
Document对象 iwl-PROFILE-DESTINATION 中的属性表示。表 290.2 “idoc 文档属性” - 数据记录
-
数据记录由
Segment对象表示,后者作为片段的嵌套层次结构构建。您可以通过Document.getRootSegment方法访问根段。 - 状态记录
-
在 Camel SAP 组件中,状态记录 不由 文档模型表示。但是,您可以通过控制记录上的
status属性访问最新的 status 值。
创建文档实例示例
例如,例 290.1 “在 Java 中创建 IDoc 文档” 演示了如何使用 Java 中的 IDoc 模型 API 创建 IDoc 类型 FLCUSTOMER_CREATEFROMDATA01 的 IDoc 文档。
例 290.1. 在 Java 中创建 IDoc 文档
// Java
import org.fusesource.camel.component.sap.model.idoc.Document;
import org.fusesource.camel.component.sap.model.idoc.Segment;
import org.fusesource.camel.component.sap.util.IDocUtil;
import org.fusesource.camel.component.sap.model.idoc.Document;
import org.fusesource.camel.component.sap.model.idoc.DocumentList;
import org.fusesource.camel.component.sap.model.idoc.IdocFactory;
import org.fusesource.camel.component.sap.model.idoc.IdocPackage;
import org.fusesource.camel.component.sap.model.idoc.Segment;
import org.fusesource.camel.component.sap.model.idoc.SegmentChildren;
...
//
// Create a new IDoc instance using the modelling classes
//
// Get the SAP Endpoint bean from the Camel context.
// In this example, it's a 'sap-idoc-destination' endpoint.
SapTransactionalIDocDestinationEndpoint endpoint =
exchange.getContext().getEndpoint(
"bean:SapEndpointBeanID",
SapTransactionalIDocDestinationEndpoint.class
);
// The endpoint automatically populates some required control record attributes
Document document = endpoint.createDocument()
// Initialize additional control record attributes
document.setMessageType("FLCUSTOMER_CREATEFROMDATA");
document.setRecipientPartnerNumber("QUICKCLNT");
document.setRecipientPartnerType("LS");
document.setSenderPartnerNumber("QUICKSTART");
document.setSenderPartnerType("LS");
Segment rootSegment = document.getRootSegment();
Segment E1SCU_CRE_Segment = rootSegment.getChildren("E1SCU_CRE").add();
Segment E1BPSCUNEW_Segment = E1SCU_CRE_Segment.getChildren("E1BPSCUNEW").add();
E1BPSCUNEW_Segment.put("CUSTNAME", "Fred Flintstone");
E1BPSCUNEW_Segment.put("FORM", "Mr.");
E1BPSCUNEW_Segment.put("STREET", "123 Rubble Lane");
E1BPSCUNEW_Segment.put("POSTCODE", "01234");
E1BPSCUNEW_Segment.put("CITY", "Bedrock");
E1BPSCUNEW_Segment.put("COUNTR", "US");
E1BPSCUNEW_Segment.put("PHONE", "800-555-1212");
E1BPSCUNEW_Segment.put("EMAIL", "fred@bedrock.com");
E1BPSCUNEW_Segment.put("CUSTTYPE", "P");
E1BPSCUNEW_Segment.put("DISCOUNT", "005");
E1BPSCUNEW_Segment.put("LANGU", "E");文档属性
表 290.2 “idoc 文档属性” 显示您可以在 Document 对象上设置的控制记录属性。
表 290.2. idoc 文档属性
| 属性 | length | SAP 字段 | 描述 |
|---|---|---|---|
|
| 70 |
| EDI 归档密钥 |
|
| 3 |
| 客户端 |
|
| 8 |
| 日期 IDoc 被创建 |
|
| 6 |
| 创建时间 IDoc |
|
| 1 |
| 方向 |
|
| 14 |
| 引用消息 |
|
| 14 |
| 引用消息组 |
|
| 6 |
| EDI 消息类型 |
|
| 1 |
| EDI 标准 |
|
| 6 |
| EDI 标准版本 |
|
| 14 |
| 对交换文件的引用 |
|
| 8 |
| idoc 类型 |
|
| 16 |
| idoc number |
|
| 4 |
| SAP 版本的 IDoc |
|
| 30 |
| 基本 IDoc 类型的名称 |
|
| 30 |
| 扩展类型的名称 |
|
| 3 |
| 逻辑消息代码 |
|
| 3 |
| 逻辑消息功能 |
|
| 30 |
| 逻辑消息类型 |
|
| 1 |
| 输出模式 |
|
| 10 |
| 接收器地址(SADR) |
|
| 70 |
| 接收器的逻辑地址 |
|
| 2 |
| 接收器合作伙伴功能 |
|
| 10 |
| 接收器合作伙伴数量 |
|
| 2 |
| 接收器合作伙伴类型 |
|
| 10 |
| 接收器端口(SAP 系统、EDI 子系统) |
|
|
| 发件人地址(SADR) | |
|
| 70 |
| 发件人的逻辑地址 |
|
| 2 |
| 发件人合作伙伴功能 |
|
| 10 |
| 发件人合作伙伴数量 |
|
| 2 |
| 发件人合作伙伴类型 |
|
| 10 |
| 发件人端口(SAP 系统、EDI 子系统) |
|
| 20 |
| EDI/ALE: Serialization 字段 |
|
| 2 |
| IDoc 的状态 |
|
| 1 |
| test 标记 |
在 Java 中设置文档属性
当在 Java 中设置控制记录属性时(来自 表 290.2 “idoc 文档属性”),Java bean 属性的常见约定遵循。也就是说,可以通过 getName 和 setName 方法访问 name 属性,用于获取和设置属性值。例如,iDocType,iDocTypeExtension, 和 messageType 属性可以在 Document 对象中设置,如下所示:
// Java
document.setIDocType("FLCUSTOMER_CREATEFROMDATA01");
document.setIDocTypeExtension("");
document.setMessageType("FLCUSTOMER_CREATEFROMDATA");在 XML 中设置文档属性
在 XML 中设置控制记录属性时,必须在 idoc:Document 元素上设置属性。例如,iDocType,iDocTypeExtension, 和 messageType 属性可以设置如下:
<?xml version="1.0" encoding="ASCII"?>
<idoc:Document ...
iDocType="FLCUSTOMER_CREATEFROMDATA01"
iDocTypeExtension=""
messageType="FLCUSTOMER_CREATEFROMDATA" ... >
...
</idoc:Document>