Sunday, 4 August 2013

Easytrieve Macro Sample Program.


Macro Example with Parameter Substitution
A macro, called CNTLRPT, exists in your library, containing:

  MACRO 2  CNTL-FLD  VALUE RANGE  ‘  ‘  HIGH-VALUE ‘  ‘
*
  IF &CNTL-FLD  =  &VALUE  &RANGE  &HIGH-VALUE
           PRINT        RPT1
 END-IF
*
 REPORT    RPT1
           SEQUENCE    &CNTL-FLD NAME
           CONTROL      &CNTL-FLD NEWPAGE
           TITLE 1           ‘CONTROL REPORT OF NAME WITHIN &CNTL-FLD’          +
                                  &CNTL-FLD
           LINE 1             &CNTL-FLD NAME GROSS-PAY NET-PAY
The ampersand
(&) tells EASYTRIEVE PLUS which values are to be passed to the macro.
To use CNTLRPT, code:
%PAYLIB
JOB   INPUT   PAYFILE   NAME   REGPROG
%CNTLRPT   REGION   516

OR

 %PAYLIB   JOB   INPUT   PAYFILE   NAME   REGPROG
 %CNTLRPT   REGION   516   RANGE   THRU   HIGH-VALUE   520

 OR

 %PAYLIB   JOB   INPUT   PAYFILE   NAME   REGPROG
 %CNTLRPT   REGION   ‘516   520   525   580’
Macro Examples
The following examples illustrates some of the uses of macros.
Commonly Used Routines
This macro provides for using SYSDATE for comparison with any other data in a file.
  MACRO USER-DATE
*
*        GET THE CURRENT DATE AND PUT INTO
*        USER FIELD (LESS SLASHES)
*        DEFINE GETDATE-DATE W 8 A
*
 DEFINE   GETDATE-FIRST6   GETDATE-DATE     6       N
 DEFINE   GETDATE-LAST5   GETDATE-DATE   +3   5  A
 DEFINE   GETDATE-LAST6   GETDATE-DATE   +2   6  A
 DEFINE   GETDATE-LAST3   GETDATE-DATE   +5   3  A
 DEFINE   GETDATE-LAST2   GETDATE-DATE   +6   2  A
*
 GETDATE-DATE    =   SYSDATE . *  MOVE   ALL   8
 GETDATE-LAST3  =   GETDATE-LAST2 . *  SHIFT  LEFT  OVER NEXT   / 
 GETDATE-LAST6  =   GETDATE-LAST5 . *  SHIFT  LEFT  OVER FIRST   /
 &USER-DATE        =   GETDATE-FIRST6 . *  MOVE  TO  USER  FIELD
*
The DEFINE Statement allows you to define to define data fields outside of the library.


Created with Artisteer

No comments:

Post a comment