From: Frank Swarbrick on
I've wondered this for a long time... Why is there a restriction that an
OCCURS clause cannot occur at level 01 or 77? For instance, why not

01 TRANS-MORE-CNT OCCURS 4
PIC S9(7) COMP-3 VALUE ZERO.

Or even

77 TRANS-MORE-CNT OCCURS 4
PIC S9(7) COMP-3 VALUE ZERO.

Rather than something silly like...

01.
05 TRANS-MORE-CNT OCCURS 4
PIC S9(7) COMP-3 VALUE ZERO.

It's always bugged me.

Frank

From: William M. Klein on
You are talking about Standard COBOL. There are implementations (Micro Focus
for example) that allow this as an extension.

The restriction (as I think I have been told - I wasn't there when it was added)
is that some statements require that an operand be a "data-name" instead of an
"identifier". At least up to the '85 Standard (and somewhat in there) one major
distinction between a "data-name" and an "identifier" in a syntax diagram was
the ability to subscript it.

Consider (abbreviated - I haven't checked, but I think this was one of the
"problem" cases):

FD File-1.
01 Rec-Table occurs 10 times.
....

Write Rec-Tabl.

The Standard doesn't allow one to user "Rec-Table without a subscript - but
write doesn't let you use a subscript.

Those that have such an extension come up with rules to handle "hard cases" but
given the "ease" of putting a group-item at the 01-level, J4 (and WG4) have
rejected adding this every time the "suggestion" has come up.

--
Bill Klein
wmklein <at> ix.netcom.com
"Frank Swarbrick" <Frank.Swarbrick(a)efirstbank.com> wrote in message
news:473B0FEA.6F0F.0085.0(a)efirstbank.com...
> I've wondered this for a long time... Why is there a restriction that an
> OCCURS clause cannot occur at level 01 or 77? For instance, why not
>
> 01 TRANS-MORE-CNT OCCURS 4
> PIC S9(7) COMP-3 VALUE ZERO.
>
> Or even
>
> 77 TRANS-MORE-CNT OCCURS 4
> PIC S9(7) COMP-3 VALUE ZERO.
>
> Rather than something silly like...
>
> 01.
> 05 TRANS-MORE-CNT OCCURS 4
> PIC S9(7) COMP-3 VALUE ZERO.
>
> It's always bugged me.
>
> Frank
>


From: Robert on
On Wed, 14 Nov 2007 15:10:34 -0700, "Frank Swarbrick" <Frank.Swarbrick(a)efirstbank.com>
wrote:

>I've wondered this for a long time... Why is there a restriction that an
>OCCURS clause cannot occur at level 01 or 77? For instance, why not
>
>01 TRANS-MORE-CNT OCCURS 4
> PIC S9(7) COMP-3 VALUE ZERO.
>
>Or even
>
>77 TRANS-MORE-CNT OCCURS 4
> PIC S9(7) COMP-3 VALUE ZERO.
>
>Rather than something silly like...
>
>01.
> 05 TRANS-MORE-CNT OCCURS 4
> PIC S9(7) COMP-3 VALUE ZERO.
>
>It's always bugged me.

I think the reason is SYNCHRONIZATION. The Standard does not say 01 and 77 levels
('records') are automatically synchronized, but it does say the implementor has the option
to say that, "A record itself may be automatically synchronized." 13.16.56.3 Micro Focus
elected to make it automatic; I expect most or all compilers do, on machines requiring
synchronization.

Assuming for illustration 8 byte word boundaries, the compiler would generate 4 byte
fillers between each TRANS-MORE-CNT in your first example, even though you did not say
SYNC, but no filler in your second example, BECAUSE you did not say SYNC.

After getting frustrated by this 'compiler bug', people would ask for a NOSYNC option to
'fix' it.

From: Rick Smith on

"Robert" <no(a)e.mail> wrote in message
news:0k4nj35572pnugah142kv58gnabes24lid(a)4ax.com...
> On Wed, 14 Nov 2007 15:10:34 -0700, "Frank Swarbrick"
<Frank.Swarbrick(a)efirstbank.com>
> wrote:
>
> >I've wondered this for a long time... Why is there a restriction that an
> >OCCURS clause cannot occur at level 01 or 77? For instance, why not
> >
> >01 TRANS-MORE-CNT OCCURS 4
> > PIC S9(7) COMP-3 VALUE ZERO.
> >
> >Or even
> >
> >77 TRANS-MORE-CNT OCCURS 4
> > PIC S9(7) COMP-3 VALUE ZERO.
> >
> >Rather than something silly like...
> >
> >01.
> > 05 TRANS-MORE-CNT OCCURS 4
> > PIC S9(7) COMP-3 VALUE ZERO.
> >
> >It's always bugged me.
>
> I think the reason is SYNCHRONIZATION. The Standard does not say 01 and 77
levels
> ('records') are automatically synchronized, but it does say the
implementor has the option
> to say that, "A record itself may be automatically synchronized."
13.16.56.3 Micro Focus
> elected to make it automatic; I expect most or all compilers do, on
machines requiring
> synchronization.
>
> Assuming for illustration 8 byte word boundaries, the compiler would
generate 4 byte
> fillers between each TRANS-MORE-CNT in your first example, even though you
did not say
> SYNC, but no filler in your second example, BECAUSE you did not say SYNC.

Micro Focus COBOL 3.2.24 (Jun 1994) did not add
implicit FILLER bytes. The following program displays:
16 / 4 = 4.

Were implict FILLER bytes added, "space-for-table"
would have been 32. Using an odd number for the occurs
does report the next higher even number due to implicit
FILLER bytes (i.e., occurs 5 reports 24 / 4 = 6).
-----
$set align"8"
program-id. A27B20.
data division.
working-storage section.
01 item occurs 4 pic s9(7) comp-3 value 0.
01 dummy pic x.
78 space-for-table value start of dummy - start of item.
78 length-of-item value length of item.
78 occurs-count value space-for-table / length-of-item.
procedure division.
display space-for-table " / " length-of-item
" = " occurs-count
stop run.
-----


From: Judson McClendon on
Do you fellows really think those were reasons used when OCCURS was
originally defined in COBOL decades ago? I don't think so. I suspect it
had more do with their concept of what a record was, and as pointed out
already, using a subscript in WRITE would seem a bit un-COBOL-ish
at the time. :-)
--
Judson McClendon judmc(a)sunvaley0.com (remove zero)
Sun Valley Systems http://sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."


