Creating Macros
There are two parts to every macro: a
prototype statement and the macro code.
Prototype Statement
A prototype statement identifies the code
which follows as a macro and sets up substitution parameters if they are to be
used. You are required to code the prototype statement first in a macro.
MACRO [n] [positional] [keyword]
- You use MACRO to identify the start of a macro.
- Two types of parameter substitution are available positional and keyword.
Positional – Ordered
- No default substitution
- Must be supplied when invoking a macro or will be null (treated as nonexistent).
Keyword – Unordered
- Must supply default values
- Useful when default values are needed or for infrequently used parameters
- May be supplied or allowed to default when invoking a macro
Example
A macro called PAYLIB exists in your
library containing:
MACRO
FILE PAYROLL
NAME 1 20 A
DEPT 21 2 A
GROSS 23 4 P 2
NET 27 4 P 2
DEDUCTIONS W 4 P 2
FILE PAYROLL
NAME 1 20 A
DEPT 21 2 A
GROSS 23 4 P 2
NET 27 4 P 2
DEDUCTIONS W 4 P 2
Macro Invocation
Once you have created and stored a macro
you can use it in any program.
%macro-name macro-parameter
- The % (percent sign) directs EASYTRIEVE PLUS to retrieve a macro with the designated name.
- Macro-parameters are the parameters you want to be substituted in the macro (positional or keyword).
How to Use in a program
The PAYLIB macro on the previous page is
used in a program in this manner.
%PAYLIB
JOB INPUT PAYROLL NAME DEDUCTRPT
IF DEPT = 911 914 THRU 920
DEDUCTIONS = GROSS - NET
PRINT MACRO-EXAMPLE
REPORT MACRO-EXAMPLE
SEQUENCE DEPT NAME
TITLE 1 ‘EXAMPLE OF USING MACROS’
TITLE 2 ‘IN A PROGRAM’
LINE 1 DEPT NAME GROSS NET DEDUCTIONS
JOB INPUT PAYROLL NAME DEDUCTRPT
IF DEPT = 911 914 THRU 920
DEDUCTIONS = GROSS - NET
PRINT MACRO-EXAMPLE
REPORT MACRO-EXAMPLE
SEQUENCE DEPT NAME
TITLE 1 ‘EXAMPLE OF USING MACROS’
TITLE 2 ‘IN A PROGRAM’
LINE 1 DEPT NAME GROSS NET DEDUCTIONS
- MACRO(no substitution parameters)
- MACRO POS1 POS2(only positional parameters)
- MACRO 0 KEY1 VALUE1 KEY2 VALUE2 (only keyword parameters)
- MACRO 2 POS1 POS2 KEY1 VALUE1 (keyword and positional combined)
No comments:
Post a Comment