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.
The following table outlines the macro variables and the various contexts in which they can be used.
Macro Variable | Context | ||
---|---|---|---|
Source | Destination | Pre/Post Command | |
${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.
Context Definitions
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 Advanced Commands topic. |
Rules Regarding Macro Variable Use
Below are some general rules for macro variable use.
- Macros are identified by
${c}
, wherec
is one-to-many characters. - Macro variables are case-insensitive. You can enter them in lowercase or uppercase.
- When a string contains macros to be resolved and one or more
%
characters, you must escape each%
character with%%
. This is because the%
character has a special use during internal macro processing. After all macro substitution takes place, the software strips the extra%
, yielding the intended character sequence. - 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
Below is the table of all reserved macro variables.
Macro | Description |
---|---|
Framework Macros | |
${sourcefile}
|
References the source file name involved in the current operation. |
${sourcefilebase}
|
References the source file name base (everything up to, but not including, the last '. '. |
${sourcefileext}
|
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. |
${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. |
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 |
Comments
0 comments
Please sign in to leave a comment.