290.10. 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 制御レコードのフィールド値にアクセスまたは変更するためのものです。これらのメソッドは、AttributeName、AttributeName の形式です。ここで、AttributeName はフィールド値の名前です (を参照してください)。表290.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();IDoc と Document オブジェクトの関係
SAP ドキュメントによると、IDoc ドキュメントは次の主要部分で設定されています。
- 制御記録
-
コントロールレコード (IDoc ドキュメントのメタデータを含む) は、
Documentオブジェクトの属性によって表されます。詳細は、表290.2「IDoc ドキュメントの属性」 を参照してください。 - データ記録
-
データレコードは、セグメントのネストされた階層として構築される
Segmentオブジェクトによって表されます。Document.getRootSegmentメソッドを介してルートセグメントにアクセスできます。 - 状況記録
-
Camel SAP コンポーネントでは、ステータスレコードはドキュメントモデルによって表され ません。ただし、制御レコードの
status属性を介して最新のステータス値にアクセスできます。
Document インスタンスの作成例
例えば、例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 ドキュメントの属性
| 属性 | 長さ | SAP フィールド | 説明 |
|---|---|---|---|
|
| 70 |
| EDI アーカイブキー |
|
| 3 |
| クライアント |
|
| 8 |
| IDoc が作成された日付 |
|
| 6 |
| IDoc が作成された時間 |
|
| 1 |
| 方向 |
|
| 14 |
| メッセージ参照 |
|
| 14 |
| メッセージグループへの参照 |
|
| 6 |
| EDI メッセージタイプ |
|
| 1 |
| EDI 規格 |
|
| 6 |
| EDI 規格のバージョン |
|
| 14 |
| エクスチェンジファイルへの参照 |
|
| 8 |
| IDoc タイプ |
|
| 16 |
| IDoc 番号 |
|
| 4 |
| IDoc の SAP リリース |
|
| 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: シリアル化フィールド |
|
| 2 |
| IDoc のステータス |
|
| 1 |
| テストフラグ |
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>