*****************************************
      * Program name: f_exec.cbl
      * This program provides a file processing
      * example of EXECUTE command usage.
      *
      * Copyright 2000 Deskware, Inc.
      *****************************************

       1 file_name_list.
        5 file_name_01 PIC X(n) VALUE `first.dat`.
        5 file_name_02 PIC X(n) VALUE `second.dat`.
        5 file_name_03 PIC X(n) VALUE `third.dat`.
        5 file_name_04 PIC X(n) VALUE `fourth.dat`.
        5 file_name_05 PIC X(n) VALUE `fifth.dat`.
        5 file_name_06 PIC X(n) VALUE `sixth.dat`.
        5 file_name_07 PIC X(n) VALUE `seventh.dat`.
        5 file_name_08 PIC X(n) VALUE `eighth.dat`.

      * file name target variable definition
       1  file_name_var PIC X(12).

      * file record definition
       1 file_record.
        5 field_1 PIC 99.
        5 field_2 PIC XX VALUE `AB`.

      * move statement to be executed
       1  move_exec.
        5  `MOVE file_name_`.
        5  counter PIC 99.
        5  ` TO file_name_var`.

       PERFORM VARYING counter FROM 1 BY 1 UNTIL counter > 8
          EXECUTE move_exec
          FD file_name_var RECORD IS 4 BYTES
          OPEN file_name_var FOR WRITING
          PERFORM VARYING field_1 FROM 1 BY 1 UNTIL field_1 > 10
             IF field_1 > 5
                MOVE `CD` TO field_2
             END-IF
             WRITE file_record TO file_name_var
          END-PERFORM
          CLOSE file_name_var
       END-PERFORM.
       GOBACK.