Procedure 16.8. Processing an Inbound IDoc

  1. Create an Inbound Interface

    Platform uses Inbound Interfaces to consume data in IDoc format.

    Open your MPT and navigate the Outline view to Inbound Interfaces. Right-click and press "Add Inbound Interface".images/download/attachments/144836047/AddInterface-version-1-modificationdate-1645136758000-api-v2.png
    For this example, we will create an Inbound Interface to process an inbound ORDERS IDoc. Choose format type as IDoc

    images/download/attachments/144836047/AddIDocInterface-version-1-modificationdate-1645136765000-api-v2.png
  2. Configure the mapper to process the IDoc
    The inbound IDoc will need a mapper which can traverse through the IDoc segments and fields and convert it to a model. So, the processor tab has an option to specify the fully qualified name of the mapper which will be used to process the IDoc.

    images/download/attachments/144836047/IDocInterfaceProcessor-version-1-modificationdate-1645136774000-api-v2.png
  3. Setup the MessageSourcePoll
    The IDoc file has to be processed through Platform framework that parses the IDoc and validates it before passing it to the actual IDoc interface and mapper. For this, the message source poll entry for the message source should have inbound interface as PLT.ConcatenatedIDoc_IB V1.0.

  4. Setup the EdiInboundRoute

    Platform uses the EdiInboundRoute to determine the inbound interface/mapper to use to process the valid IDoc.

    The EdiInboundRoute consists of the Sender details and Receiver details along with the transaction type, interface, and the inbound queue to be used.

    The route is determined using the sender/receiver info along with the transaction set number and the inbound queue details.

    Load the EdiInboundRoute using PLT.EdiInboundRoute_IB interface, version 2.0.
    images/download/attachments/144836047/IDocEdiInboundRoute-version-1-modificationdate-1645136798000-api-v2.png

  5. Converting an IDoc to ModelList

    Platform uses the EdiInboundRoute to determine the inbound interface/mapper to use to process the valid IDoc.

    The EdiInboundRoute consists of the Sender details and Receiver details along with the transaction type, interface, and the inbound queue to be used.

    The route is determined using the sender/receiver info along with the transaction set number and the inbound queue details.

    Load the EdiInboundRoute using PLT.EdiInboundRoute_IB interface, version 2.0.images/download/attachments/144836047/IDocEdiInboundRoute-version-1-modificationdate-1645136798000-api-v22.png

  6. Converting an IDoc to ModelList

    Platform uses the EdiInboundRoute to find the IDocMapper to be used for processing the IDoc transaction set. The mapper implementation must override the public ModelList parse(IDoc iDoc) method to traverse through the IDoc and create a ModelList object along with the action to be used.

    The mapper should also implement its parameterized constructor which should invoke the super class constructor. The parameterized constructor should have EdiMessagingContext as parameter.


    public SampleIDocOrderMapper(EDIMessagingContext ediMsgContext) {
    super("ZPTS", IDOC_METADATA_FILE, ediMsgContext);
    }

    The superclass constructor must be invoked with the parameters as module prefix, XML rule file name and the EdiMessagingContext.

    Sample implementation of parse method in IDoc mapper :

    @Override
    public ModelList process(IDoc iDoc) throws Exception {
    ModelList modelList = new ModelList();
    modelList.setActionName("PLT.InsertOrUpdate");
    modelList.setCustomModelName(Order.STANDARD_MODEL_NAME);
    modelList.setError(null);
    modelList.setValueChainId(getEDIMessagingContext().getUserContext().getValueChainId());
    Order order = new Order();
    order.setValueChainId(getEDIMessagingContext().getUserContext().getValueChainId());
    for (IDocSegment segE1EDKA1 : iDoc.getSegments("E1EDKA1")) {
    if (segE1EDKA1.getField("LIFNR").getValue().equals("BUY")) {
    buyingEnterpriseName = (String) segE1EDKA1.getField("NAME1").getValue();
    }
    else if (segE1EDKA1.getField("LIFNR").getValue().equals("SEL")) {
    sellingEnterpriseName = (String) segE1EDKA1.getField("NAME1").getValue();
    }
    }
    for (IDocSegment segE1EDK02 : iDoc.getSegments("E1EDK14")) {
    if ("014".equals((String) segE1EDK02.getField("QUALF").getValue())) { //Purchasing organization
    String orgName = (String) segE1EDK02.getField("ORGID").getValue();
    order.setBuyingOrganizationName(orgName);
    order.setBuyingEnterpriseName(buyingEnterpriseName);
    order.setCreationOrganizationName(orgName);
    order.setCreationEnterpriseName(buyingEnterpriseName);
    }
    else if ("018".equals((String) segE1EDK02.getField("QUALF").getValue())) {
    String orgName = (String) segE1EDK02.getField("ORGID").getValue();
    order.setSellingOrganizationName(orgName);
    order.setSellingEnterpriseName(sellingEnterpriseName);
    }
    }
    IDocSegment segE1EDK01 = iDoc.getFirstSegment("E1EDK01");
    String orderNumber = (String) segE1EDK01.getField("BELNR").getValue();
    order.setOrderNumber(orderNumber);
    List<IDocSegment> segsE1EDP01 = iDoc.getSegments("E1EDP01");
    int itemNo = 1;
    for (IDocSegment segE1EDP01 : segsE1EDP01) {
    OrderLineItem orderLineItem = new OrderLineItem();
    orderLineItem.setOrderLineItemNumber(String.valueOf(itemNo));
    String itemName = (String) segE1EDP01.getField("POSEX").getValue();
    if (!StringUtils.isNullOrBlank(itemName)) {
    ItemRow itemRow = ItemCacheManager.getInstance().getItem(
    new ItemKey(getEDIMessagingContext().getUserContext().getValueChainId(), buyingEnterpriseName, itemName));
    orderLineItem.setItemName(itemRow.getItemName());
    orderLineItem.setItemEnterpriseName(itemRow.getEntName());
    }
    String shippedQuantity = (String) segE1EDP01.getField("MENGE").getValue();
    if (!StringUtils.isNullOrBlank(shippedQuantity)) {
    orderLineItem.setShippedQuantity(Double.valueOf(shippedQuantity));
    }
    String unitPrice = (String) segE1EDP01.getField("BMNG2").getValue();
    if (!StringUtils.isNullOrBlank(unitPrice)) {
    orderLineItem.setUnitPrice(Double.valueOf(unitPrice));
    }
    orderLineItem.setCurrency((String) segE1EDP01.getField("PMENE").getValue());
    order.getOrderLineItems().add(orderLineItem);
    itemNo++;
    }
    modelList.add(order, ModuleService.getXmlns(Order.MODEL_TYPE));
    modelList = writeModelList(modelList);
    return modelList;
    }