Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
engswee
Active Contributor

Introduction

As there is no dedicated Managed File Transfer (MFT) capability in PI (yet!), passthrough scenario is a common approach to achieving a 1-1 file transfer interface. A passthrough scenario is one of the simplest configuration in PI as there are no ESR objects required.

However, every now and then, we come across requirements that slightly complicates the passthrough scenario, i.e. changing the filename extension, adding prefix to the original filename, adding timestamp in a custom format. These cannot be achieved by the standard file-based adapters. To get around it, some form of mapping is required and therefore we return to the necessity to have ESR objects. Here are some common approaches so far:

  • Create a passthrough Java mapping that dynamically modifies the Dynamic Configuration attributes
  • Configure FCC at sender, perform 1-1 mapping and configure FCC at receiver
  • Execute additional OS-level commands/scripts to perform renaming/moving of file

DynamicAttributeChangeBean (DACB) is an adapter module solution that aims to fill this gap, in particular addressing these passthrough scenarios. DACB is another "develop/deploy once, use multiple times" adapter module (the likes of ExcelTransformBean) that is highly configurable and reusable.

Source Code and Deployment Archive

DynamicAttributeChangeBean belongs in the same adapter module project as FormatConversionBean. Refer to following blog for the location of source code and/or EAR deployment file.

FormatConversionBean - One Bean to rule them all!

Module Parameter Reference

Below is a list of the parameters for configuration of the module. Certain parameters will automatically inherit the default values if it is not configured.

Parameter NameAllowed valuesDefault valueRemarks
mode

add,

change,

delete,

regex,

none

Required field. Determines the mode of processing

  • add = Adds prefix and/or suffix to the attribute
  • change = Replaces a value in the attribute with a new value
  • delete = Deletes prefix and/or suffix from the attribute
  • regex = A more dynamic version of change mode performed via regular expression matching and substitution on the attribute
  • none = Used if only timestamp addition is required
namespacehttp://sap.com/xi/XI/System/FileNamespace of the input Dynamic Configuration attribute
attributeFileNameInput Dynamic Configuration attribute
outNamespaceIf blank, inherit from namespaceOptional output namespace if it differs from input Dynamic Configuration namespace
outAttributeIf blank, Inherit from attributeOptional output attribute if it differs from input Dynamic Configuration attribute
prefix

Available when mode = 'add' or 'delete'

Value at the front of attribute to be added or deleted

suffix

Available when mode = 'add' or 'delete'

Value at the end of attribute to be added or deleted

oldValue

Required field when mode = 'change'

Existing value in attribute to be replaced

newValue

Required field when mode = 'change'

New value as replacement in attribute

replaceAllY, NN

Available when mode = 'change'

Replaces all values of oldValue in the attribute

regex

Required field when mode = 'regex'

The regular expression for matching patterns of the attribute

replacement

Required field when mode = 'regex'

The replacement value for the matched patterns. Matched capturing groups from the regular expression above can be referenced in the replacement value

addTimestampY, NNAdds timestamp at the end of the attribute before the extension (the last .xxx)
timestampFormatyyyyMMdd-HHmmss-SSS

The format of the timestamp following allowed patterns in Java's SimpleDateFormat

Example Scenarios

Here are some example use case scenarios for DACB based on different configuration options. For the sake of simplicity, the results shown are Console output using the Standalone testing of Adapter Module in NWDS approach.

Scenario 1

Add prefix and suffix to the FileName attribute.

Module parameters

Parameter NameParameter Value
modeadd
namespacehttp://sap.com/xi/XI/System/File
attributeFileName
prefixMY_
suffix.zip

Result

The FileName attribute is appended with a prefix and suffix.

Scenario 2

Change the extension of the FileName attribute.

Output attribute in a different namespace.

Module parameters

Parameter NameParameter Value
modechange
namespacehttp://sap.com/xi/XI/System/File
attributeFileName
outNamespacehttp://sap.com/xi/XI/SFTP/SFTP
oldValue.txt
newValue.xml

Result

The extension is changed from txt to xml and stored in a different namespace. Note that the original input attribute is not modified.

Scenario 3

Delete the last extension.

Use default namespace and attribute.

Add a custom timestamp.

Module parameters

Parameter NameParameter Value
modedelete
suffix.pgp
addTimestampY
timestampFormat'_'yyyyMMdd

Result

The default namespace and attribute is used. The PGP extension is removed from the filename, and a timestamp is added.

Scenario 4

Dynamic change mode using regular expression.

Match the filename pattern while also capturing the two numeric groups - the first (\d+) after order Order and the second (\d+) after Batch.

Rename the output using references from the matched capturing groups ($1 and $2.)

Module parameters

Parameter NameParameter Value
moderegex
regexOrder_(\d+)_Batch_(\d+).xml
replacementPO_$1_Group_$2.txt

Result

Values 1234 and 10 are captured from the input attribute, and used in the renaming of the output attribute.

Scenario 5

And finally (and this is the most exciting example use case!) an example based on an actual requirement from this thread. For this, actual configuration and testing screenshots will be shown.

Requirement: Determine the target folder based on the dynamic values contained in the file name.

Module configuration

Monitoring Logs and Testing Result

An input file with value of Partner1_002_Invoice.xml set in the Dynamic Configuration FileName attribute.

After the module processing by DACB, an additional attribute for Directory is added, with the value dynamically determined from the input filename. The target directory = /sapinterface/xxx/Partner1/002/

The audit log shows the attribute changes and the file being routed to the dynamically determined target directory.

And we find the file in the directory as expected!

Conclusion

With usage of DACB, most passthrough scenarios can remain "ESR object"-less (although there is actually reason to have at least the Service Interface defined in ESR)

15 Comments
Labels in this area