****************************************
      * Program name: perform.cbl
      * This sample program demonstrates the
      * various uses of the PERFORM command.
      *
      * Copyright 2000 Deskware, Inc.
      ****************************************                                                             
      * Syntax: PERFORM .
      *
      * Syntax: PERFORM  UNTIL .
      *
      * Syntax: PERFORM  VARYING 
      *             FROM  BY 
      *             UNTIL .
      *
      * Syntax: PERFORM UNTIL 
      *         END-PERFORM.
      *
      * Syntax: PERFORM VARYING 
      *             FROM  BY 
      *             UNTIL 
      *         END-PERFORM.
      *
       1 firstname               PIC X(20).
       1 test OCCURS 5 TIMES.
             5  test_var1          PIC X(07).
       1 error_var               PIC X(01) VALUE `N`.
       1 counter                 PIC S999999.99.
       1 editedcounter           PIC ZZZ,ZZZ,ZZZ.99DB.
       1 newcounter              PIC 999,999,999.99.
       1 len                     PIC 9999.99.
       1 from_var                PIC 99.99.
       1 by_var                  PIC 99.99.
       1 content_length          PIC 9V99 VALUE 9.33444444.
       1 grossrevenues           PIC 99999999.99.
       1 taxpercent              PIC .99.
       1 taxdue                  PIC 9999999V99.
       1 printtax                PIC $$$,$$$,$$$.99DB.

       MAIN.
           DISPLAY `This program will demonstrate the use of the `.
           DISPLAY `PERFORM command`.

           INITIALIZE len.
      * Here is an example of an INLINE PERFORM UNTIL.
           PERFORM UNTIL len > 7
              DISPLAY `inline perform ` & len
              ADD 1 TO len
           END-PERFORM.

           INITIALIZE counter.
           MOVE 0 TO counter.
           DISPLAY `STARTING counter: ` & counter.
      * Here is an example of a PERFORM UNTIL.
           PERFORM MODULE2
              UNTIL counter > 9.
           DISPLAY `STARTING counter: ` & counter.

           MOVE SPACES TO firstname.

           MOVE ZERO TO counter.
           MOVE 3 TO from_var.
           MOVE 1    TO by_var.
           DISPLAY `from_var: `  &
                    from_var     &
                    `  by_var: ` &
                    by_var.
      * Here is an example of a PERFORM VARYING.
           PERFORM MODULE1
              VARYING counter
              FROM from_var BY by_var
              UNTIL counter > 500
               OR firstname(3:7) = `equal50`
               OR firstname(3:7) = `equal75`.
           GOBACK. 

       MODULE1.
         DISPLAY `MODULE1: ` &
                 counter.

           INITIALIZE len.
      * Here is an example of an INLINE PERFORM UNTIL inside a called module.
           PERFORM UNTIL len > 7
              DISPLAY `inline again`
              ADD 1 TO len
           END-PERFORM.


           MOVE 100000 TO grossrevenues.
           MOVE .10 TO taxpercent.
           COMPUTE taxdue = grossrevenues * taxpercent.
           MOVE taxdue TO printtax.
           DISPLAY `grossrevenues: ` & grossrevenues.
           DISPLAY `taxpercent: `    & taxpercent.
           DISPLAY `printtax: `      & printtax.


         IF counter IS EQUAL TO 50 THEN
            DISPLAY `counter = to 50`
            MOVE `equal50` TO firstname(3:7)
         END-IF.
      
         IF counter IS EQUAL TO 75 THEN
            DISPLAY `counter = 75`
            MOVE `equal75` TO firstname(3:7)
         END-IF.

       MODULE2.
           ADD 1 TO counter.
           DISPLAY `counter ` & counter.