|ORBiT Sponsor Message|
Trivia and Gotchas
By Shawn M. Gordon
I thought I would go through a little COBOL trivia this month, as well as point out a couple of potential gotchas with some of the newer COBOL features.
First the trivia. I have been asking people for years if they could remember what the 66-level item was used for, and in the last 10 years, no one has been able to tell me, off of the top of their head. I remembered reading about it in school many moons ago, but never could find it in the manual again for some reason. Maybe I didnt try very hard.
So far Ive never had an occasion to use it, but who knows? My mission statement is to help educate, and you never know what someone might find useful. So to quote from the short piece of documentation that I found on the topic:
66 data-name-1 RENAMES data-name-2 [THRU data-name-3]
The RENAMES clause is used to give an alternative name to one or more consecutive data fields.
When this clause is used data-name-2 (THRU to data-name-3) are given the name data-name-1. These areas of data may be referred to as the renamed version or as the original data names.
One or more RENAMES clause may be associated with any logical record, and must follow that records?s last data description entry.
A level 66 RENAMES entry may not rename a level 01, level 77, level 88 or another level 66 entry.
The OCCURS clause may not be associated with the renamed items.
01 REC-1. 03 FLD-1 PIC 99. 03 FLD-2 PIC 9(3)V99. 03 FLD-3 PIC X. 66 NME-X RENAMES FLD-1 THRU FLD-2. 01 REC-B. 03 GRP-1. 05 FLD-7 PIC 99. 05 FLD8 PIC XX. 03 FLD-9 PIC X(7). 03 FLD-10 PIC X(4). 66 NME-Y RENAMES FLD-8 THRU FLD-10.
It would seem the ability to address byte ranges within a variable that was introduced in COBOL 85 would make this feature a little less useful. It is kind of cool that you can just chunk off a section of another record structure with a name, then refer to it later. This would probably be a bit more self-explanatory than using byte referencing, especially if you are consistently going after the same number of bytes.
There was some recent discussion on the HP3000-L newsgroup about the COBOL financial functions that were introduced in the 89 COBOL addendum. There is a function that will sum an entire table, as follows:
01 YTD-SALES. 03 MONTH-TABLE OCCURS 12 TIMES 05 MTD-SALES PIC S9(7)V99 COMP. COMPUTE TOTAL-YTD-SALES = FUNCTION SUM(MTD-SALES(ALL)).
This statement wont be as precise as you want, because the internal representation during the calculation is floating point, and the conversion back and forth from fixed to floating will lose some precision. The answer is to use the ROUNDED verb in the compute, as in:
COMPUTE TOTAL-YTD-SALES ROUNDED = FUNCTION
This can still potentially lead to some imprecision, but it is much more accurate than not using ROUNDED. As a side note, this problem can also crop up for the NUMVAL function.
The whole chapter on the new COBOL FUNCTIONS is very interesting, and you will probably find a number of very useful items in there. Some functions I use more often than others, but there is a wealth of financial functions, and computational functions. I will devote a column in the future on some of the more interesting ones and how to use them.
As always, I welcome your input to this column. Earn yourself a free 3000 Always Online hat for tips you submit, either to the NewsWire or to me at email@example.com.
Shawn Gordon, whose S.M. Gordon & Associates firm
supplies HP 3000 utilities, has worked with 3000s since 1983.
Copyright The 3000 NewsWire. All rights reserved.