Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program-id. Program1 as "TABLES.Program1".
- environment division.
- input-output section.
- file-control. Select inin assign to "C:\Users\Bogin\Desktop\WORKS\COBOL\FILES\Table_IN.txt" organization is line sequential.
- Select outout assign to "C:\Users\Bogin\Desktop\WORKS\COBOL\FILES\Table_OUT.txt".
- data division.
- file section.
- fd inin.
- 01 inF.
- 05 shipName pic x(20).
- 05 product pic x(10).
- 05 units pic 99999.
- 05 country pic x(15).
- fd outout.
- 01 outF.
- 05 pic xxxxx.
- 05 shipNameOut pic x(20).
- 05 pic xxxxx.
- 05 productOut pic x(10).
- 05 pic xxxxx.
- 05 unitsOut pic zzzz9.
- 05 pic xxxxx.
- 05 totalUnits pic zzzzzz9.99.
- 05 pic xxxxx.
- 05 countryOut pic x(15).
- 05 pic x(25).
- working-storage section.
- 01 tableOne.
- 05 elementsPrice pic x(96)
- value "Butane 0040Copper 0075Iron Ore1050Oil 2123Rubber 1080Sugar 0815Timber 0046Wheat 0240".
- 05 tableA redefines elementsPrice.
- 10 elementsDivided occurs 8 times indexed by ind.
- 15 eleName pic x(8).
- 15 elePrice pic 99v99.
- 01 loopf value "n".
- 01 tempCalcValue pic 99999999.99.
- procedure division.
- 100Main.
- open input inin
- open output outout
- perform until loopf = "y"
- read inin
- at end
- move "y" to loopf
- not at end
- perform 200Search
- perform 300Write
- end-read
- end-perform
- close inin
- close outout
- stop run.
- 200Search.
- set ind to 1
- search elementsDivided
- at end
- move 0 to tempCalcValue
- when eleName(ind) = product
- multiply elePrice(ind) by units giving tempCalcValue
- end-search.
- 300Write.
- move spaces to outF
- move shipName to shipNameOut
- move product to productOut
- move units to unitsOut
- move tempCalcValue to totalUnits
- move country to countryOut
- write outF
- after advancing 1 line.
- end program Program1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement