Re: PIC P put to real use
- From: "Chuck Stevens" <charles.stevens@xxxxxxxxxx>
- Date: Fri, 26 May 2006 09:42:12 -0700
"Pete Dashwood" <dashwood@xxxxxxxxxxxxxx> wrote in message
news:4dojm7F1bt62kU1@xxxxxxxxxxxxxxxxx
"Chuck Stevens" <charles.stevens@xxxxxxxxxx> wrote in message
news:e52fu5$1cm9$1@xxxxxxxxxxxxxxxxxxxxxxx
One justification for NOT allowing colons in PICTURE character-strings
has for some time been that you could code
05 AUTH-TIME PIC 99/99PP.
and
INSPECT AUTH-TIME REPLACING ALL "/" BY ":".
to accomplish this.
Personally, I think this is a little more obvious than the reference
modification approach.
I don't.
I think it is appalling. Why would I use an INSPECT when I can use a MOVE?
People who say refmodding is difficult are usually the same people who ban
PERFORM...VARYING and negated or compound conditions... :-)
I don't mind PERFORM...VARYING, I don't mind negated or compound conditions,
and I don't mind reference modification.
The reason I prefer INSPECT to a reference-modified MOVE in this instance is
that the former is not dependent on the exact placement of the character in
the PICTURE (or, for that matter, on whether or not there is more than one
of them in the PICTURE), and the reference modified MOVE is.
Suppose, for example, Management decided they wanted Auth-Time recorded to
the second instead of merely to the minute as it appears now. Part of a
reasonable approach might be to change the declaration to
05 AUTH-TIME PIC 99B99B99.
This would necessitate NO change to the INSPECT, whereas an additional MOVE
would be required. (Actually, I prefer to use "/" in both the PICTURE and
the INSPECT in such a case, because it's clearer in both locations what's
being replaced)
COBOL is not intended to be written by simpletons using a crayon and
non-joined-up writing; it is a programming language.
I'm not sure why that makes a MOVE (or two MOVEs) that blindly insert(s)
characters into certain locations of some data item declared elsewhere a
neater, better, clearer solution than a single INSPECT that identifies the
characters being replaced as well as the replacement text! I think the
days of "the more obscure and terse my code, the more likely management is
going to think I'm a genius" have passed us by! I grant that it's very
likely a single reference-modified MOVE will be more efficient at run time
than the INSPECT, but I wouldn't guarantee that being the case with multiple
MOVEs.
It is reasonable to assume that people using it understand something about
programming.
And ... ?
I strongly oppose dragging style down to the lowest common denominator so
that "the guy dragged out of bed at 3 am" doesn't have to scratch his
head.
And ... ?
If he was competent he wouldn't be scratching his head. If he is
scratching his head why did we drag HIM out of bed to make an urgent fix
under pressure...? Why employ him at all? Get trained or get out. If you
can't handle refmodding you might be happier selling burgers...or running
for Government.
And ... ?
Maybe this is why so many COBOL 'programmers' have difficulty moving to
other languages where you can't just write what you think in English.
Programming is a skill and it needs to be learned.
Is this turning into a rant? All this over the suggestion that the intent
of a particular INSPECT might be a little easier to figure out *quickly*
than the intent of a reference-modified MOVE?
The language is simple and clear enough.
I have never seen a COBOL program yet that I couldn't fix. Even badly
written ones. Or well written ones that use 'complex' features like those
described...
Complex is in the eye of a beholder.
I like Frank's PP use and it is only the second time in 40 years that I
have seen it used in anger.
I have no objection to the PP use, nor did I raise one. I was talking about
the replacement of characters in a numeric-edited data item once its numeric
value has been established.
My opinion is that it is far more likely that the reference-modified MOVE
will be the source of a future bug if the format of the destination data
item is changed than if an INSPECT were used to accomplish the same thing.
As for insertion characters, the best solution by far is the one Richard
mentioned where the Character 'I' can be used to insert anything you like.
(Great machine, that 1900... :-))
I agree; that's why I implemented it that way.
I used to use the following, which doesn't require refmodding or
INSPECT...(Only because I started using it before refmodding was
invented...)
01 AUTH-INFO.
05 AUTH-AMT PIC ZZZ,ZZ9.99.
05 PIC X VALUE SPACE.
05 timeSpot.
15 tsHours pic 99.
15 colon1 pic x.
15 tsMinutes pic 99.
15 colon2 pic x.
15 tsSeconds pic 99.
05 AUTH-TIME PIC xxBxxBxx redefines timeSpot.
* MY-AMOUNT is 123.45
* TIME-HHMMSS is 124559
MOVE MY-AMOUNT TO AUTH-AMT
MOVE TIME-HHMMSS TO AUTH-TIME
MOVE ':' TO colon1 colon2
DISPLAY AUTH-INFO
I actually like that better than the reference modification. I think it's
clearer code. In your example you don't have to look back at the
declaration of AUTH-TIME to have an idea what's intended. With the
Reference Modification MOVE, you do.
But I like Frank's better, assuming you are offended by centiseconds...:-)
Better still, maintain your times in Standard Numeric Time Form and use the
ISO 8601 time/date functions to format them! ;-)
-Chuck Stevens
.
- Follow-Ups:
- Re: PIC P put to real use
- From: Pete Dashwood
- Re: PIC P put to real use
- From: Chuck Stevens
- Re: PIC P put to real use
- References:
- PIC P put to real use
- From: Frank Swarbrick
- Re: PIC P put to real use
- From: Howard Brazee
- Re: PIC P put to real use
- From: Chuck Stevens
- Re: PIC P put to real use
- From: Pete Dashwood
- PIC P put to real use
- Prev by Date: Re: Long numbers programming
- Next by Date: Re: If all the CoBOL people updating the language...
- Previous by thread: Re: PIC P put to real use
- Next by thread: Re: PIC P put to real use
- Index(es):
Relevant Pages
|