Examples: Variable substitution

Examples of variable substitution using XML and IBM MQ Explorer.


Examples showing how variable substitution works

Assuming that the file path to the matching trigger file is c:\MONITOR\REPORTS\Paris\Report2009.doc, the variables are substituted as shown in the following table.

Variable specification After variable substitution
${FilePath} c:\MONITOR\REPORTS\Paris\Report2009.doc
${FilePath{token=1}{separator=.}} c:\MONITOR\REPORTS\Paris\Report2009
${FilePath{token=2}{separator=.}} doc
${FilePath{token=3}} REPORTS
We can also specify a negative token index to select tokens relative to the last character of the variable, as shown in the following table. The examples in the table use the same variable value, c:\MONITOR\REPORTS\Paris\Report2009.doc.

Variable specification After variable substitution
${FilePath} c:\MONITOR\REPORTS\Paris\Report2009.doc
${FilePath{token=-2}{separator=.}} c:\MONITOR\REPORTS\Paris\Report2009
${FilePath{token=-2}{separator=\}} Paris
${FilePath{token=-4}} MONITOR

The variables that are used for substitution are only available for positive trigger conditions. Only match and fileSize trigger conditions cause variables to be substituted. If a noMatch condition is used, and there are substitution variable names in the task definition, the task is not called, and the monitor raises a return code of 103 and error message BFGDM0060E.


Example using XML

The following example task definition XML uses the monitor agent name as the source agent for the transfer (Paris), uses the penultimate directory name in the file path as the destination agent name for the transfer (Report2009), and renames the transferred file to be the root of the trigger file name with an extension of .rpt.
<?xml version="1.0" encoding="UTF-8" ?>
<request version="4.00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
   <managedTransfer>
     <originator>
       <hostName>reportserver.com</hostName>
       <userID>USER1</userID>
     </originator>
     <sourceAgent agent="${AgentName}" QMgr="QM1" />
     <destinationAgent agent="${FilePath{token=-2}}" QMgr="QMD" />
     <transferSet>
       <item mode="binary" checksumMethod="MD5">
         <source recursive="false" disposition="leave">
           <file>c:/incoming/reports/summary/report.doc</file>
         </source>
         <destination type="file" exist="overwrite">
           <file>/reports/${FileName{token=1}{separator=.}}.rpt</file>
         </destination>
       </item>
     </transferSet>
   </managedTransfer>
</request>
This results in the task XML being transformed to:
<?xml version="1.0" encoding="UTF-8" ?>
<request version="4.00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
   <managedTransfer>
     <originator>
       <hostName>reportserver.com</hostName>
       <userID>USER1</userID>
     </originator>
     <sourceAgent agent="AGENT1" QMgr="QM1" />
     <destinationAgent agent="Paris" QMgr="QMD" />
     <transferSet>
       <item mode="binary" checksumMethod="MD5">
         <source recursive="false" disposition="leave">
           <file>c:/incoming/reports/summary/report.doc</file>
         </source>
         <destination type="file" exist="overwrite">
           <file>/reports/Report2009.rpt</file>
         </destination>
       </item>
     </transferSet>
   </managedTransfer>
</request>
The variable ${FilePath{token=-2}} in the <destinationAgent> element's agent attribute is replaced with the value Paris. This value is treated in a not case-sensitive way and interpreted as a reference to the agent PARIS.


Examples using IBM MQ Explorer

When creating a resource monitor through the IBM MQ Explorer, and once the monitor properties and trigger conditions have been specified, the option is given to add transfer items to the monitor. The following examples demonstrate how the ${FilePath} and ${FileName} variables can be used in the Add a transfer item panel to customize transfers resulting from a resource monitor match.


Example 1

In order to simply transfer the source file to another location when a trigger condition is met, the ${FilePath} variable can be used:

  • Set the source File name to be ${FilePath}.
  • From the dropdown menu of Type for the destination, select Directory.
  • Set the destination File name to be the location to which you wish the source file to be transferred, for example, this could be C:\MFT\out\.


Example 2

In order to transfer the source file to another location and change the extension of the file, the ${FileName} variable can be used in conjunction with the ${FilePath} variable:

In the following example it is assumed that the file path of the source file is equal to C:\MONITOR\REPORTS\Paris\Report2009.doc:

  • Set the source File name to be ${FilePath}.
  • Set the destination File name to be the location to which you wish the source file to be transferred, followed by ${FileName{token=1}{separator=.}}, followed by the new extension of the file. For example, this could be C:\MFT\out\${FileName{token=1}{separator=.}}.rpt, which would equate to C:\MFT\out\Report2009.rpt with the source file name.


Example 3

In order to use part of the file path of the source file to determine the destination of the transfer, the ${FilePath} variable can be used in conjunction with token and separator specifications.

In the following example it is assumed that the file path of the source file is equal to C:\MONITOR\REPORTS\Paris\Report2009.doc.

It is possible to use part of the source file path to determine the destination of the file. Using the file path example of C:\MONITOR\REPORTS\Paris\Report2009.doc, if the file were to be transferred to a folder depending upon the location of the source file, that is, Paris in this example, then the following could be done:

  • Set the source File name to be ${FilePath}.
  • Set the destination File name to be the destination to where the folders for each location are situated, and then append the destination part of the file path and the file name. For example, this could be C:\MFT\out\${FilePath{token=-2}{separator=\}}\${FileName}, which would equate to C:\MFT\out\Paris\Report2009.doc with the source file name.

Parent topic: Monitor MFT resources


Related concepts


Related information