284.6. IDoc のメッセージ本文

IDoc メッセージタイプ

IDoc Camel SAP エンドポイントの 1 つを使用する場合、メッセージ本文のタイプは、使用している特定のエンドポイントによって異なります。

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 ドキュメントは、基礎となる SAP IDoc API のラッパー API を提供する Eclipse Modeling Framework (EMF) を使用してモデル化されます。このモデルで最も重要なタイプは次のとおりです。

org.fusesource.camel.component.sap.model.idoc.Document
org.fusesource.camel.component.sap.model.idoc.Segment

Document タイプは、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 制御レコードのフィールド値にアクセスまたは変更するためのものです。これらのメソッドは、AttributeNameAttributeName の形式です。ここで、AttributeName はフィールド値の名前です (を参照してください)。表284.2「IDoc ドキュメントの属性」)。
ドキュメントコンテンツへのアクセス方法

getRootSegment メソッドは、ドキュメントコンテンツ (IDoc データレコード) へのアクセスを提供し、コンテンツを Segment オブジェクトとして返します。各 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();

Document インスタンスの作成例

例えば、例284.1「Java での IDoc ドキュメントの作成」 Java で IDoc モデル API を使用して、IDoc タイプ FLCUSTOMER_CREATEFROMDATA01 で IDoc ドキュメントを作成する方法を示します。

例284.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");

ドキュメント属性

表284.2「IDoc ドキュメントの属性」 Document オブジェクトに設定できる制御レコード属性を示します。

表284.2 IDoc ドキュメントの属性

属性長さSAP フィールド説明

archiveKey

70

ARCKEY

EDI アーカイブキー

クライアント

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

DOCNUM

IDoc 番号

iDocSAPRelease

4

DOCREL

IDoc の SAP リリース

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: シリアル化フィールド

status

2

STATUS

IDoc のステータス

testFlag

1

テスト

テストフラグ

Java でドキュメント属性を設定する

Java で制御レコード属性を設定する場合 (から表284.2「IDoc ドキュメントの属性」)、Java Bean プロパティーの通常の規則に従います。つまり、属性値を取得および設定するために、getName および setName メソッドを介して name 属性にアクセスできます。たとえば、iDocTypeiDocTypeExtension、および messageType 属性は、Document オブジェクトで次のように設定できます。

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

XML でドキュメント属性を設定する

XML で制御レコード属性を設定する場合、idoc:Document 要素に属性を設定する必要があります。たとえば、iDocTypeiDocTypeExtension および messageType 属性は次のように設定できます。

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