Advertisement
Guest User

Untitled

a guest
Nov 1st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
COBOL 2.14 KB | None | 0 0
  1.        program-id. Program1 as "TABLES.Program1".
  2.  
  3.        environment division.
  4.        input-output section.
  5.        file-control. Select inin assign to "C:\Users\Bogin\Desktop\WORKS\COBOL\FILES\Table_IN.txt" organization is line sequential.
  6.                        Select outout assign to "C:\Users\Bogin\Desktop\WORKS\COBOL\FILES\Table_OUT.txt".
  7.  
  8.        data division.
  9.        file section.
  10.        fd inin.
  11.        01 inF.
  12.           05 shipName pic x(20).
  13.           05 product pic x(10).
  14.           05  units pic 99999.
  15.           05 country pic x(15).
  16.  
  17.        fd outout.
  18.        01 outF.
  19.            05    pic xxxxx.
  20.            05 shipNameOut pic x(20).
  21.            05    pic xxxxx.
  22.           05 productOut pic x(10).
  23.           05    pic xxxxx.
  24.           05  unitsOut pic zzzz9.
  25.           05    pic xxxxx.
  26.          05 totalUnits pic zzzzzz9.99.
  27.         05    pic xxxxx.
  28.           05 countryOut pic x(15).
  29.          05    pic x(25).
  30.  
  31.        working-storage section.
  32.  
  33.        01 tableOne.
  34.            05 elementsPrice pic x(96)
  35.                value "Butane  0040Copper  0075Iron Ore1050Oil     2123Rubber  1080Sugar   0815Timber  0046Wheat   0240".
  36.            05 tableA redefines elementsPrice.
  37.                10 elementsDivided occurs 8 times indexed by ind.
  38.                    15 eleName pic x(8).
  39.                    15 elePrice pic 99v99.
  40.  
  41.        
  42.        01 loopf value "n".
  43.      
  44.        01 tempCalcValue pic 99999999.99.
  45.  
  46.        procedure division.
  47.            100Main.
  48.            open input inin
  49.            open output outout
  50.  
  51.            perform until loopf = "y"
  52.                read inin
  53.  
  54.                at end
  55.                    move "y" to loopf
  56.  
  57.                    not at end
  58.                        perform 200Search
  59.                        perform 300Write
  60.                        
  61.            end-read
  62.            end-perform
  63.            
  64.            close inin
  65.            close outout
  66.  
  67.  
  68.            stop run.
  69.  
  70.        200Search.
  71.          set ind to 1
  72.            search elementsDivided
  73.                 at end
  74.                    move 0 to tempCalcValue
  75.                when eleName(ind) = product
  76.                multiply elePrice(ind) by units giving tempCalcValue
  77.  
  78.            end-search.
  79.  
  80.  
  81.        300Write.
  82.            move spaces to outF
  83.            move shipName to shipNameOut
  84.            move product to productOut
  85.            move units to unitsOut
  86.            move tempCalcValue to totalUnits
  87.            move country to countryOut
  88.            write outF
  89.            after advancing 1 line.
  90.  
  91.        end program Program1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement