Example - Program Location Statements

This example illustrates program location statements and in-line rules. In addition to showing rules, program input, and Customizer output, this example goes a step further and shows the program after AMB precompiler processing.
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.

User rules:

 1.            % DEFINE $IN-LINE( &ARG)
 2.                COUNTER = &ARG
 3.                % &IN-LINE = &ARG
 4.            % END
 5.            % DEFINE $MY-EPILOGUE
 6.               % * MARK COLUMN 7 MARGIN
 7.                % SET LINKAGE
 8.                01  MY-EPILOGUE-CHR        &40+PIC X.
 9.                % SET PROCEDURE
10.                    COUNTER = 100
11.                % SET EPILOGUE $SECOND-EPILOGUE
12.            % DEFINE $SECOND-EPILOGUE
13.               % BEGIN
14.                    COUNTER = 101
15.            % SET EPILOGUE $MY-EPILOGUE

Lines 1-14:

Three rules are defined-- $IN-LINE, $MY-EPILOGUE, and $SECOND-EPILOGUE.

Line 15:

% SET EPILOGUE $MY-EPILOGUE automatically invokes $MY-EPILOGUE at the very end of the program (after line 63).

Program input:

16.            % SET EVAL-BRACKETS "<>"
17.            IDENTIFICATION DIVISION.
18.            PROGRAM-ID.
19.                                          EXAMPLE9.
20.            ENVIRONMENT DIVISION.
21.            INPUT-OUTPUT SECTION.
22.            FILE-CONTROL.
23.                SELECT YOUR-FILE      ASSIGN UT-S-YOURFILE.
24.            DATA DIVISION.
25.            FILE SECTION.
26.            FD  YOUR-FILE.
27.            01  YOUR-RECORD                 PIC X(80).
28.            WORKING-STORAGE SECTION.
29.            01  COUNTER                     PIC S9(4) COMP.
30.            01  WS-1                        PIC X.
31.            % SET END-WORKING-STORAGE
32.           * PLACE FOR STUFF THAT MUST BE AT END OF WS FOR 
33.           * CERTAIN NON-BUILDER PRE-PROCESSORS.
34.            PROCEDURE DIVISION.
35.                COUNTER = 1
36.                $IN-LINE( 2)
37.                TEST-NO-DELIMITERS = <$IN-LINE( 3)>
38.                ADD <$IN-LINE( 4)> <$IN-LINE( 5)> TO COUNTER
39.            % SET LINKAGE
40.            01  LINKAGE-STUFF              PIC X.
41.            % SET PROCEDURE
42.            % SET DELIMITERS-OPTIONAL
43.                $IN-LINE( TEST-NO-DELIMITERS)
44.                $IN-LINE( 6)
45.            % SET DATA
46.           * PLACING DATA IN DATA DIVISION
47.            % SET PROCEDURE
48.            % SET FILE
49.            FD  MY-FILE.
50.            01  MY-RECORD                  PIC X(80).
51.            % SET PROCEDURE
52.            % SET FILE-CONTROL
53.                SELECT MY-FILE         ASSIGN UT-S-MYFILE.
54.            % SET PROCEDURE
55.                OPEN INPUT MY-FILE YOUR-FILE
56.                CLOSE MY-FILE YOUR-FILE
57.            % SET WORKING-STORAGE
58.            01  TEST-NO-DELIMITERS          PIC 9(&IN-LINE).
59.            % SET PROCEDURE
60.            /* THIS IS AN S-COBOL COMMENT LINE.
61.            % SET AUXILIARY-OUTPUT
62.            THIS IS AUXILIARY FILE DATA
               /*************************************
63.            % SET NORMAL-OUTPUT

Line 31:

This is a marker for the code on line 58 that is relocated to WORKING-STORAGE; it goes immediately above this marker.

Line 36:

$IN-LINE is invoked, passing the actual argument 2 to the rule formal argument &ARG. The result appears in output line 6306 (COUNTER = 2).

Line 37:

First, the contents of the evaluation brackets are evaluated. The brackets contain a call to the $IN-LINE rule, passing the argument 3 to the rule argument &ARG. This calls the rule; the result appears in output line 6308 (COUNTER = 3).

Next, the contents of the brackets are resolved, giving TEST-NO-DELIMITERS a value. The value comes from a variable within $IN-LINE, which must have same name as the rule it belongs to, and its value is the same as the argument passed to the rule, for example, 3. Thus, <$IN-LINE( 3)> is replaced by 3, and TEST-NO-DELIMITERS = 3 is output to line 6310.

Line 38:

If we add 45 to COUNTER instead of 4 and 5, the space between the first and second appearance of the in-line rule would be omitted.

Lines 39-41:

Line 39 generates the LINKAGE SECTION statement and relocates line 40 to the Linkage Section; see output lines 5328-5330). Line 41 ends the effect of % SET LINKAGE.

Line 42:

This omits delimiters around string arguments, as on line 43.

Lines 45-47:

Line 45 relocates line 46 to immediately after the DATA DIVISION statement (see output line 5304).

Lines 48-51:

Line 48 relocates lines 49-50 to the end of the File Section (see output lines 5312-5314).

Lines 52-54:

Line 52 relocates line 53 to the end of FILE-CONTROL.

Lines 57-59:

Line 57 relocates line 58 to the end of WORKING-STORAGE.

Lines 61-63:

Line 61 outputs line 62 to an external auxiliary file named RULE.

Output source:

001700 IDENTIFICATION DIVISION.                              17.
001800 PROGRAM-ID.                                           18.
001900                               EXAMPLE9.               19.
002000 ENVIRONMENT DIVISION.                                 20.
002100 INPUT-OUTPUT SECTION.                                 21.
002200 FILE-CONTROL.                                         22.
002300     SELECT YOUR-FILE          ASSIGN UT-S-YOURFILE.   23.
005300     SELECT MY-FILE            ASSIGN UT-S-MYFILE.     53.
005302 DATA DIVISION.                                        24.
005304* PLACING DATA IN DATA DIVISION                        46.
005306 FILE SECTION.                                         25.
005308 FD  YOUR-FILE.                                        26.
005310 01  YOUR-RECORD                 PIC X(80).            27.
005312 FD  MY-FILE.                                          49.
005314 01  MY-RECORD                   PIC X(80).            50.
005316 WORKING-STORAGE SECTION.                              28.
005318 01  COUNTER                     PIC S9(4) COMP.       29.
005320 01  WS-1                        PIC X.                30.
005322 01  TEST-NO-DELIMITERS          PIC 9(6).
005324*    PLACE FOR STUFF THAT MUST BE AT END OF WS FOR   
005326*    CERTAIN NON-BUILDER PRE-PROCESSORS                33.
005328 LINKAGE SECTION.
005330 01  LINKAGE-STUFF               PIC X.                40.
006300 01  MY-EPILOGUE-CHR             PIC X.
006302 PROCEDURE DIVISION.                                   34.
006304     COUNTER = 1                                       35.
006306     COUNTER = 2
006308     COUNTER = 3
006310     TEST-NO-DELIMITERS = 3
006312     COUNTER = 4
006314     COUNTER = 5
006316     COUNTER = COUNTER + 4 5
006318     COUNTER = TEST-NO-DELIMITERS
006320     COUNTER = 6
006322     OPEN INPUT MY-FILE YOUR-FILE                      55.
006324     CLOSE MY-FILE YOUR-FILE                            56.
006326*/*  THIS IS AN S-COBOL COMMENT LINE.                  60.
006328     COUNTER = 100                                       11.
006330     COUNTER = 101                                       15.

Lines 6312-6316:

If we add 45 to COUNTER instead of 4 and 5, the space between the first and second appearance of the in-line rule would be omitted.

Line 6328:

Line 15 of the rule source (% SET EPILOGUE $MY-EPILOGUE) put $MY-EPILOGUE in the storage area called EPILOGUE. All rules in EPILOGUE are invoked at the end of the program and after Customizer processing, starting with the last rule put into EPILOGUE. Because $MY-EPILOGUE is the only rule in EPILOGUE, it is invoked. The result is line 6328 in the output.

During $MY-EPILOGUE processing, % SET LINKAGE relocates line 9 to the end of the Linkage Section (line 6300), and puts COUNTER = 100 at the end of the Procedure Division (line 6328). Line 15 is an EPILOGUE statement nested within a $MY-EPILOGUE; it puts $SECOND-EPILOGUE into the EPILOGUE area. This completes $MY-EPILOGUE processing.

Now, $SECOND-EPILOGUE, the last rule existing in EPILOGUE, is invoked.

After precompiler processing:

After Customizer processes the above program, the precompiler processes it. The result is shown below. Note the additional lines (5324 through 5340 and 6236 through 6242) that the precompile process generates.

001700 IDENTIFICATION DIVISION.                              17.
001800 PROGRAM-ID.                                           18.
001900                                 EXAMPLE9.             19.
002000 ENVIRONMENT DIVISION.                                 20.
002100 INPUT-OUTPUT SECTION.                                 21.
002200 FILE-CONTROL.                                         22.
002300     SELECT YOUR-FILE          ASSIGN UT-S-YOURFILE.   23.
005300     SELECT MY-FILE           ASSIGN UT-S-MYFILE.     53.
005302 DATA DIVISION.                                        24.
005304* PLACING DATA IN DATA DIVISION                        46.
005306 FILE SECTION.                                         25.
005308 FD  YOUR-FILE.                                        26.
005310 01  YOUR-RECORD               PIC X(80).              27.
005312 FD  MY-FILE.                                          49.
005314 01  MY-RECORD                 PIC X(80).              50.
005316 WORKING-STORAGE SECTION.                              28.
005318 77  COUNTER                   PIC S9(4) COMP.         29.
005320 01  WS-1                      PIC X.                  30.
005322 01  TEST-NO-DELIMITERS        PIC 9(6).
005322
005324 01  GENERATED--FLAGS.
005326     05  TRUE                    PIC X VALUE 'T'.
005328         88  ALWAYS              VALUE 'T'.
005330         88  NEVER               VALUE 'F'.
005332     05  FALSE                   PIC X VALUE 'F'.
005334     05  YOUR-FILE--END          PIC X.
005336     05  YOUR-FILE--INV          PIC X.
005338     05  MY-FILE--END            PIC X.
005340     05  MY-FILE--INV            PIC X.
005342
005344*    PLACE FOR STUFF THAT MUST BE AT END OF WS FOR    32.
005346*    CERTAIN NON-BUILDER PRE-PROCESSORS.              33.
005348 LINKAGE SECTION.
005350 01  LINKAGE-STUFF               PIC X.                40.
006200 01  MY-EPILOGUE-CHR             PIC X.
006202 PROCEDURE DIVISION.                                   34.
006204 MAIN--SECTION SECTION.                                35.
006206 MAIN--SECTION--PARA.                                  35.
006208     COUNTER = 1.                                      35.
006210     COUNTER = 2.
006212     COUNTER = 3.
006214     TEST-NO-DELIMITERS = 3.
006216     COUNTER = 4.
006218     COUNTER = 5.
006220     COUNTER = COUNTER + 4 5
006222     COUNTER = TEST-NO-DELIMITERS.
006224     COUNTER = 6.
006226     OPEN INPUT MY-FILE YOUR-FILE.                     55.
006228     CLOSE MY-FILE YOUR-FILE.                          56.
006230*    THIS IN AN S-COBOL COMMENT LINE                   60.
006232     COUNTER = 100.                                    11.
006234     COUNTER = 101.                                    15.
006236 MAIN--SECTION--EXIT.                                  15.
006238     EXIT PROGRAM.                                     15.
006240 MAIN--SECTION--EXIT.                                  15.
006242 STOP RUN.                                             15.