This section provides the following tips on the use of submaps:
For an introductions to submaps, see "Transforming with a submap".
Often the map requires some programming logic to determine when to call a submap. Sometimes you might have certain conditions that must be true for the submap to be called. This logic goes into the main map, in the attribute that contains the submap's destination business object, and before the call to the runMap() method. If you enter these conditions in the Conditions area of the Submap dialog (see Figure 21), Map Designer Express adds these conditions to the if statement with which it surrounds the runMap() call.
Guidelines: Keep the following points in mind when entering these conditions:
Example: In the business objects shown in Figure 20 the OrderLine business object has an attribute called DelSched, which is a child business object. In a submap condition, you can refer to that attribute as follows:
currentBusObj_For_ObjOrder_OrderLine_DelSched
Enter the following submap condition in the Conditions area of the Submap dialog to execute a submap on the DelSched business object only if the value of the TransportType attribute of the same business object is equal to the string AIR.
currentBusObj_For_ObjOrder_OrderLine_DelSched.getString( "TransportType").equals("AIR")
The following condition executes the submap for OrderLine DelSched attributes only if the OrderLine LinePrice attribute value is greater than $10,000.00.
ObjOrderLine.getFloat["LinePrice") > 10000.00
Example: Conditions are needed for the following ma because the mapping should occur only if SAP_CustPartnerFunctions.PartnerId is not equal to SAP_CustomerMaster.CustomerId:
SAP_CustomerMaster.SAP_CustSalesAreaData.SAP_ CustPartnerFunctions[n]
to
Customer.RelatedCustomerRef
The following sections take you through the steps in creating the map call:
To create the Sub_SaCwCustCreditAreaData submap, perform the following steps from within Map Designer Express:
Specify a source business object of SAP_CustPartnerFunctions and a destination business object of RelatedCustomerRef. Name the map as Sub_SaCwCustPartners.
Map validation OK. Native Map: Code generation succeeded.
To call the Sub_SaCwCustCreditAreaData submap, perform the following steps from within Map Designer Express:
In the case of a simple condition, you can type it into the Condition area for Submap dialog window:
currentBusObj_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_ SAP_CustPartnerFunctions.getString("PartnerId")).equals( parent_custid)
Map Designer Express generates the code for the submap call with the condition added to the if statement that precedes the submap call.
If you leave the Condition field blank and click OK, Map Designer Express generates the code for the submap call without the condition. Continue to step 2 for information on how to explicitly add the code.
To access Activity Editor, double-click the Rule column again and click the View Code push-button of the Submap dialog.
For the RelatedCustomerRef attribute, the code that includes the
condition follows:
{ BusObjArray srcCollection_For_ObjSAP_CustomerMaster_ SAP_CustSalesAreaData_ SAP_CustPartnerFunctions = ObjSAP_CustomerMaster.getBusObjArray( "SAP_CustSalesAreaData.SAP_CustPartnerFunctions"); String parent_custid = ObjSAP_CustomerMaster.getString("CustomerId"); // // LOOP ONLY ON NON-EMPTY ARRAYS // ----------------------------- // // Perform the loop only if the source array is non-empty. // if ( (srcCollection_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_ SAP_CustPartnerFunctions != null) && (srcCollection_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions.size() > 0)) { int currentBusObjIndex_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions; int lastInputIndex_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions = srcCollection_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions.getLastIndex(); for (currentBusObjIndex_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions = 0; currentBusObjIndex_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions <= lastInputIndex_For_ObjSAP_CustomerMaster_ SAP_CustSalesAreaData_SAP_CustPartnerFunctions; currentBusObjIndex_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions++) { BusObj currentBusObj_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions = (BusObj) (srcCollection_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions.elementAt(currentBusObjIndex_For_ObjSAP_CustomerMaster_SAP _CustSalesAreaData_SAP_CustPartnerFunctions)); // // INVOKE MAP ON VALID OBJECTS // --------------------------- // // Invoke the map only on those child objects that meet certain // criteria. // if (currentBusObj_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions != null) { if (! (currentBusObj_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions.getString("PartnerId")).equals(parent_custid)) { currentBusObj_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions.setVerb(ObjSAP_CustomerMaster.getVerb()); BusObj[] _cw_inObjs = { currentBusObj_For_ObjSAP_CustomerMaster_SAP_CustSalesAreaData_SAP _CustPartnerFunctions }; try { BusObj[] _cw_outObjs = DtpMapService.runMap("Sub_SaCwCustPartners", "CwMap", _cw_inObjs, cwExecCtx); ObjCustomer.setWithCreate("RelatedCustomerRef", _cw_outObjs[0]); } catch (MapNotFoundException me) { logError(5502, "Sub_SaCwCustPartners"); throw new MapFailureException ("Submap not found"); } } } } }
You can use Map Designer Express to automatically generate a submap call through the Submap dialog. However, you can also use Expression Builder to generate the submap call. Coding the map call allows you to write more varied operations than Map Designer Express supports graphically. For example, you can use a submap to provide a value for an attribute that does not contain a child business object or use a submap that has multiple inputs and outputs.
Perform the following steps to use Expression Builder to generate a submap call:
Figure 91. Coding a submap call
Result: Map Designer Express generates the Java code necessary to call the map you specify as a submap. It displays in the code area at the top of the Expression Builder window.
Replace the placeholders InObj, InAttrName, OutObj, and OutAttrName with the correct names for the following:
Result: The code is inserted into Activity Editor at the insertion point.
To map source business objects of different types to a destination business object, you need to create a many-to-one submap.
Example: This kind of mapping would be needed for the following map:
SAP_CustCreditControlAreaData[n] to Customer.CustomerInformation.CustomerCreditData[0]. CreditAreaCreditData[n]
Some of the attributes must be mapped from SAP_CustomerMaster and SAP_CustCreditCentralData.
Transforming multiple source business objects of different types involves the following major steps:
To create a submap that maps source child business objects of different types to one destination child object, you create a map with the many source business objects and the single destination business object. This map contains the transformations for attributes in the different source object to the corresponding attributes in the destination object.
To create a many-to-one submap, perform the following steps from within Map Designer Express:
Drag SAP_CustCreditControlAreaData, SAP_CustCreditCentralData, and SAP_CustomerMaster business objects into the left half of the mapping screen, and CreditAreaCreditData into the right half. The new map will have three source objects and one destination object.
Recommendation: Submap names should begin with the prefix "Sub_". For example: Sub_SaCwCustCreditAreaData.
Unless the relationship management is performed in this submap, it does not matter which source object is used to set the verb. Ensure that when you call this submap, you set the verb for the same particular object before passing it into the submap. If one of the source objects is the source parent object and you choose to use its verb, you do not need to set the verb before passing this object into the submap; it already has a verb associated with it.
Result: If everything is correct, the following message displays:
Map validation OK. Native Map: Code generation succeeded.
To invoke the many-to-one submap, call it with the runMap() method from the main map, in the attribute that holds the submap's destination business object. To invoke the Sub_SaCwCustCreditAreaData submap, perform the following steps from within Map Designer Express:
For the Sub_SaCwCustCreditAreaData submap, the main map is the map that contains the CreditAreaCreditData business object as an attribute.
Double-click the Transformation Rule column associated with the CreditAreaCreditData attribute to open its Activity Editor and enter the following code:
{ BusObj srcobj1 = ObjSAP_CustomerMaster; BusObj srcobj2 = (BusObj) (ObjSAP_CustomerMaster.getBusObj("SAP_CustCreditCentralData")); BusObjArray srcobj3 = (BusObjArray)(ObjSAP_CustomerMaster.get( "SAP_CustCreditControlAreaData")); // // INVOKE MAP ON VALID OBJECTS // --------------------------- // // Invoke the map only on those child objects that meet certain // criteria. // int i = 0; // When checking all 3 source objects, != null might be not required if (srcobj1 != null && srcobj2 != null & srcobj3 != null) { for (i = 0; i < srcobj3.size(); i++) { BusObj[] _cw_inObjs = new BusObj[3]; // set verb for the one of the following objects _cw_inObjs[0] = srcobj1; _cw_inObjs[1]= srcobj2; _cw_inObjs[2] = srcobj3.elementAt(i); try { BusObj[] _cw_outObjs = DtpMapService.runMap( "Sub_SaCwCustCreditAreaData", "CwMap", _cw_inObjs, cwExecCtx); ObjCustomer.setWithCreate( "CustomerInformation.CustomerCreditData[0].CreditAreaCreditData[" + i + "]", _cw_outObjs[0]); } catch (MapNotFoundException me) { logError(5502, "Sub_SaCwCustCreditAreaData"); throw new MapFailureException ("Submap not found"); } } } }
logInfo("in for loop");
or
trace("in for loop");
If everything is working properly and none of your source objects is null, the message in for loop displays in the InterChange Server Express log file as many times as there are instances of the source child object.