Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Defensive Programming

1 view
Skip to first unread message

WOB

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
In article <199808040122...@ladder03.news.aol.com>,
mark0...@aol.com (Mark0Young) wrote:
> In article <6q4fr4$aeh$1...@juliana.sprynet.com>, "WOB"
<wobco...@sprynet.com>
> writes:
>
> > COMPUTE WS-MAX-SUB = (LENGTH OF WS-TABLE-REC /
> > LENGTH OF WS-TABLE (1)).
> >
> > If the OCCURS ever changes, the calculated MAX-SUB will always be
> >correct.
>
> I like it! Unfortunately, most of our COBOL code is still '74 (FCOBOL), so
we
> code the upper limit right above the OCCURS clause.

> But I really do like your COMPUTE and using LENGTH OF to plug in the
correct
> table limit without requiring that the number of occurrences having to be
> updated in two places, and I will be adding that code if I get involved in
our
> conversion from DOS/VS COBOL (FCOBOL) to COBOL/VSE (IGYCRCTL).
>
> Do you have a feel for LENGTH OF name vs. FUNCTION LENGTH(name)? I'm more
> inclined towards FUNCTION LENGTH(name) because that is standard COBOL
(optional
> intrinsic functions), whereas LENGTH OF is an IBM extension, no?
>
> Mark A. Young
>

Mark,

In the COBOL/370 Book that I have, I've not seen any severe restrictions
using the LENGTH Intrinsic Function, including usage with a table element. I
would imagine then maybe one of our esteemed colleagues could test out this
theory in their own COBOL environment. Here's the example everyone:

03 WS-MAX-SUB PIC S9(09) BINARY.
03 WS-TABLE-REC.
05 WS-TABLE OCCURS 100 TIMES.
07 WS-TABLE-ELEMENT-01 PIC X(10).
07 WS-TABLE-ELEMENT-02 PIC X(20).
07 WS-TABLE-ELEMENT-03 PIC X(30).

COMPUTE WS-MAX-SUB = (FUNCTION LENGTH (WS-TABLE-REC) /
FUNCTION LENGTH (WS-TABLE (1))).

Under the IBM umbrella, intrinsic functions are supported in COBOL/370,
COBOL/MVS, COBOL/VSE and COBOL/390 but not COBOL2.

Some other usage's are with Reference Modification and INSPECT.

HTH....

Cheers,

WOB,
Atlanta


Leif Svalgaard

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to

>03 WS-MAX-SUB PIC S9(09) BINARY.
>03 WS-TABLE-REC.
> 05 WS-TABLE OCCURS 100 TIMES.
> 07 WS-TABLE-ELEMENT-01 PIC X(10).
> 07 WS-TABLE-ELEMENT-02 PIC X(20).
> 07 WS-TABLE-ELEMENT-03 PIC X(30).
>
>COMPUTE WS-MAX-SUB = (FUNCTION LENGTH (WS-TABLE-REC) /
> FUNCTION LENGTH (WS-TABLE
(1))).
>


This will only work if there are no COMP or BINARY items on machines
where such items must be on specific boundaries.

Try to change ELEMENT-01's picture to PIC X(11) and -02's to PIC S9(4) COMP.
The compilers insert slack bytes to align binary stuff on (say) word
boundaries.
This makes the size of WS-TABLE-REC too large,

A pity though, because it was really neat.


Leif Svalgaard

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
sorry,
I was sleeping.
This WILL work.
It is very NEAT. Thank you for this wonderful mechanism.
Truly remarkable.

(Donald, sorry about the poor SAPM ratio here)

Leif Svalgaard wrote in message <35c7c...@news1.ibm.net>...

Ken Foskey

unread,
Aug 5, 1998, 3:00:00 AM8/5/98
to
WOB wrote:
>
>
> COMPUTE WS-MAX-SUB = (FUNCTION LENGTH (WS-TABLE-REC) /
> FUNCTION LENGTH (WS-TABLE (1))).
>


Now I remember: the FUNCTION can only be used in COMPUTE the other one
can be used anwhere. This is an MVS 'extension' and they will be
correcting the 'documentation' shortly.

If only I could fix my bugs so easily :-)

Ken


William M. Klein

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to

WOB wrote in message <6q8cq4$s49$1...@juliana.sprynet.com>...

<much snippage>


>
> In the COBOL/370 Book that I have, I've not seen any severe
restrictions
>using the LENGTH Intrinsic Function, including usage with a table element.

<more snippage>

Just as a side comment - that not MANY of you may need to worry about yet.

There are some well-defined rules for both the LENGTH OF special register
and the LENGTH intrinsic function about how to handle items/groups with DBCS
items included. I don't have my manuals handy - but I do know that J4 and
WG4 worked quite a bit on this issue for the next Standard. The problem
being (obviously?) do you want the number of character positions or do you
want the number of bytes? J4 was able to come with some examples of each.


William M. Klein

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to

Ken Foskey wrote in message <35C86145...@zip.com.au>...

FYI - in the next Standard (and in some compilers - for example Micro Focus)
this rule is changed so that a numeric (or integer) function CAN be used
anywhere that a numeric item can be used as a sending item.


COBOL Frog (Huib Klink)

unread,
Aug 6, 1998, 3:00:00 AM8/6/98
to
Ken Foskey wrote:

> WOB wrote:
> >
> >
> > COMPUTE WS-MAX-SUB = (FUNCTION LENGTH (WS-TABLE-REC) /
> > FUNCTION LENGTH (WS-TABLE (1))).
> >
>
> Now I remember: the FUNCTION can only be used in COMPUTE the other one
> can be used anwhere.

No, for exampleDIVIDE FUNCTION LENGTH (WS-TABLE-REC)
BY FUNCTION LENGTH (WS-TABLE (1))
GIVING WS-MAX-SUB
will work too.

> This is an MVS 'extension' and they will be
> correcting the 'documentation' shortly.

FUNCTION is not an MVS extension. It is a regular part of the COBOL standard now,
added in1989 to the 1985 standard.

The COBOL Frog

--
Dut: Vandaag is de eerste dag van de rest van je leven! Maak er wat van!
Eng: Today is de first day of the rest of your life! Use it!


0 new messages