The purpose of a Macro is to standardize functions that are common
to several programs, or to several procedures of the same program. A called
Macro is a complement to the generation possibilities of the system. Usually,
a Macro. appears in a program description as if its lines had been directly
entered by a programmer.
A Macro. is not a sub-program because, unlike a sub-program, a Macro can
contain non-consecutive statements.
However, a Macro can call a sub-program.
Macro types
There are six basic types of Macros:
Differences between Macros and sub-programs
You
must often decide whether to use a sub-program or a Macro to consolidate all
the procedures that are common to several Programs.
In order to find
the answer, you must ask several questions:
- Are the common procedures consecutive?
- Is the position of these procedures defined?
- Are there a lot of parameters?
- Are these procedures executed as a general rule?
Answers to these questions will help you to determine which procedures
should be executed in a sub-program and which should be executed in a Macro.
- If they are not consecutive ⇒ Macro.
- If the position is already defined ⇒ Macro.
- If there are a lot of parameters ⇒ sub-program.
- If the procedures are not executed as a general rule ⇒ sub-program.
Parameterizing the key of a specific code line
You
can parameterize the key of specific code lines (Function code, sub-Function
code, and the first two characters of the line number). As a recommendation,
before writing a Macro, you should try to structure the procedure to be written.
Try to minimize the number of parameters in the key, so as to:
- Facilitate usage of the Macro,
- Obtain Programs with a homogenous structure,
- Minimize the resolution time of a Macro.
As a general rule, it is not recommended to use a Macro instead
of one or two specific code lines. Using specific code is less time-consuming
upon generation and limits the number of necessary Macro calls.
Consistency of parameters
A Program may call several
Macros. You should check that the parameters are used consistently.
Example: If two Macros are called into the same program,
and both use a Data Structure as a parameter, both Macros would ideally have
that Data Structure in the same position.
This has a twofold
advantage:
- It is easier for the programmer,
- The same type of information is presented in the same order in a Program
While this is not always possible, it would be wise to consider the placement
of parameters in existing Macros prior to designing a Macro.
Documenting a Macro
Documenting a Macro is important.
It gives the developer the information he/she needed to use the Macro properly:
the meaning of each parameter, which functions and/or sub-functions are used,
etc.
A Macro can be documented in two different ways:
- In the same way as any program, via the -G Lines tab
(-GC Lines section),
- On the Macro Comments tab.
Note: The comments entered on the -G Lines tab will
not be displayed in the sub-reports output by a Program or Screen Description
request (generation-print request) whereas those entered Comments tab
will. This may be the most effective way to document the meaning of the parameters,
However, since the lines will be displayed each time the Macro is called,
brevity is advised.
Overriding a Macro line
Given the same key, the
lines of a Macro are overridden by the lines of the calling program (Program
or Screen entity). It is advised to design Macros so that as few lines as
possible will be overridden by the calling programs. This helps the maintenance.