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 组件,使用 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 类型定义的确切结构。
Segment 类型用于访问 IDoc 文档的数据记录,其中片段会根据文档的 IDoc 类型所定义的结构进行布局。在概述中,Segment 接口会公开以下方法:
// 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();
创建文档实例示例 复制链接链接已复制到粘贴板!
例如,例 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 对象上设置的控制记录属性。
| 属性 | length | SAP Field | 描述 |
|---|---|---|---|
|
| 70 |
| EDI 归档密钥 |
|
| 3 |
| 客户端 |
|
| 8 |
| 创建日期 IDoc |
|
| 6 |
| 创建时间 IDoc |
|
| 1 |
| 方向 |
|
| 14 |
| 对消息的引用 |
|
| 14 |
| 对消息组的引用 |
|
| 6 |
| EDI 消息类型 |
|
| 1 |
| EDI 标准 |
|
| 6 |
| EDI 标准版本 |
|
| 14 |
| 对交换文件的引用 |
|
| 8 |
| idoc 类型 |
|
| 16 |
| idoc 号 |
|
| 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 属性,用于获取和设置属性值。例如,i Doc Type、iDocTypeExtension 和 messageType 属性可以设置为在 Document 对象中如下所示:
// Java
document.setIDocType("FLCUSTOMER_CREATEFROMDATA01");
document.setIDocTypeExtension("");
document.setMessageType("FLCUSTOMER_CREATEFROMDATA");
在 XML 中设置文档属性 复制链接链接已复制到粘贴板!
在 XML 中设置控制记录属性时,必须在 idoc:Document 元素上设置属性。例如,i Doc Type、iDocTypeExtension 和 messageType 属性可以设置如下:
<?xml version="1.0" encoding="ASCII"?>
<idoc:Document ...
iDocType="FLCUSTOMER_CREATEFROMDATA01"
iDocTypeExtension=""
messageType="FLCUSTOMER_CREATEFROMDATA" ... >
...
</idoc:Document>