搜索

290.10. IDoc 的消息正文

download PDF

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 对象上设置的控制记录属性。

表 290.2. idoc 文档属性
属性lengthSAP Field描述

archiveKey

70

ARCKEY

EDI 归档密钥

client

3

MANDT

客户端

creationDate

8

CREDAT

创建日期 IDoc

creationTime

6

CRETIM

创建时间 IDoc

direction

1

DIRECT

方向

eDIMessage

14

REFMES

对消息的引用

eDIMessageGroup

14

REFGRP

对消息组的引用

eDIMessageType

6

STDMES

EDI 消息类型

eDIStandardFlag

1

STD

EDI 标准

eDIStandardVersion

6

STDVRS

EDI 标准版本

eDITransmissionFile

14

REFINT

对交换文件的引用

iDocCompoundType

8

DOCTYP

idoc 类型

iDocNumber

16

文档NUM

idoc 号

iDocSAPRelease

4

DOCREL

SAP IDoc 版本

iDocType

30

IDOCTP

基本 IDoc 类型的名称

iDocTypeExtension

30

CIMTYP

扩展类型的名称

messageCode

3

MESCOD

逻辑消息代码

messageFunction

3

MESFCT

逻辑消息功能

messageType

30

MESTYP

逻辑消息类型

outputMode

1

OUTMOD

输出模式

recipientAddress

10

RCVSAD

接收器地址(SADR)

recipientLogicalAddress

70

RCVLAD

接收器的逻辑地址

recipientPartnerFunction

2

RCVPFC

接收器合作伙伴功能

recipientPartnerNumber

10

RCVPRN

合作伙伴接收器数

recipientPartnerType

2

RCVPRT

合作伙伴接收器类型

recipientPort

10

RCVPOR

接收器端口(SAP 系统、EDI 子系统)

senderAddress

 

SNDSAD

发送者地址(SADR)

senderLogicalAddress

70

SNDLAD

发送者的逻辑地址

senderPartnerFunction

2

SNDPFC

发送者的合作伙伴功能

senderPartnerNumber

10

SNDPRN

合作伙伴发送者数

senderPartnerType

2

SNDPRT

合作伙伴发送者类型

senderPort

10

SNDPOR

发送者端口(SAP 系统、EDI 子系统)

serialization

20

SERIAL

EDI/ALE: Serialization 字段

status

2

状态

IDoc 的状态

testFlag

1

测试

test 标记

在 Java 中设置文档属性

在 Java 中设置控制记录属性时(来自 表 290.2 “idoc 文档属性”),则遵循 Java bean 属性的常规约定。也就是说,可以通过 getNamesetName 方法访问 name 属性,用于获取和设置属性值。例如,i Doc Type、iDocTypeExtensionmessageType 属性可以设置为在 Document 对象中如下所示:

// Java
document.setIDocType("FLCUSTOMER_CREATEFROMDATA01");
document.setIDocTypeExtension("");
document.setMessageType("FLCUSTOMER_CREATEFROMDATA");

在 XML 中设置文档属性

在 XML 中设置控制记录属性时,必须在 idoc:Document 元素上设置属性。例如,i Doc Type、iDocTypeExtensionmessageType 属性可以设置如下:

<?xml version="1.0" encoding="ASCII"?>
<idoc:Document ...
               iDocType="FLCUSTOMER_CREATEFROMDATA01"
               iDocTypeExtension=""
               messageType="FLCUSTOMER_CREATEFROMDATA" ... >
    ...
</idoc:Document>
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.