Skip to Content

Multi Mapping with Dynamic FileName and Dynamic Folder using Variable Substitution

Introduction

As we all know if we use multi mapping we cannot set dynamic file name and folder with dynamic configuration because same header is shared by all the messages,Recently there are many threads asking about this requirement, If the fields used in variable substitution are part of the target payload then dynamic file name or folder is not a problem, only those fields are not part of the target payload then we cannot use variable substitution for dynamic file name and folder but in this blog i will show you how to achieve this using variable substitution.

Approach

We will add separate node under target structure to hold the fields which are used in variable substitution and these fields are not part of the target file, we will use below content conversion parameters for this node and then file adapter will ignore this record at runtime.
CCContentConversion.png

Scenario

The scenario is we get one message with multiple orders and we need to generate multiple files at the target side with each file containing single order. We need to create dynamic folders based on plant field in the source message, we need to create dynamic file name with IDoc number.


Design

The below are sender and receiver data types used in this scenario, for simplicity i have created the own data type for IDoc, i have added separate node called ‘File’ under target structure, FileName(this field used in dynamic file name) and plant(this field used in dynamic folder) are fields under this node, these fields will be used in variable substitution in the receiver file channel in the directory.

ORDERS05.pngStockOrder.png

As we are creating multiple files from single IDoc we need to change the occurrence of receiver message to unbounded under signature part of the mapping.

/wp-content/uploads/2016/01/mapping_signature_861483.png

The below is mapping between source message and target message, all fields are simple field to field mapping, we will receive multiple IDOC nodes in source message and i am creating multiple StockOrder nodes in target side. DOCNUM (Idoc number) and WERKS i am not passing to the target file, we need these fields to set dynamic file name and folder so we need to map these two fields under File node in the target structure.

/wp-content/uploads/2016/01/mapping_861478.png

The below is FileName field mapping, IDoc number concatenate with ‘.txt’ extension.

fileNameMapping.png

Configuration

The below is receive file communication channel configuration, target directory and target file name with variables created under variable substitution section.

CCtarget.png

The below is content conversion for receiver file, As we don’t need to send the fields under File node to the target file we need to use below parameters to ignore these fields in the target file.

CCContentConversion.pngOrderHeader.png

OrderItem.png

The below is ‘fname’ and ‘plant’ variables which we used in target directory and file name.

CCAdvanced.png

Testing Results

The below is input payload, there are two IDocs with same plant(3204), so at the end we expect two dynamic folders.

inputPayload.png

The below are four messages in message monitor, one for sender to messaging system, three message for messaging system to receiver(as per our multi mapping one file split into three messages)

messageMoni.png

We can see IDoc number and the plant number are mapped under File node in the target payload.

/wp-content/uploads/2016/01/payload_861503.png

We can see in the audit log the variables plant and IDoc number are replaced at runtime.

/wp-content/uploads/2016/01/auditlog_861504.png

As we expect the two folders created under target directory.

/wp-content/uploads/2016/01/floders_861505.png

We can find two files under 3204 directory (source file contains two IDocs with same plant 3204)

/wp-content/uploads/2016/01/3204_861506.png

The below one of the file content, We can see the IDoc number and plant values are not part of the file, only it contains header and item of the order.

FileContent.png

And one file under 3205 folder.

/wp-content/uploads/2016/01/3205_861507.png

References

A new approach: Multi-mapping Dynamic Configuration using a generic custom module

Multi-mapping with Dynamic Configuration – SOAP loopback approach

Conclusion

With this approach we can still achieve dynamic file name and folder even we use multi mapping, i hope this will be helpful.

7 Comments
You must be Logged on to comment or reply to a post.