This code, developed to run under TSO/E REXX, was designed as to demonstrate commercial arithmetic. A number of records are read, an amount is aggregated, VAT is calculated, and a total amount due is derived.
/* ---- REXX Routine to calculate VAT and balance due. ---- */ Drop name. /* Clear STEM variable first */ names = " "; balance = 0; amount = 0; /* Initialise other variables */ /* ---- Phase 1 read all the input data ---- */ "ALLOC DA(cobol.cntl(demo3d)) F(ut1) SHR" /* Assign input file */ "EXECIO * DISKR UT1 (FINIS STEM name." /* Read all the amounts */ /* ---- Phase 2 aggregate all the input amounts ---- */ Do n = 0 + 1 Until n > (name.0 - 1) Parse Var name.n . amount . /* Isolate actual amount */ amount = STRIP(amount,B) /* Ensure numeric only. */ balance = (balance + amount) End; /* ---- Phase 3 perform additional calculations, report, and quit */ vat = ((balance/100)*17.5) /* Calculate the VAT. */ due = balance + vat; Say "Total is $"||balance||" Plus VAT at 17.5% $"||, vat||" Final Amount is $"||due; "FREE F(ut1)" /* De-allocate the file */ Exit 0 /* leave program */
In the above example the FREE statement de-allocates the file, and arguably would be better placed immediately after the EXECIO statement. Another alternative would be to place the FREE on the Data Stack so that it is executed irrespective of whether the routine ends normally or abnormally. For more information on this click here.
Copyright © KMS-IT Limited 2002