| Arnold Trembley 2007-09-10, 7:55 am |
| Pete Dashwood wrote:
> "Richard" <riplin@Azonic.co.nz> wrote in message
> news:1189376682.979533.132800@o80g2000hse.googlegroups.com...
>
> Not just a MicroFocus extension. Fujitsu NetCOBOL also implements TYPEDEF.
> (Maybe others do too?) I think Robert's ignorance of the standard can be
> forgiven in this instance; most programmers assume that what is in the
> manual they use daily, is in the COBOL standard, and really don't care
> whether it is or not.
>
> (I have never met a programmer on a COBOL shop floor who was concerned with
> what the COBOL standard mandated. They are concerned with their local
> programming standards (and getting code past peer review). They are further
> concerned with what their particular implementation supports; if it's in the
> manual and doesn't violate local standards, it's OK to use. I have not
> encountered anyone anywhere who is concerned about the fact that they might
> be using "Non-Standard" extensions to the COBOL language, provided by their
> vendor. In fact, the majority would consider it is part of their competitive
> advantage, by going with that vendor, to use extensions provided. The days
> when the possibility that the COBOL might be ported, and standard COBOL was
> therefore viewed as a Good Thing, are long gone. They disappeared about the
> same time the standards committee lost all credibility by taking 17 years to
> produce a standard revision.)
>
> It is a pity that the 2002 standard, which is actually trying to do some
> useful things with the language, has inherited this legacy. I guess you
> could say: "Too little, too late..."
>
>
> While it may not be standard COBOL, it is certainly an "interesting"
> construct.
>
> For the benefit of many who may be wondering what this is all about, here is
> a small sample program (reproduced from Fujitsu docs, which are publicly
> downloadable) that explains the concept very well, in my opinion.
>
> 000010 @OPTIONS MAIN
> 000020*----------------------------------------------------------------------
> 000030* The TYPEDEF clause can define an arbitrary data type.
> 000040* The defined data type can be referenced by the TYPE clause.
> 000050*
> 000060* This sample uses a date type to measure the execution performance of
> 000065* the ADD statement.
> 000070*----------------------------------------------------------------------
> 000080 IDENTIFICATION DIVISION.
> 000090 PROGRAM-ID. SAMPLE.
> 000100 DATA DIVISION.
> 000110 WORKING-STORAGE SECTION.
> 000120*----------------------------------------------------------------------
> 000130* The TYPEDEF clause is used to define the date type (DATE-EDITED).
> 000140*----------------------------------------------------------------------
> 000150 01 DATE-EDITED TYPEDEF.
> 000160 02 YEARS PIC 9(4).
> 000170 02 PIC X(1) VALUE "/".
> 000180 02 MONTHS PIC 9(2).
> 000190 02 PIC X(1) VALUE "/".
> 000200 02 DAYS PIC 9(2).
> 000210 02 PIC X(1) VALUE " ".
> 000220 02 HOURS PIC 9(2).
> 000230 02 PIC X(1) VALUE ":".
> 000240 02 MINUTES PIC 9(2).
> 000250 02 PIC X(1) VALUE ":".
> 000260 02 SECONDS PIC 9(2).
> 000270 02 PIC X(1) VALUE ".".
> 000280 02 M-SECS PIC 9(2).
> 000290*----------------------------------------------------------------------
> 000300* The date type defined above can be used by specifying the TYPE
> 000305* clause.
> 000310*----------------------------------------------------------------------
> 000320 01 STARTED TYPE DATE-EDITED.
> 000330 01 ENDED TYPE DATE-EDITED.
> 000340*----------------------------------------------------------------------
> 000350 01 WK-DATE.
> 000360 02 YEARS PIC 9(4).
> 000370 02 MONTHS PIC 9(2).
> 000380 02 DAYS PIC 9(2).
> 000390 02 HOURS PIC 9(2).
> 000400 02 MINUTES PIC 9(2).
> 000410 02 SECONDS PIC 9(2).
> 000420 02 M-SECS PIC 9(2).
> 000430 01 COUNTER PIC S9(8) VALUE 0.
> 000440 PROCEDURE DIVISION.
> 000450 MOVE FUNCTION CURRENT-DATE TO WK-DATE.
> 000460 MOVE CORR WK-DATE TO STARTED.
> 000470 DISPLAY "STARTED-TIME IS " STARTED.
> 000480**
> 000490 PERFORM 1000000 TIMES
> 000500 ADD 1 TO COUNTER
> 000510 END-PERFORM.
> 000520**
> 000530 MOVE FUNCTION CURRENT-DATE TO WK-DATE.
> 000540 MOVE CORR WK-DATE TO ENDED.
> 000550 DISPLAY "ENDED-TIME IS " ENDED.
> 000560 EXIT PROGRAM.
> 000570 END PROGRAM SAMPLE.
>
>
> Pete.
Perhaps I am missing something here about the benefits of typedef in
COBOL (or perhaps I don't understand typedefs at all).
As far as I can tell, it appears the only advantage to using typedef
is that it creates invisible variables under the group names STARTED
and ENDED with predictable non-unique names, in order to save two
lines of code in the procedure division that would read "MOVE
EDITED-DATE TO STARTED" and "MOVE EDITED-DATE TO ENDED". And to get
this advantage I would have to use qualification and MOVE
CORRESPONDING, which is strongly discouraged by my shop standards.
If I wanted to simulate typedefs or use them directly, I'm not sure I
would want to put each one in a copybook by itself. Surely in this
day and age we are not that short of WORKING-STORAGE memory.
With kindest regards,
--
http://arnold.trembley.home.att.net/
|