属性の変換は、以下の方法で対話式に行うことができます。
表 14 に、Map Designer Express がコードを生成できる標準変換をリストします。
次のいずれでもカスタム変換を作成できます。
このセクションでは、次のカスタム変換のインプリメント方法を説明します。
Customer.CustomerStatus = 'Inactive' if SAP_CustomerMaster.DeleteInd = 'X'.
あるいは、CustomerStatus = 'Active' です。
カスタム変換を作成し、すべてのコードを作成して内容ベースのロジックを自分でインプリメントすることができます。しかし、より適切な方法は、DeleteInd (SAP_CustomerMaster オブジェクト内) と CustomerStatus 間に移動変換を作成することから開始する方法です (属性の移動手順については、"ソース属性の宛先属性へのコピー"を参照)。
この結果、Map Designer Express により移動変換が生成されます。サンプル・コードを以下に示します。
{ Object _cw_CpBTBSourceValue = null; // // RETRIEVE SOURCE // --------------- // // Retrieve the source value from the source business object and // place it in a local variable for code safety. // _cw_CpBTBSourceValue = ObjSAP_CustomerMaster.get("DeleteInd"); // // SET DESTINATION // --------------- // // Put the source value into the destination business object // attribute. // { Object _cw_SetSrcVal = _cw_CpBTBSourceValue; BusObj _cw_SetDestBusObj = ObjCustomer; String _cw_SetDestAttr = "CustomerStatus"; // // Set the destination value only if neither // source nor destination is null. // if ((_cw_SetSrcVal != null) && (_cw_SetDestBusObj != null)) { if (dataValidationLevel >= 1) { if (!_cw_SetDestBusObj.validData(_cw_SetDestAttr, _cw_SetSrcVal)) { String warningMessage = "Invalid data encountered when attempting to set the value of the ¥'_cw_SetDestAttr¥' attribute of BusObj ¥'_cw_SetDestBusObj¥' while running map ¥'" + getName() + "¥'. The invalid value was ¥'" + _cw_SetSrcVal + "\'."; // // Log a warning about this failure. // logWarning(warningMessage); if (failOnInvalidData) { // // Fail the map execution with a warning message. // throw new MapFailureException(warningMessage); } } } // SECTION THAT NEEDS TO BE UPDATED WITH THE LOGIC if (_cw_SetSrcVal != null) { if (_cw_SetSrcVal instanceof BusObj) { // // Since BusObjs are not immutable, we need to make // a copy of the source object before actually // putting it into the destination attribute. // _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, ((BusObj)_cw_SetSrcVal).duplicate()); } else if (_cw_SetSrcVal instanceof BusObjArray) { // // Since BusObjs are not immutable, we need to make // a copy of the source object before actually // putting it into the destination attribute. // _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, ((BusObjArray)_cw_SetSrcVal).duplicate()); } else { // // Since our version of simple data types are immutable in // Java (Strings included), we do not have to make a copy // of the source value here. // _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, _cw_SetSrcVal); } } } } } // HERE IS THE MODIFIED CODE if (_cw_SetSrcVal != null) { if (((String)_cw_SetSrcVal).equals("X")) _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, "Inactive"); else _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, "Active"); } } } }
Activity Editor の「ファイル」メニューから、「保管」を選択して変更を保管します。
Customer.CustomerStatus = 'Inactive' if Verb = 'Create' あるいは、CustomerStatus = 'Active' です。
内容ベースのロジックの手順に従います。ただし、以下の条件ステートメントを使用して、生成されたコードのセクションを置き換えます。
// HERE IS THE MODIFIED CODE if (_cw_SetSrcVal != null) { if (ObjSAP_CustomerMaster.getVerb() .equalsIgnoreCase("Create")) _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, "Inactive"); else _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr,"Active");
SAP_CustomerMaster.State を Customer.CustomerAddress.State にマップします。SAP の状態が不足している場合は、デフォルトで CA に設定します。
宛先属性にソース値を設定される前に、ソース属性が null でないかどうかをチェックします。
例: この例では、ソース・データが不足していると、宛先属性にデフォルト値が設定されます。
SAP_CustomerMaster.State を Customer.CustomerAddress.State に移動することから開始します。条件ステートメントを以下のように変更します。
// HERE IS THE MODIFIED CODE if (_cw_SetSrcVal != null) _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, _cw_SetSrcVal); else _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, "CA"); _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, "CA");
呼び出しコンテキストの値をチェックする必要がある場合は、String 型である組み込み変数 strInitiator を使用します。
例: 呼び出しコンテキストが EVENT_DELIVERY かどうかをチェックするには、以下のステートメントを使用します。
if (strInitiator.equals(MapExeContext.EVENT_DELIVERY)) //rest of the code
SAP_CustomerMaster.State を Customer.CustomerAddress.State にマップします。SAP の状態が不足している場合は、マップの実行を停止します。
SAP_CustomerMaster.State を
Customer.CustomerAddress.State
に移動することから開始します。その後、1 つの if() 文を追加して、SAP
の State 属性が null
かどうかをチェックします。生成されるコードは、以下のようになります。
{ Object _cw_CpBTBSourceValue = null; // // RETRIEVE SOURCE // --------------- // // Retrieve the source value from the source business object and // place it in a local variable for code safety. // _cw_CpBTBSourceValue = ObjSAP_CustomerMaster.get("State"); // // SET DESTINATION // --------------- // // Put the source value into the destination business object // attribute. // { Object _cw_SetSrcVal = _cw_CpBTBSourceValue; BusObj _cw_SetDestBusObj = ObjCustomer; String _cw_SetDestAttr = "CustomerAddress.State"; // New code if (_cw_SetSrcVal == null) { String errorMessage = "Data in the state attribute is missing"; logError(errorMessage); // // Fail the map execution with a warning message. // throw new MapFailureException(errorMessage); } // End of new code // // Set the destination value only if neither // source nor destination is null. // else if ((_cw_SetSrcVal != null) && (_cw_SetDestBusObj != null)) { if (dataValidationLevel >= 1) { if (!ObjCustomer.validData("CustomerAddress.State", _cw_SetSrcVal)) { String warningMessage = "Invalid data encountered when attempting to set the value of the ¥"CustomerAddress.State¥" attribute of BusObj ¥'ObjCustomer¥' while running map ¥'" + getName() + "¥'. The invalid value was ¥'" + _cw_SetSrcVal + "¥'."; // // Log a warning about this failure. // logWarning(warningMessage); if (failOnInvalidData) { // // Fail the map execution with a warning message. // throw new MapFailureException(warningMessage); } } } if (_cw_SetSrcVal != null) _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, _cw_SetSrcVal); } } }
マップが実行されて、State 属性が設定されていないと、ダイアログ・ウィンドウとサーバー画面の両方にエラー・メッセージが表示されます。サーバー画面のメッセージは、次のようになります。
[1999/09/22 17:58:51.008] [Server] Sub_SaCwCustomerMaster: Error Data in the state attribute is missing
マップは実行を停止します。
try { // your code } catch (Exception e) { throw new MapFailureException(e.toString()); }
ソース・データが不足する場合は、マップを強制的に失敗させるのサンプルで、エラー・メッセージを画面に表示するための logError() メソッドの使用方法に注意してください。 汎用メッセージ・ファイル CWMapMessages txt (¥DLMs¥messages に保管されています) に用意されているメッセージを使用できます。 メッセージ・ファイルの詳細については、付録 A, メッセージ・ファイルを参照してください。
CWMapMessages.txt のフォーマットは、以下のとおりです。
# critical data is missing error 10 Data in the {1} attribute is missing. Map execution stopped. # Another error 11 Another error message
{1} の代わりに単語 State が、表示される必要のあるエラーに直接対応して使用できることに注意してください。ただし、特定の単語を直接インプリメントすると、メッセージの汎用性は失われます。別の属性にも重大なデータが存在する場合は、その特定の属性に固有のメッセージ・ファイルに、別のメッセージが必要です。
メッセージ番号 10 を表示するには、以下のコードを使用します。
logWarning(10, "State");
単語 State により、メッセージ・テキスト内の {1} が置換されます。
次のメッセージが InterChange Server Express ログ・ファイルに表示されます。
[1999/09/23 10:17:43.648] [Server] Sub_SaCwCustomerMaster: Warning 10: Data in the State attribute is missing. Map execution stopped.
マッピング API では、DtpDate
クラスに日付の形式設定のメソッドを用意しています。表 61 に、日付の形式設定メソッドを要約します。
日付の形式設定 | DtpDate メソッド |
---|---|
日付から月名を取得 |
getMonth(), getShortMonth()
|
日付から月の数値を取得 |
getIntMonth(), getNumericMonth()
|
日を取得 |
getDayOfMonth(), getIntDay()
|
曜日を取得 |
getDayOfWeek(), getIntDayOfWeek()
|
日付から年を取得 |
getYear(), getIntYear()
|
時間値の取得 |
getHours()
|
日付から分値を取得 |
getMinutes(), getIntMinutes()
|
日付から秒値を取得 |
getSeconds(), getIntSeconds()
|
日付からミリ秒値を取得 |
getMSSince1970()
|
リストから最も古い日付を取得 |
getMinDate(), getMinDateBO()
|
リストから最新の日付を取得 |
getMaxDate(), getMaxDateBO()
|
指定形式に従った日付を構文解析 |
DtpDate()
|
指定またはデフォルトの形式で日付を取得 |
toString()
|
IBM 汎用日付形式へ日付を再形式設定
|
getCWDate()
|
日付への日数の追加 |
addDays()
|
日付への平日の数の追加 |
addWeekdays()
|
日付への年数の追加 |
addYears()
|
日付間の日数の計算 |
calcDays()
|
日付間の平日の数の計算 |
calcWeekdays()
|
日付の比較 |
after(), before()
|
完全な月名を使用 |
get12MonthNames(), set12MonthNames(), set12MonthNamesToDefault()
|
短い月名を使用 |
get12ShortMonthNames(), set12ShortMonthNames(), set12ShortMonthNamesToDefault()
|
曜日名の使用 |
get7DayNames(), set7DayNames(), set7DayNamesToDefault()
|
IBM では、汎用ビジネス・オブジェクト内の次の日付形式を使用します。
YYYYMMDD HHMMSS
この形式は、汎用日付形式 と呼ばれます。
アプリケーション固有の日付をこの汎用形式に変換するには、DtpDate クラスの getCWDate() メソッドを使用します。
例: 例えば、SAP 日付属性を汎用日付にマップするには、ソース属性 (SAP 日付ストリング) を宛先属性 (汎用日付ストリング) にコピーします。
DtpDate() コンストラクターで SAP 日付ストリング (YYYYMMDD) を構文解析して、ソース属性 (SAP 日付ストリング) を新しい DtpDate オブジェクト (汎用日付ストリング) にコピーします。
このコードの最後のセクションは、次のようになります。
// HERE IS THE MODIFIED CODE if (_cw_SetSrcVal != null) { try { DtpDate myDate = new DtpDate((String)_cw_SetSrcVal, "YMD"); _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, myDate.getCWDate()); } catch (DtpDateException de) { logError(5501); logInfo(de.getMessage()); } }
例: Clarify 日付属性を汎用日付にマップするには、ソース属性 (Clarify 日付ストリング) を宛先属性 (汎用日付ストリング) にコピーします。
DtpDate() コンストラクターで Clarify 日付ストリング (MM/DD/YYYY HH:MM:SS) を構文解析して、ソース属性 (Clarify 日付ストリング) を新しい DtpDate オブジェクト (汎用日付ストリング) にコピーします。
次のコードは、Clarify 日付を汎用日付に変換します。
if (_cw_SetSrcVal != null) { try { DtpDate myDate = new DtpDate((String)_cw_SetSrcVal, "M/D/Y h:m:s"); _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, myDate.getCWDate()); } catch (DtpDateException de) { logError(5501); logInfo(de.getMessage()); } }
汎用日付を Clarify 形式に変換するには、次のコードを使用します。
if (_cw_SetSrcVal != null) { try { DtpDate myDate = new DtpDate((String)_cw_SetSrcVal, "YMD hms"); _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, myDate.toString("M/D/Y h:m:s", true)); } catch (DtpDateException de) { logError(5501); logInfo(de.getMessage()); } }
汎用日付形式から SAP 日付形式への変換は、次の手順で行います。
DtpDate() コンストラクターで汎用日付ストリング (YYYYMMDD HHMMSS) を構文解析して、ソース属性 (汎用日付ストリング) を新しい DtpDate オブジェクト (SAP 日付ストリング) にコピーします。
次のコード・フラグメントは、この汎用日付から SAP 日付への変換を示します。
// HERE IS THE MODIFIED CODE if (_cw_SetSrcVal != null) { try { DtpDate myDate = new DtpDate((String)_cw_SetSrcVal, "YMD hms"); _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, myDate.toString("YMD")); } catch (DtpDateException de) { logError(5501); logInfo(de.getMessage()); } }
現在のシステム日付で初期化される DtpDate オブジェクトを作成するには、パラメーターを指定しないで DtpDate() コンストラクターを使用します。
DtpDate()
例: 現在日付を汎用形式にマップするには、次のコードを使用します。
//get the current date DtpDate myDate = new DtpDate(); // format the date to the destination object's format and map _cw_SetDestBusObj.set(_cw_SetDestAttr, myDate.getCWDate());
現在日付をアプリケーション固有の形式に変換するには、次のコードを使用します。
//get the current date DtpDate myDate = new DtpDate(); // format the date to the destination object's format and map _cw_SetDestBusObj.set(_cw_SetDestAttr, myDate.toString( "application format");
変換コードを作成する場合、特定の属性の参照、ストリングの操作、または API メソッドの呼び出しのために、複雑な Java 式を作成する必要があることがあります。これらの式は、Activity Editor で手動で入力することも、式ビルダーを使用して式を対話式に作成することもできます。 式ビルダーは、Activity Editor 内から使用できるユーティリティーです。
ヒント: 代わりに、Activity Editor のグラフィック表示を使用することもできます。
式ビルダーを表示するには、Activity Editor 内の式を挿入する位置にカーソルを合わせ、以下のいずれかを行います。
図 85 に、式ビルダーの主要コンポーネントを示します。
このセクションでは、式ビルダーを使用して次のストリング変換を実行する方法について説明します。
SAP_CustomerMaster.CustomerName を Customer.AccountOpenedBy に移動して、すべての文字を大文字に変換します。
toUpperCase() ストリング処理関数を使用するには、次の手順を行います。
if (_cw_SetSrcVal != null) { // // Since our version of simple data types are immutable in // Java (Strings included), we do not have to make a copy // of the source value here. // _cw_SetDestBusObj.setWithCreate( _cw_SetDestAttr, _cw_SetSrcVal); }
_cw_SetSrcVal 変数には SAP.CustomerName が含まれ、_cw_SetDestAttr には AccountOpenedBy が含まれます。
使用するメソッドがわかっている場合は、それを上記のコード行に追加します。そうでない場合は、式ビルダーを使用すると、正しいメソッドを見つけることができます。次の手順で行います。
結果: メソッド呼び出しがコードに挿入されます。
次のストリング変換では、ストリング処理メソッド (length() や substring() など) を使用して、SAP_CustomerMaster.AddressLine1 を Customer.CustomerAddress.AddressLine1 と AddressLine2 に移動します。
このストリング変換は、次の手順で行います。
if (_cw_SetSrcVal != null) // // Since our version of simple data types are immutable in // Java (Strings included), we do not have to make a copy // of the source value here. // { _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, _cw_SetSrcVal); }
_cw_SetSrcVal 変数には SAP.AddressLine1 が含まれ、_cw_SetDestAttr には CustomerAddress.AddressLine1 が含まれます。
コードは自分で変更することも式ビルダーを使用することもできます。どちらの場合も、String クラスの length()、substring(int, int)、substring(int)、および indexOf(int) メソッドを使用します。
if (_cw_SetSrcVal != null) { // first check the length of _cw_SetSrcVal if (((String)_cw_SetSrcVal).length() < 10) { // if it is less then 10, map it to AddressLine1 _cw_SetDestBusObj.setWithCreate( _cw_SetDestAttr, _cw_SetSrcVal); } else { // if the length is not less than 10, search for comma int index = ((String)_cw_SetSrcVal).indexOf(","); // if comma is found, take a substring of _cw_SetSrcVal up to // the comma and map it to AddressLine1 if (index != -1) _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, ((String)_Cw_SetSrcVal).substring(0, index)); // if comma is not found, take first 9 characters of // _cw_SetSrcVal and map them to AddressLine1 else _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, ((String)_Cw_SetSrcVal).substring(0, 9)); } }
if (_cw_SetSrcVal != null) { // first check the length of _cw_SetSrcVal if (((String)_cw_SetSrcVal).length() >= 10) { // if the length is not less than 10, search for comma int index = ((String)_cw_SetSrcVal).indexOf(","); // if comma is found, take a substring of _cw_SetSrcVal after // the comma and map it to AddressLine2 if (index != -1) _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, ((String)_Cw_SetSrcVal).substring(index + 1)); // if comma is not found, take all characters of // _cw_SetSrcVal starting at the 10th and map them to // AddressLine1 else _cw_SetDestBusObj.setWithCreate(_cw_SetDestAttr, ((String)_Cw_SetSrcVal).substring(9)); } }
自分でコードを作成する場合、ソース・データが null またはブランクでないようにします。ソース属性が null かどうかを検査するには、次のいずれかを使用します。
ソース属性が空のストリングかどうかを検査するには、以下を実行します。