A macro variable is a string enclosed in ${ and } (for example, ${datetime}), used to indicate the substitution of other data. You can use macros for many reasons, including, for example, building on filenames from the source to the destination.
Rules Regarding Macro Variable Use
Most of these rules apply uniformly to macro use throughout this article. Two exceptions are noted where applicable: the case-sensitivity rule for ${file} and ${filename}, and the %% escaping rule. The %% rule depends on the command, not the Framework or Connector Processing context: it applies to GET, PUT, and SET commands, but not to PreProcessingCommand or PostProcessingCommand command strings.
- Macros are identified by
${c}, wherecis one-to-many characters. - Macro variables are case-insensitive. You can enter them in lowercase or uppercase, except for
${file}and${filename}, which must be written in lowercase. - Escape each
%character as%%when it appears in a string containing macros to be resolved by aGET,PUT, orSETcommand. Because%has a special meaning during macro processing, the software removes the extra%after substitution to produce the intended character sequence.
This requirement does not apply toPreProcessingCommandorPostProcessingCommandcommand strings, where%can be used literally. - You can use macros multiple times within the same command. For
${datetime}the same substitution value is used in all references within the same command. - If the path of the any of the files referenced in the macros contains embedded spaces (for example.,
%sourcefile%resolves totest 1.edi) it might be necessary to add double quotes to the macro specification(s) in the command in order for the command to be properly processed by the operating system. For example,GET * "${sourcefile}.xxx".
Reserved Macro Variables
These macro names are reserved by the system and can't be redefined as custom macros. They fall into two groups depending on which properties consume them: Framework Macros and Connector Processing Macros.
Framework Macros
Used with the Data Flow framework’s transfer hooks (PreGetCommand, PostGetCommand, PrePutCommand, and PostPutCommand) and supported on FTP/FTPS and SFTP endpoints. These hooks are distinct from PreProcessingCommand and PostProcessingCommand, documented under Connector Processing Macros, and use different macros to reference the transferred file. See Usage Notes for how Framework Macros and Connector Processing Macros overlap.
Framework Macro Contexts
Framework macro variables are valid in certain contexts. The following describes the various contexts in which macro variables are valid. Not all macro variables are valid in all contexts.
Source - Applies to the "source" values of PUT and GET commands.
Destination - Applies to the "destination" values of PUT and GET commands.
Post/Pre Command - Applies to the properties Post Get Command, Post Put Command, Pre Get Command, and Pre Put Command as described in SET command in the Data Flow Command Reference article.
See also: Connector Processing Macros, below, for the separate PreProcessingCommand/PostProcessingCommand properties on File System and SMB endpoints.
The following table outlines the Framework Macros and the contexts in which each is valid:
| Macro Variable | Context | ||
|---|---|---|---|
| Source | Destination | Pre/Post Command | |
| ${sourcefile} | X | X | |
| ${srcfile} | X | X | |
| ${sourcefilebase} | X | X | |
| ${srcfilebase} | X | X | |
| ${sourcefileext} | X | X | |
| ${srcfileext} | X | X | |
| ${destfile} | X | ||
| ${destfilebase} | X | ||
| ${destfileext} | X | ||
| ${datetime} | X | X | X |
Note: Cells with a bolded, italicized, underscored X indicate the value might not be known. If the value is not known, the macro name (for example, ${sourcefile}) is simply passed through. Further, if a macro is used that is not supported within a particular context (for example, referencing ${destfile} within a Source context), it will simply be passed through as well.
Framework Macro Descriptions
The following macros are valid in the contexts defined above:
| Macro | Description |
|---|---|
|
|
References the source file name involved in the current operation. |
|
|
References the source file name base (everything up to, but not including, the last '.'. |
|
|
References the source file name extension (everything from, and including, the last '.'. If no extension is contained in the source file, blank is returned. |
${destfile} |
References the destination file name involved in the current operation. Note: Unlike |
${destfilebase} |
References the destination file name base (everything up to, but not including, the last '.'. |
${destfileext} |
References the destination file name extension (everything from, and including, the last '.'. If no extension is contained in the destination file, blank is returned. |
${datetime:format} |
Specifies the current date/time in the specified format. |
Connector Processing Macros
PreProcessingCommand and PostProcessingCommand are properties supported only by the File System and SMB connectors. They are distinct from the PreGetCommand/PostGetCommand/PrePutCommand/PostPutCommand properties documented under Framework Macros, and use different macros to reference the transferred file. See Usage Notes for how Framework Macros and Connector Processing Macros overlap.
Connector Processing Macro Descriptions
The following macros are used with PreProcessingCommand/PostProcessingCommand, properties supported only on File System and SMB endpoints.
| Macro | Description |
|---|---|
${file} |
The connector-side path and filename of the file involved in the operation — the source file before a GET, or the delivered destination file after a PUT. For File System endpoints, this is a filesystem path. For SMB endpoints, this is an SMB URL, not a local Windows path. |
${filename} |
The name only (no path) of that same file. |
Scope and behavior by connector
${file} and ${filename} are only meaningful where PreProcessingCommand/PostProcessingCommand are supported in the first place — confirm the endpoint type before using them.
| Connector | Supports Pre/PostProcessingCommand? | Notes |
|---|---|---|
| File System | Yes | Postprocessing (after PUT) supports OS commands or built-in commands ($LCOPY, $LDELETE, $LREPLACE). Preprocessing (before GET) supports built-in commands only — not OS commands. ${file} expands to a filesystem path. |
| SMB | Yes | Both hooks support only $LCOPY, $LDELETE, $LREPLACE — OS commands are not supported. ${file} expands to an SMB URL, not a local path. |
|
S3, FTP, SFTP, AS2 |
No | Not supported at all, including via custom SET PostProcessingCommand=.... |
Usage Notes
-
${file}and${filename}must be written in lowercase, unlike Framework Macros, which are case-insensitive. -
${sourcefile}/${srcfile}and${destfile}are Framework Macros that return filenames without directories, documented forPreGetCommand/PostGetCommand/PrePutCommand/PostPutCommand. They are not valid substitutes for${file}/${filename}in OS processing commands underPreProcessingCommand/PostProcessingCommand. - The distinction above applies specifically to referencing the transferred file. Although the built-in
$LCOPYcommand can resolve Framework Macros such as${srcfile}and${datetime}inPreProcessingCommandandPostProcessingCommand,${sourcefile},${srcfile}, and${destfile}cannot be used in place of${file}or${filename}for that purpose.
${datetime} Macro Reference
${datetime} supports pattern-based formatting and optional date/time arithmetic beyond simple substitution. This section defines the format syntax and the operations available when using ${datetime} — see Framework Macro Descriptions, above, for where ${datetime} itself is introduced as a macro.
Format for ${datetime} Macro
In the pattern, all ASCII letters are reserved as pattern letters, which are defined as the following:
| Symbol | Meaning | Example |
|---|---|---|
G |
era designator | AD |
y |
year | 2004 |
M |
month in year | September & 09 |
d |
day in month | 15 |
h |
hour in am/pm (1~12) | 12 |
H |
hour in day (0~23) | 0 |
m |
minute in hour | 30 |
s |
second in minute | 24 |
S |
millisecond | 352 |
E |
day in week | Wednesday |
D |
day in year | 259 |
F |
day of week in month | 2 (2nd Wed in September) |
w |
week in year | 35 |
W |
week in month | 2 |
a |
am/pm marker | PM |
k |
hour in day (1~24) | 24 |
K |
hour in am/pm (0~11) | 0 |
z |
time zone | Central Standard Time |
' |
escape for text | delimiter |
" |
single quote | ' |
Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] are treated as quoted text. For instance, characters like '.', '#' and '@' appear in the resulting date or time text even if they are not enclosed within single quotes.
Note: A pattern containing any invalid pattern letter will result in a thrown exception during formatting or parsing.
Examples Using Pattern Strings:
| ${datetime} Format Pattern | Result |
|---|---|
MM-dd-yyyy |
09-15-2004 |
EEE_MMM_d_yy |
Wed_September_15_04 |
h_mm_a |
12_08_PM |
K_mma-z |
0_00PM-CST |
Using ${datetime} operations
Use operations in the ${datetime} macro to specify variants of the date and time in either the past or the future. The format of the macro with operations depends on which fields are included.
When only date fields are included in the format:
${datetime[+/-#y][+/-#m][+/-#d]:format}
Otherwise, when time fields are included in the format:
${datetime[+/-#h][+/-#m][+/-#s]:format}
The '#' character specifies one or more digit values and the order of the +/- fields (y=year, m=month, d=day, h=hour, m=minute, s=second) dictates the order of the operation. Calendar rules, however, still apply. For example, if the operation causes the day to wrap to the next month then the month value is automatically incremented.
The format parameter variable is case-insensitive and is always required. If it is specified with the +/- field(s), it must be specified as the last parameter.
Note: You can only use date operations when the format includes only date fields and not time fields. Otherwise, you can only use time operations.
Macro Variable Usage Examples
Destination File Examples:
| Command | Destination Result |
|---|---|
PUT test.edi ${datetime:yyyyMMdd_HHmmssSSS}.edi |
20090714_131524352.edi |
GET test.edi ${srcfilebase}.${datetime:MMdd}${srcfileext} |
test.0713.edi |
SET PostProcessingCommand=cmd /c copy "${file}" C:\Inbox\Archive\PUT -UNI *
|
On a File System endpoint, after each file is sent, a copy of the delivered file is placed in C:\Inbox\Archive\. |
SET PostProcessingCommand=$LCOPY "${filename}" "archive\"PUT -UNI *
|
On an SMB endpoint, after each file is sent, the built-in $LCOPY command copies the delivered file into the archive folder on the same SMB share. ${filename} is the name of the delivered file, without a path, and relative paths resolve to the endpoint’s folder. |
GET * "${srcfile}.bak" |
order.edi is retrieved as order.edi.bak. |
Comments
1 comment
For Pre/PostProcessing Commands on File System endpoints, I have found that ${file} must be used to reference the file that was delivered in the PUT. Example below
SET PostProcessingCommand=cmd /c cp ${file} C:\Inbox\Archive\
PUT -UNI *
Please sign in to leave a comment.