       $set p(prexml) endp
       identification division.
       program-id. Migrate.

      ******************************************************************
      *Assign for existing COBOL indexed file.
      *****************************************************************
       select customer-file assign to "customers"
                            organization is indexed
                            record key is customer-id
                            alternate key is customer-name
                            access mode is dynamic.

      ******************************************************************
      *Assign for new XML file "customer.xml".  This is the target for
      *the migration to XML.
      ******************************************************************
       select xml-customer-file assign to "customers.xml"
                                organization is xml
                                document-type is "customer.xsd"
                                file status is file-status-spec.

      ******************************************************************
      *File definition for the existing customer database
      ******************************************************************
       fd customer-file.
       copy "customer.cpy".

      ******************************************************************
      *File definition for the new XML customer database.  Note the
      *usage of "xd" to denote an XML format.
      ******************************************************************
       xd xml-customer-file.
       copy "customer-xml-migrate.cpy".


       working-storage section.
      *XML File status
       01 file-status-spec pic S9(9).


       procedure division.
      *Open the customer file
           open input customer-file

      *Open the XML file (the migration target).
           open output xml-customer-file

      *Migrate the legacy COBOL customer file to the new XML customer
      *file.
           perform migrate-to-xml

      *Close the legacy COBOL file and the XML file
           close customer-file
           close xml-customer-file

      *Exit the program
           exit program
           stop run.

      ******************************************************************
      *Perform migration from the legacy COBOL file to the new XML file.
      *****************************************************************
       migrate-to-xml section.
           perform until exit
      *Read a record from the customer file
               read customer-file next record into customer-record
                   at end
                       exit perform
                   not at end
      *If a record has been successfully input, move it to the XML
      *record and write it to the XML file
                       move customer-record to xml-customer-record
                       write xml-customerdb key is 
                          all xml-customer-record
               end-read
           end-perform
           write xml-customerdb
           exit section.

