The Macro entity
The purpose of a Macro is to standardize functions that are common to several batch or transactional programs or to several procedures of the same program, with possible variations. When the instance that calls the Macro is generated, the Macro lines are inserted in the code according to the values of their identifiers, which might contain parameters.
A Macro is not a subprogram because, unlike a subprogram, a Macro can contain non-consecutive statements.
However, a Macro can call a subprogram.
Macro types
- A general program outline type. It gives a program a standard structure that implements all the development standard from your site. This type of Macro is also used to describe a body of technical (system-oriented) procedures that are linked to the use of a TP monitor or a DBMS.
- A technical (system-oriented) function type. It is used to standardize specific commands, such as the input/output procedures of a DBMS (read, modify, or delete for example).
- A complex technical functions type. It resolves all the complicated procedures that are involved
in a DBMS (validation management, sequential read of a file, the technical procedures for database
updates, or particular access path that is used in a database for example).
This type is generally a combination of elementary technical functions that you must rewrite to minimize the task of connecting elementary Macros to one another.
- A general function type. It resolves certain procedures that are common to a set of applications (date validation, date transformation, or standards for online error message handling for example). This type of Macro is independent of the operating system, the TP monitor, and the DBMS in use.
- A specific function type. It is used to harmonize the development of programs that constitute a system. For example, it can be used to standardize the presentation of certain reports or screens by using common procedures that are defined in a Macro.
- A type that is used to create cross-references. For example, if a Macro calls a subprogram, you can automatically find which programs use that subprogram.
Differences between Macros and subprograms
You must often decide whether to use a subprogram or a Macro to consolidate all the procedures that are common to several Programs.
- Are the common procedures consecutive?
- Is the position of these procedures defined?
- Are there many parameters?
- Are these procedures run generally?
- If they are not consecutive, choose a Macro.
- If the position is already defined, choose a Macro.
- If there are many parameters, choose a subprogram.
- If the procedures are not run generally, choose a subprogram.
Parameterizing the key of a specific code line
You can parameterize the key of specific code lines (function code, subfunction code, and the first 2 characters of the line number). As a recommendation, before you write a Macro, you must try to structure the procedure to be written. If you minimize the number of parameters in the key, you facilitate the Macro use, obtain programs with a homogeneous structure, and minimize the resolution time of a Macro.
As a 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
- It is easier for the programmer.
- The same type of information is presented in the same order in a Program.
Documenting a Macro
Documenting a Macro is important. It gives the developer the information that is needed to use the Macro properly: the meaning of each parameter, which functions, subfunctions, or both, are used.
- In the same way as any program, in the -G Lines tab (-GC Lines),
- On the Macro Comments tab.
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. The maintenance is easier.