      $set ans85
      ******************* IDENTIFICATION DIVISION *********************
       identification division.
       program-id. customer.

      ******************* ENVIRONMENT DIVISION ************************
       environment division.

      *---------------------------------------------------------------*
       input-output section.
       file-control.
           select customer-file assign "cust.ism"
           organization is indexed
           record key is file-c-code
           access is dynamic
           lock mode manual.

      ******************* DATA DIVISION *******************************
       data division.

      *---------------------------------------------------------------*
       file section.
       fd  customer-file.
       01  customer-record.
           03  file-c-code             pic x(5).
           03  file-c-name             pic x(15).
           03  file-c-addr1            pic x(15).
           03  file-c-addr2            pic x(15).
           03  file-c-addr3            pic x(15).
           03  file-c-addr4            pic x(15).
           03  file-c-limit            pic 9(4) comp.
           03  file-c-area             pic x.
           03  file-c-order.
             78  no-of-orders              value 10.
               05  file-c-order-entry occurs no-of-orders.
                   07  file-ord-no     pic 9(6).
                   07  file-ord-date   pic 9(6).
                   07  file-ord-val    pic 9(4)v99 comp.
                   07  file-pay-val    pic 9(4)v99 comp.

      *---------------------------------------------------------------*
       working-storage section.

           copy "DS-CNTRL.MF".
           copy "CUSTOMER.CPB".

       78  refresh-text-and-data-proc      value 255.
       78  dialog-system                   value "DSRUN".

       77  array-ind                   pic 9(4) comp.
       77  display-error-no            PIC 9(4).

      ******************* PROCEDURE DIVISION **************************
       procedure division.
      *---------------------------------------------------------------*
       controlling section.
           perform program-initialize
           perform program-body until CUSTOMER-EXIT-FLG-TRUE
           perform program-terminate.
      *---------------------------------------------------------------*
       program-initialize section.
           initialize DS-CONTROL-BLOCK
           initialize CUSTOMER-DATA-BLOCK
           move CUSTOMER-DATA-BLOCK-VERSION-NO to
                                         DS-DATA-BLOCK-VERSION-NO
           move CUSTOMER-VERSION-NO to DS-VERSION-NO
           open i-o customer-file
           perform load-screenset.
      *---------------------------------------------------------------*
       program-body section.
           if DS-EXIT-FIELD-TRUE
               perform derivations
               perform set-up-for-refresh-screen
           end-if
           evaluate true
               when CUSTOMER-DEL-FLG-TRUE
                   perform delete-record
               when CUSTOMER-LOAD-FLG-TRUE
                   perform load-record
               when CUSTOMER-SAVE-FLG-TRUE
                   perform save-record
               when CUSTOMER-CLR-FLG-TRUE
                   perform clear-record
           end-evaluate
           perform clear-flags
           perform call-dialog-system.
      *---------------------------------------------------------------*
       program-terminate section.
           close customer-file
           stop run.
      *--------------------------------------------------------------*
       delete-record section.
           move CUSTOMER-C-CODE to file-c-code
           delete customer-file
           perform clear-record.
      *---------------------------------------------------------------*
       load-record section.
           initialize customer-record
           move CUSTOMER-C-CODE to file-c-code
           if file-c-code not = spaces
               read customer-file
                   invalid key
                       initialize CUSTOMER-DATA-BLOCK
                       move file-c-code to CUSTOMER-C-CODE
                   not invalid key
                       perform fill-screen-from-record
                       perform derivations
               end-read
           else
               initialize CUSTOMER-DATA-BLOCK
           end-if
           perform set-up-for-refresh-screen.
      *---------------------------------------------------------------*
       save-record section.
           perform fill-record-from-screen
           rewrite customer-record
               invalid key
                   write customer-record
               end-write
           end-rewrite.
      *---------------------------------------------------------------*
       clear-flags section.
           initialize CUSTOMER-GROUP-002.
      *---------------------------------------------------------------*
       clear-record section.
           initialize customer-record
           initialize CUSTOMER-DATA-BLOCK
           perform set-up-for-refresh-screen.
      *---------------------------------------------------------------*
       fill-record-from-screen section.
           move CUSTOMER-C-CODE to file-c-code
           move CUSTOMER-C-NAME to file-c-name
           move CUSTOMER-C-ADDR1 to file-c-addr1
           move CUSTOMER-C-ADDR2 to file-c-addr2
           move CUSTOMER-C-ADDR3 to file-c-addr3
           move CUSTOMER-C-ADDR4 to file-c-addr4
           move CUSTOMER-C-LIMIT to file-c-limit
           move CUSTOMER-C-AREA to file-c-area
           perform varying array-ind from 1 by 1
                                          until array-ind > no-of-orders
               move CUSTOMER-ORD-NO(array-ind) to file-ord-no(array-ind)
               move CUSTOMER-ORD-DATE(array-ind) to
                                           file-ord-date(array-ind)
               move CUSTOMER-ORD-VAL(array-ind) to
                                           file-ord-val(array-ind)
               move CUSTOMER-PAY-VAL(array-ind) to
                                           file-pay-val(array-ind)
           end-perform.
      *---------------------------------------------------------------*
       fill-screen-from-record section.
           move file-c-code  to CUSTOMER-C-CODE
           move file-c-name  to CUSTOMER-C-NAME
           move file-c-addr1 to CUSTOMER-C-ADDR1
           move file-c-addr2 to CUSTOMER-C-ADDR2
           move file-c-addr3 to CUSTOMER-C-ADDR3
           move file-c-addr4 to CUSTOMER-C-ADDR4
           move file-c-limit to CUSTOMER-C-LIMIT
           move file-c-area  to CUSTOMER-C-AREA
           perform varying array-ind from 1 by 1
                                          until array-ind > no-of-orders
               move file-ord-no(array-ind) to CUSTOMER-ORD-NO(array-ind)
               move file-ord-date(array-ind) to
                                           CUSTOMER-ORD-DATE(array-ind)
               move file-ord-val(array-ind) to
                                           CUSTOMER-ORD-VAL(array-ind)
               move file-pay-val(array-ind) to
                                           CUSTOMER-PAY-VAL(array-ind)
           end-perform.
      *---------------------------------------------------------------*
       set-up-for-refresh-screen section.
           move refresh-text-and-data-proc to DS-PROC-NO.
      *---------------------------------------------------------------*
       derivations section.
           move 0 to CUSTOMER-C-BAL
           perform varying array-ind
                              from 1 by 1 until array-ind > no-of-orders
               compute CUSTOMER-ORD-BAL(array-ind) =
                     CUSTOMER-ORD-VAL(array-ind) -
                                           CUSTOMER-PAY-VAL(array-ind)
               add CUSTOMER-ORD-BAL(array-ind) to CUSTOMER-C-BAL
           end-perform.
      *---------------------------------------------------------------*
       load-screenset section.
           move DS-NEW-SET to DS-CONTROL
           move "CUSTOMER" to DS-SET-NAME
           perform call-dialog-system.
      *---------------------------------------------------------------*
       call-dialog-system section.
           call dialog-system using DS-CONTROL-BLOCK,
                                    CUSTOMER-DATA-BLOCK
           if not DS-NO-ERROR
               move DS-SYSTEM-ERROR-NO to display-error-no
               display "DS ERROR NO:   " display-error-no
               perform program-terminate
           end-if.
      ******************* END OF PROGRAM ******************************
