Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

There's a whole WORLD in a mud puddle! -- Doug Clifford


devel / comp.lang.cobol / Re: Iterating an array

SubjectAuthor
* Iterating an arrayBruce Axtens
+* Re: Iterating an arrayBruce Axtens
|`- Re: Iterating an arraydocdwarf
`* Re: Iterating an arrayRick Smith
 `* Re: Iterating an arrayBruce Axtens
  `- Re: Iterating an arraydocdwarf

1
Iterating an array

<shrvek$e12$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=192&group=comp.lang.cobol#192

  copy link   Newsgroups: comp.lang.cobol
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bruce.axtens@gmail.com (Bruce Axtens)
Newsgroups: comp.lang.cobol
Subject: Iterating an array
Date: Wed, 15 Sep 2021 13:13:51 +0800
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <shrvek$e12$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Sep 2021 05:13:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5a7f967cc8e5e75d2d45c6db0de5ab7a";
logging-data="14370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/p+himmmKqbYz8jnyF3iZ9"
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.8.1
Cancel-Lock: sha1:yY4/qbWUuSlM1rqf/uSLdUxvkH4=
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: Bruce Axtens - Wed, 15 Sep 2021 05:13 UTC

So I have an array created by defining with an occurs. Let's say I have
OCCURS 10 TIMES. When it comes to the PERFORM VARYING (or whatever) is
there a way to iterate through the rows in the array without specifying
the same number of rows in the PERFORM, that is, the compiler knowing
how many rows are defined in WORKING-STORAGE, it can limit the number of
iterations in the PERFORM?

Bruce

Re: Iterating an array

<shsr2t$r7p$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=193&group=comp.lang.cobol#193

  copy link   Newsgroups: comp.lang.cobol
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bugmagnet@outlook.com (Bruce Axtens)
Newsgroups: comp.lang.cobol
Subject: Re: Iterating an array
Date: Wed, 15 Sep 2021 21:05:30 +0800
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <shsr2t$r7p$1@dont-email.me>
References: <shrvek$e12$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Sep 2021 13:05:34 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3d48772c693ee8c4f207209dee6ef95b";
logging-data="27897"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XZUhvxOXCRuy3nRmhPjaW"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.9
Cancel-Lock: sha1:X4nvxe9jyGtUaDUlbWS0iqc8BNg=
In-Reply-To: <shrvek$e12$1@dont-email.me>
 by: Bruce Axtens - Wed, 15 Sep 2021 13:05 UTC

Bruce Axtens wrote:
> So I have an array created by defining with an occurs.

And this is what I ended up with (so far)

IDENTIFICATION DIVISION.

PROGRAM-ID. HelloWorldTests.

ENVIRONMENT DIVISION.

DATA DIVISION.

WORKING-STORAGE SECTION.

01 Hello PIC X(13).

01 WS-CNT PIC 9 VALUE 0.

01 WS-MAX PIC 9 VALUE 0.

01 Tests.

03 Test1.

05 WS-T-Enabled PIC X VALUE '1'.

05 WS-T-Name PIC X(5) VALUE 'Test1'.

05 WS-T-Func PIC X(10) VALUE 'HelloWorld'.

05 WS-T-Answer PIC X(13) VALUE 'Hello, World!'.

03 Test2.

05 WS-T-Enabled PIC X VALUE '0'.

05 WS-T-Name PIC X(5) VALUE 'Test1'.

05 WS-T-Func PIC X(10) VALUE 'HelloWorld'.

05 WS-T-Answer PIC X(13) VALUE 'Hello, World!'.

01 TestGroup REDEFINES Tests.

03 TestList OCCURS 2 TIMES.

05 WS-TL-Enabled PIC X.

05 WS-TL-Name PIC X(5).

05 WS-TL-Func PIC X(10).

05 WS-TL-Answer PIC X(13).

01 TestItem.

03 WS-TI-Enabled PIC X.

03 WS-TI-Name PIC X(5).

03 WS-TI-Func PIC X(10).

03 WS-TI-Answer PIC X(13).

PROCEDURE DIVISION.

COMPUTE WS-MAX = LENGTH OF TestGroup / LENGTH OF Test1.

PERFORM 10-TEST

VARYING WS-CNT

FROM 1

BY 1

UNTIL WS-CNT > WS-MAX

STOP RUN.

10-TEST.

MOVE TestList(WS-CNT) TO TestItem.

IF WS-TI-Enabled = '1'

CALL WS-TI-Func USING BY REFERENCE Hello

IF Hello = WS-TI-Answer

DISPLAY "Pass"

ELSE

DISPLAY "Fail"

END-IF

END-IF.

Re: Iterating an array

<shtdcr$8e9$1@reader1.panix.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=194&group=comp.lang.cobol#194

  copy link   Newsgroups: comp.lang.cobol
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix1.panix.com!not-for-mail
From: docdwarf@panix.com
Newsgroups: comp.lang.cobol
Subject: Re: Iterating an array
Date: Wed, 15 Sep 2021 18:18:03 -0000 (UTC)
Organization: Public Access Networks Corp.
Message-ID: <shtdcr$8e9$1@reader1.panix.com>
References: <shrvek$e12$1@dont-email.me> <shsr2t$r7p$1@dont-email.me>
Injection-Date: Wed, 15 Sep 2021 18:18:03 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix1.panix.com:166.84.1.1";
logging-data="8649"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
 by: docdwarf@panix.com - Wed, 15 Sep 2021 18:18 UTC

In article <shsr2t$r7p$1@dont-email.me>,
Bruce Axtens <bugmagnet@outlook.com> wrote:

[snip]

> 03 TestList OCCURS 2 TIMES.

03 TestList OCCURS WS-NC-2 TIMES.

>
> 05 WS-TL-Enabled PIC X.
>
> 05 WS-TL-Name PIC X(5).
>
> 05 WS-TL-Func PIC X(10).
>
> 05 WS-TL-Answer PIC X(13).
>
> 01 TestItem.
>
> 03 WS-TI-Enabled PIC X.
>
> 03 WS-TI-Name PIC X(5).
>
> 03 WS-TI-Func PIC X(10).
>
> 03 WS-TI-Answer PIC X(13).

01 WS-NUMERIC-CONSTANTS.
05 WS-NC-1 PIC 9 VALUE 1.
05 WS-NC-2 PIC 9 VALUE 2.
05 WS-NC-3 PIC 9 VALUE 3.
etc.

>
> PROCEDURE DIVISION.
>
> COMPUTE WS-MAX = LENGTH OF TestGroup / LENGTH OF Test1.
>
> PERFORM 10-TEST
>
> VARYING WS-CNT
>
> FROM 1
>
> BY 1
>
> UNTIL WS-CNT > WS-MAX

PERFORM 10-TEST
VARYING SUB1 FROM 1 BY 1
UNTIL SUB1 > WS-NC-2.

etc.

DD

Re: Iterating an array

<f965fbb7-18c0-42e0-8f56-013c87d0374an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=195&group=comp.lang.cobol#195

  copy link   Newsgroups: comp.lang.cobol
X-Received: by 2002:ac8:489a:: with SMTP id i26mr1281524qtq.372.1631730194372;
Wed, 15 Sep 2021 11:23:14 -0700 (PDT)
X-Received: by 2002:a25:99c8:: with SMTP id q8mr1762530ybo.63.1631730193963;
Wed, 15 Sep 2021 11:23:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.cobol
Date: Wed, 15 Sep 2021 11:23:13 -0700 (PDT)
In-Reply-To: <shrvek$e12$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=98.180.88.86; posting-account=CcFQgQoAAAB4uPj9HOgZiRCM2Y_v-jmi
NNTP-Posting-Host: 98.180.88.86
References: <shrvek$e12$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f965fbb7-18c0-42e0-8f56-013c87d0374an@googlegroups.com>
Subject: Re: Iterating an array
From: rs847925@gmail.com (Rick Smith)
Injection-Date: Wed, 15 Sep 2021 18:23:14 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 47
 by: Rick Smith - Wed, 15 Sep 2021 18:23 UTC

On Wednesday, September 15, 2021 at 1:13:59 AM UTC-4, bruce....@gmail.com wrote:
> So I have an array created by defining with an occurs. Let's say I have
> OCCURS 10 TIMES. When it comes to the PERFORM VARYING (or whatever) is
> there a way to iterate through the rows in the array without specifying
> the same number of rows in the PERFORM, that is, the compiler knowing
> how many rows are defined in WORKING-STORAGE, it can limit the number of
> iterations in the PERFORM?

COBOL tables are often defined to be larger than the apparent
need because the number of entries may be variable. That is,
a table may be defined as OCCURS 100, when the number of
entries determined during design may be 1 to 50. Sometimes
designs change.

It is not uncommon to define both a limit and a count for
the number of entries available and used, respectively.
For example,

01 t1-limit comp pic 9(4) value 100.
01 t1-count comp pic 9(4) value 0.
01 t1-index comp pic 9(4) value 0.
01 t1-table.
03 t1-entry occurs 100.
05 (the description of the entry)

When loading a table, one may do something like.

add-entry.
if t1-count not > t1-limit
add 1 to t1-count
move new-entry to t1-entry (t1-count)
else
perform error-proc-t1-no-space
end-if
.

When using PERFORM to find an entry, one may do.

find-entry.
perform varying t1-index from 1 by 1
until t1-index > t1-count
or (whatever search criteria)
end-perform
.

Tables are not just in the WORKING-STORAGE SECTION, they
may be placed in the FILE SECTION, LOCAL-STORAGE SECTION
and LINKAGE SECTION.

Re: Iterating an array

<shul9b$10e$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=196&group=comp.lang.cobol#196

  copy link   Newsgroups: comp.lang.cobol
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bruce.axtens@gmail.com (Bruce Axtens)
Newsgroups: comp.lang.cobol
Subject: Re: Iterating an array
Date: Thu, 16 Sep 2021 13:38:51 +0800
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <shul9b$10e$1@dont-email.me>
References: <shrvek$e12$1@dont-email.me>
<f965fbb7-18c0-42e0-8f56-013c87d0374an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Sep 2021 05:38:52 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="25d798394433465795c3b52aa909c9a5";
logging-data="1038"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191js6Sb//OCy67GQlPQImD"
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.8.1
Cancel-Lock: sha1:2PPtiErmHjCfb6Rt5mPpQwpkhec=
In-Reply-To: <f965fbb7-18c0-42e0-8f56-013c87d0374an@googlegroups.com>
 by: Bruce Axtens - Thu, 16 Sep 2021 05:38 UTC

Rick Smith wrote:
> On Wednesday, September 15, 2021 at 1:13:59 AM UTC-4, bruce....@gmail.com wrote:

So best practice then is to oversize the array and read the data in from
somewhere, keeping track of how much is read in and then iterating the
table accordingly? I'm fine with that.

I've just begun the COBOL track on https://exercism.org . I learned
COBOL on a VAX-11 back in the early 1980s but never got to use it to
earn a living. I'm hardly the best qualified for creating the track but
I'm giving it my best anyway.

Re: Iterating an array

<shvc8g$f1s$1@panix1.panix.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=197&group=comp.lang.cobol#197

  copy link   Newsgroups: comp.lang.cobol
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix1.panix.com!panix1.panix.com!not-for-mail
From: docdwarf@panix.com
Newsgroups: comp.lang.cobol
Subject: Re: Iterating an array
Date: 16 Sep 2021 12:10:56 -0000
Organization: PANIX -- Public Access Networks Corp.
Lines: 17
Message-ID: <shvc8g$f1s$1@panix1.panix.com>
References: <shrvek$e12$1@dont-email.me> <f965fbb7-18c0-42e0-8f56-013c87d0374an@googlegroups.com> <shul9b$10e$1@dont-email.me>
Injection-Info: reader1.panix.com; posting-host="panix1.panix.com:166.84.1.1";
logging-data="17037"; mail-complaints-to="abuse@panix.com"
 by: docdwarf@panix.com - Thu, 16 Sep 2021 12:10 UTC

In article <shul9b$10e$1@dont-email.me>,
Bruce Axtens <bruce.axtens@gmail.com> wrote:
>Rick Smith wrote:
>> On Wednesday, September 15, 2021 at 1:13:59 AM UTC-4, bruce....@gmail.com wrote:
>
>So best practice then is to oversize the array and read the data in from
>somewhere, keeping track of how much is read in and then iterating the
>table accordingly? I'm fine with that.

You've got the general idea down fairly well. Tables are intended to keep
small amounts of frequently- and rapidly-needed data available in core
(remember core?) so as to cut down the time and I/O needed for file
access. Think of a small shipping company, 700, 800 clients, each of
which has its own discount. How do you process a week's orders and make
sure folks get what they deserve?

DD

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor