Variable Substitution Configuration Example

Lets look at how to configure Variable Substitutions at receiver File adapter. Variables or data elements from xml payload can be assigned to file name at PI/PO runtime using this method.

 

Receiver file channel has capabilities of defining the file directory and the file name of the output file. Variable substitution method is a great way to define dynamic file names if you want to add message payload information to the file name. Simply define variables and assign them values dynamically from either message header or the payload. Header attributes such as message ID, interface names, sender, receiver etc or application data under message payload could be substituted to the file name using variables.

 

Assume a scenario where, you have a Purchase Order outbound file interface and file name of the output file should contain Purchase Order number. In this case <poNumber> field in the receiver payload can be assigned to the file name in the format <po number>_Date-Time.XML.

 

Variable Substitution Configuration Steps.

Step 1 – Find the Variable in the Target Message Type.

First find the element in the target structure which you need to assign to the file name. In this example lets use <poNumber> field under <orderDetail>.
payload-variable-subsitution-file-adapter
Payload path for PONumber

 

Step 2 – Activate Variable Substitution in Receiver Communication Channel.

Activate variable substitution and Define a variable for the data element in the receiver file communication channel under ‘Advanced’ tab.
Here I have defined a new variable named ‘order_number’. In the ‘Reference’ field add the data element and the correct occurrence of the element.
variable-substitution-configuration-dynamic-file-name
Activate variable substitution and assign variables

 

1, 1, 1 are the occurrence of the data element in the payload. Variable is set from the first occurrence of the poNumber tag of the first occurrence of the orderDetail tag in first order tag.

Step 3 – Configure Dynamic Filename at Receiver Channel.

Assign the variable created in Step 2 to the file name.
configure-file-name-variable-subsitution-adapter
Configure filename with dynamic variable names

 

Test results of Variable Substitution

PO number of the first occurrence is assigned to the file name.
payload-variable-assigned
Payload

 

variable-substituted-file-name
Variable substituted to file name
For information on other methods of creating a dynamic file name at the receiver channel, check out my dynamic file name overview post.

9 thoughts on “Variable Substitution Configuration Example

  1. Prem says:

    Hi Isuru,

    Nice blog. I have a scenario where i need to use idoc BELNR in my filename.

    But as you know, we have many BELNRs in the idoc and we need to use a particular QUALF to extract right BELNR.

    Is it possible to use QUALF check in Variable Substitution like below?

    payload:SI_DUMMY,1,INVOIC02,1,IDOC,1,E1EDK02,1,BELNR[QUALF=002],1 ?

      • Jayaraj Muthukumarasamy says:

        Hi,

        It is not possible to use a condition in Variable Substitution. The best way is to go with ASMA. Retrieve the right BELNR based on QUALF in message mapping and set the filename dynamically using UDF. In the Receiver channel enable ASMA parameters to generate dynamic filename.

        Regards,
        Jay

Leave a Reply

Your email address will not be published. Required fields are marked *