Appendix - Using the MFUPP Preprocessor

Fizzbuzz.cbl

Note: This copybook is used with both example 1 and example 2.
      $set sourceformat"variable"
       Program-Id. fizzbuzz.
       Working-Storage Section.
       01 Current-Number   Pic 9999.
       01 Current-Result   Pic x(10).
       01 Args             Pic x(128).
       01 Starting-Numberx Pic x(10).
       01 Ending-Numberx   Pic x(10).
       01 Starting-Number  Pic 9999.
       01 Ending-Number    Pic 9999.

       Procedure Division.
       Move Spaces To Starting-Numberx, Ending-NumberX
       Move 1 To Starting-Number
       Move 100 To Ending-Number
       Accept Args From COMMAND-LINE

       Unstring Args Delimited By Space
        Into Starting-Number, Ending-Numberx
       End-Unstring

       If Starting-Numberx Not Equal Spaces
        Move Function numval(Starting-Numberx) To Starting-Number
       End-If

       If Ending-Numberx Not Equal Spaces
        Move Function numval(Ending-Numberx) To Ending-Number
       End-If

       Perform Varying Current-Number From Starting-Number By 1
                    Until Current-Number > Ending-Number

        Perform Process-Number
        Display Current-Result
        End-Perform
       Goback.

       Process-Number Section.
       Evaluate True
        When Function mod(Current-Number,15) Equal 0
            Move "FIZZBUZZ" To Current-Result
        When Function Mod(Current-Number,7) Equal 0
            Move "BAZ" To Current-Result
        When Function Mod(Current-Number,5) Equal 0
            Move "BUZZ" To Current-Result
        When Function mod(Current-Number, 3) Equal 0
            Move "FIZZ" To Current-Result
        When Other
            Move Current-Number To Current-Result
       End-Evaluate
       .
       End Program fizzbuzz.

MFUPD_Fizzbuzz.cpy

Note: This copybook is used with example 1.
       Entry "MFUT_FIZZBUZZ".
       Move 3 To CURRENT-NUMBER
       Perform Process-Number
       display CURRENT-NUMBER " IS " CURRENT-RESULT
       If CURRENT-RESULT Not Equal "FIZZ"
        Call "MFU_ASSERT_FAIL_Z" using z"3 should be FIZZ"
       End-If.

       Move 15 To CURRENT-NUMBER
       Perform Process-Number
       display CURRENT-NUMBER " IS " CURRENT-RESULT
       If CURRENT-RESULT Not Equal "FIZZBUZZ"
        Call "MFU_ASSERT_FAIL_Z" using z"15 should be FIZZBUZZ"
       End-If.
       Goback.    

MFUWS_Fizzbuzz.cpy

Note: This copybook is used with example 2.
       copy "mfunit.cpy".

      *> data driven externals
       01 mfu-dd-CURRENT-NUMBER is MFU-DD-VALUE external.
       01 mfu-dd-CURRENT-RESULT is MFU-DD-VALUE external.

       01 ws-test-temp-message   pic x(255).

MFUPD_Fizzbuzz.cpy

Note: This copybook is used with example 2.
      *>----------------------------------------------------------------
      *>
      *> A set of tests for the "fizzbuzz" example
      *>
      *> Objective:
      *>  Tests for fizz, buzz, baz, fizzbuzz and normal number
      *>
      *>----------------------------------------------------------------
       Entry "MFUT_FIZZBUZZ".
           Move Function numval(mfu-dd-CURRENT-NUMBER) To CURRENT-NUMBER
           Perform PROCESS-NUMBER

           If CURRENT-RESULT Not Equal mfu-dd-CURRENT-RESULT
               Move Spaces To ws-test-temp-message
               String "FAIL - Got: " Delimited By Size
                 mfu-dd-CURRENT-RESULT Delimited By Space
                 ", Expected " Delimited By Size
                 CURRENT-RESULT Delimited By Space
                 ", For number " Delimited By Size
                 mfu-dd-CURRENT-NUMBER Delimited By Space
                 x"0" Delimited By Size
                   Into ws-test-temp-message
               End-String
               Call "MFU_ASSERT_FAIL_Z" Using
                   By Reference ws-test-temp-message
               End-Call
           End-If
           Goback.


       Fizzbuzz-Metadata Section.
       Entry "MFUM_FIZZBUZZ"
           Move "csv:fizzbuzz_data.csv" To MFU-MD-TESTDATA
           Goback.

fizzbuzz_data.csv

Note: This data file is used with example 2.
CURRENT-NUMBER,CURRENT-RESULT
0,FIZZBUZZ
1,0001
2,0002
3,FIZZ
4,0004
5,BUZZ
6,FIZZ
7,BAZ
8,0008
9,FIZZ
10,BUZZ
11,0011
12,FIZZ
13,0013
14,BAZ
14,BAZ
15,FIZZBUZZ
16,0016
17,0017
18,FIZZ
19,0019
20,BUZZ