Example - Invoking Rules

The following example shows two sample user rules - $CONSTRUCT-FD and $DAYDEF - and how a program invokes and uses them. To illustrate how AMB processes rules, we show the program at the following two stages of generation.
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.
  • Before AMB inserts the rule source in the program. The program at this stage is stored in the GENSRC directory or data set in your Project and Group.
  • After AMB inserts the rule source in the executable COBOL program.

The rules are defined in a USERMACS file. The $CONSTRUCT-FD rule writes FD statements. The program calls the rule and passes arguments--the FD file names--to the FD file name variable in the rule. The $DAYDEF rule builds a Working-Storage symbol table. The program repeatedly calls the rule and passes arguments--literal strings and their lengths--to the string and length variables in the rule.

User-defined rules:

% DEFINE $CONSTRUCT-FD( &FILE-NAME)
    FD  &FILE-NAME
        BLOCK CONTAINS 0 RECORDS
        LABEL RECORDS ARE STANDARD.
% END

% DEFINE $DAYDEF( &DAY, &LEN)
    % &DAYCTR = &DAYCTR + 1
    02  FILLER.
      03  FILLER          PIC S9(2) COMP SYNC VALUE +&LEN.
      03  FILLER          PIC X(9) VALUE &QT&DAY&QT.
% END

Program before rule source:

 % &REC-LEN = 121                                     315.
 % &DAYCTR = 0                                        316.
 % &QT = "'"                                          317.
                                                      318.
 IDENTIFICATION DIVISION.                             319.
 PROGRAM-ID.                     EXAMPLE3.            320.
*SPECIAL CONSIDERATIONS.                              321.
*    SAMPLE PROGRAM: CALLS TO RULES THAT WRITE        322.
*    AN FD STATEMENT AND BUILD A TABLE.               323.
                                                      324.
 ENVIRONMENT DIVISION.                                325.
 INPUT-OUTPUT SECTION.                                326.
 FILE-CONTROL.                                        327.
 SELECT INPUT-FILE           ASSIGN "INPUT".          328.
 SELECT OUTPUT-FILE          ASSIGN "OUTPUT".         329.
                                                      330.
 DATA DIVISION.                                       331.
 FILE SECTION.                                        332.
                                                      333.
 $CONSTRUCT-FD( 'INPUT-FILE')                         334.
 01  INPUT-RECORD                PIC X(&REC-LEN).     335.
                                                      336.
 $CONSTRUCT-FD( 'OUTPUT-FILE')                        337.
 01  OUTPUT-RECORD               PIC X(&REC-LEN).     338.
 WORKING-STORAGE SECTION.                             340.
                                                      341.
 01  DAY-TABLE.                                       342.
   $DAYDEF( 'SUNDAY', 6)                              343.
   $DAYDEF( 'MONDAY', 6)                              344.
   $DAYDEF( 'TUESDAY', 7)                             345.
   $DAYDEF( 'WEDNESDAY', 9)                           346.
   $DAYDEF( 'THURSDAY', 8)                            347.
   $DAYDEF( 'FRIDAY', 6)                              348.
   $DAYDEF( 'SATURDAY', 8)                            349 
 01  DAY-TABLE-REDEF   REDEFINES DAY-TABLE            350.
   02  DAY-ENTRY   OCCURS &DAYCTR.                    351.
     03  DAY-LEN   PIC S9(2) COMP SYNC.               352.
     03  DAY-BOL   PIC X(9).                          353.

Program after rule source:

030200                                                315 
030800                                                316.
031100                                                317.
031800                                                318.
031900 IDENTIFICATION DIVISION.                       319.
032000 PROGRAM-ID.                     EXAMPLE3.      320.
032100*SPECIAL CONSIDERATIONS.                                       
321.
032200*    SAMPLE PROGRAM: CALLS TO RULES THAT WRITE  322.
032300*    AN FD STATEMENT AND BUILD A TABLE          323.
032400                                                324.
032500 ENVIRONMENT DIVISION.                          325.
032600 INPUT-OUTPUT SECTION.                          326.
032700 FILE-CONTROL.                                  327.
032800 SELECT INPUT-FILE      ASSIGN "INPUT".         328.
032900 SELECT OUTPUT-FILE     ASSIGN "OUTPUT".        329.
033000                                                330.
033100 DATA DIVISION.                                 331.
033200 FILE SECTION.                                  332.
033300                                                333.
033400 FD  INPUT-FILE                                 334.
033402     BLOCK CONTAINS 0 RECORDS                   334.
033404     LABEL RECORDS ARE STANDARD.                334.
033500 01  INPUT-RECORD                PIC X(121).    335.
033600                                                336.
033700 FD  OUTPUT-FILE                                337.
033702     BLOCK CONTAINS 0 RECORDS                   337.
033704     LABEL RECORDS ARE STANDARD.                337.
033800 01  OUTPUT-RECORD               PIC X(121).    338.
033900                                                339.
034000 WORKING-STORAGE SECTION.                       340.
034100                                                341.
034200 01  DAY-TABLE.                                 342.
034300   02  FILLER.                                  343.
034302     03  FILLER   PIC S9(2) COMP SYNC VALUE +6. 343.
034304     03  FILLER   PIC X(9)  VALUE 'SUNDAY'.     343.
034400   02  FILLER.                                  344.
034402     03  FILLER   PIC S9(2) COMP SYNC VALUE +6. 344.
034404     03  FILLER   PIC X(9)  VALUE 'MONDAY'.     344.
034500   02  FILLER.                                  345.
034502     03  FILLER   PIC S9(2) COMP SYNC VALUE +7. 345.
034504     03  FILLER   PIC X(9)  VALUE 'TUESDAY'.    345.
034600   02  FILLER.                                  346.
034602     03  FILLER   PIC S9(2) COMP SYNC VALUE +9. 346.
034604     03  FILLER   PIC X(9)   VALUE 'WEDNESDAY'. 346.
034700   02  FILLER.                                  347.
034702     03  FILLER   PIC S9(2) COMP SYNC VALUE +8. 347.
034704     03  FILLER   PIC X(9)  VALUE 'THURSDAY'.   347.
034800   02  FILLER.                                  348.
034802     03  FILLER   PIC S9(2) COMP SYNC VALUE +6. 348.
034804     03  FILLER   PIC X(9)  VALUE 'FRIDAY'.     348.
034900   02  FILLER.                                  349.
034902     03  FILLER   PIC S9(2) COMP SYNC VALUE +8. 349.
034904     03  FILLER   PIC X(9)VALUE 'SATURDAY'.     349.
035000 01  DAY-TABLE-REDEF   REDEFINES DAY-TABLE.     349.
035100   02  DAY-ENTRY  OCCURS 7.                     351.
035200     03  DAY-LEN  PIC S9(2) COMP SYNC.          352.
035300     03  DAY-BOL  PIC X(9).                     353.