"Rick Smith" <ricksmith(a)mfi.net> wrote:
> "Robert" <no(a)e.mail> wrote:
>> "Frank Swarbrick" <Frank.Swarbrick(a)efirstbank.com> wrote:
>>
>> >I've wondered this for a long time... Why is there a restriction that an
>> >OCCURS clause cannot occur at level 01 or 77? For instance, why not
>> >
>> >01 TRANS-MORE-CNT OCCURS 4
>> > PIC S9(7) COMP-3 VALUE ZERO.
>> >
>> >Or even
>> >
>> >77 TRANS-MORE-CNT OCCURS 4
>> > PIC S9(7) COMP-3 VALUE ZERO.
>> >
>> >Rather than something silly like...
>> >
>> >01.
>> > 05 TRANS-MORE-CNT OCCURS 4
>> > PIC S9(7) COMP-3 VALUE ZERO.
>> >
>> >It's always bugged me.
>>
>> I think the reason is SYNCHRONIZATION. The Standard does not say 01 and 77
> levels
>> ('records') are automatically synchronized, but it does say the
> implementor has the option
>> to say that, "A record itself may be automatically synchronized."
> 13.16.56.3 Micro Focus
>> elected to make it automatic; I expect most or all compilers do, on
> machines requiring
>> synchronization.
>>
>> Assuming for illustration 8 byte word boundaries, the compiler would
> generate 4 byte
>> fillers between each TRANS-MORE-CNT in your first example, even though you
> did not say
>> SYNC, but no filler in your second example, BECAUSE you did not say SYNC.
>
> Micro Focus COBOL 3.2.24 (Jun 1994) did not add
> implicit FILLER bytes. The following program displays:
> 16 / 4 = 4.
>
> Were implict FILLER bytes added, "space-for-table"
> would have been 32. Using an odd number for the occurs
> does report the next higher even number due to implicit
> FILLER bytes (i.e., occurs 5 reports 24 / 4 = 6).
> -----
> $set align"8"
> program-id. A27B20.
> data division.
> working-storage section.
> 01 item occurs 4 pic s9(7) comp-3 value 0.
> 01 dummy pic x.
> 78 space-for-table value start of dummy - start of item.
> 78 length-of-item value length of item.
> 78 occurs-count value space-for-table / length-of-item.
> procedure division.
> display space-for-table " / " length-of-item
> " = " occurs-count
> stop run.
> -----
>
>