home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Languages / MS Cobol4.5 / DEMO / NESTED.CBL < prev    next >
Encoding:
Text File  |  1991-04-08  |  3.0 KB  |  70 lines

  1.       $set ans85 nestcall noosvs mf
  2.       *******************************************************************
  3.       *                                                                 *
  4.       *                                                                 *
  5.       *                  (C) Micro Focus Ltd. 1989                      *
  6.       *                                                                 *
  7.       *                         NESTED.CBL                              *
  8.       *                                                                 *
  9.       *  This demo shows how to structure a nested COBOL program.       *
  10.       *  There are two nested programs NEST1 and NEST2 each of which    *
  11.       *  have their own local data. It also demonstrates a simple use   *
  12.       *  of GLOBAL data.                                                *
  13.       *                                                                 *
  14.       *******************************************************************
  15.        identification division.
  16.        program-id.   main.
  17.        working-storage section.
  18.        01 counter is global            pic 9999.
  19.        01 local-item                   pic x(20) value all 'a'.
  20.  
  21.        procedure division.
  22.            move 1 to counter.
  23.            display 'in main program, '.
  24.            display '            value of global counter = ', counter.
  25.            display '            value of ''local-item'' = ', local-item.
  26.            display 'calling nest1'.
  27.            display ' '.
  28.  
  29.            call 'nest1'.
  30.            display 'back in main program, '.
  31.            display '            value of global counter = ', counter.
  32.            display '            value of ''local-item'' = ', local-item.
  33.            display ' '.
  34.  
  35.            display 'calling nest2, '.
  36.            call 'nest2'.
  37.            display 'back in main program, '.
  38.            display '            value of global counter = ', counter.
  39.            display '            value of ''local-item'' = ', local-item.
  40.            display ' '.
  41.            stop run.
  42.  
  43.       * Here is the first nested program.
  44.       * Nested programs can access any GLOBAL data and have their own
  45.       * local data.
  46.        identification division.
  47.        program-id.   nest1.
  48.        working-storage section.
  49.        01 local-item                   pic x(20) value all 'b'.
  50.        procedure division.
  51.            add 1 to counter.
  52.            display 'in nest1,   adding one to counter '.
  53.            display '            value of ''local-item'' = ', local-item.
  54.            display ' '.
  55.        end program nest1.
  56.  
  57.       * here is the second nested program
  58.        identification division.
  59.        program-id.   nest2.
  60.        working-storage section.
  61.        01 local-item                   pic x(20) value all 'c'.
  62.        procedure division.
  63.            add 1 to counter.
  64.            display 'in nest2,   adding one to counter '.
  65.            display '            value of ''local-item'' = ', local-item.
  66.            display ' '.
  67.        end program nest2.
  68.  
  69.        end program main.
  70.