• Retrieve the 15 last records

    From Volker Englisch@21:1/5 to All on Wed Jul 5 11:54:22 2023
    Hello all together!

    I need to retrieve the last matching records from a serial file. I
    tried it this way:

    01 WS-LINES.
    05 WS-LINE OCCURS 15 TIMES PIC X(40).

    1000-LOOP.
    READ DWB000
    AT END ...
    END-READ.
    READ DWB000-RECORD.
    IF WS-ARTNO IS EQUAL DWB000-ARTNO THEN
    PERFORM VARYING WS-COUNTER FROM 2 BY 1 UTIL WS-COUNTER EQUAL 15
    MOVE WS-LINE (WS-COUNTER) TO WS-LINE (WS-COUNTER - 1)
    END-PERFORM
    MOVE DWB000-RECORD TO WS-LINE (15)
    END-IF.
    GO TO 1000-LOOP.

    Finally I get 15 empty lines. My intention was to push the LINEs
    downwards and move the currently found record into the highest line...

    And idea why that doesn't work? Or, is there another approach to
    accomplish it?

    I'm working with GnuCobol on FreeBSD, if that's important.

    TIA
    Volker

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Joe@21:1/5 to Volker Englisch on Wed Jul 5 15:53:10 2023
    On Wed, 5 Jul 2023 11:54:22 +0200, Volker Englisch <eh41@selene.inka.de> wrote:

    Hello all together!

    I need to retrieve the last matching records from a serial file. I
    tried it this way:

    01 WS-LINES.
    05 WS-LINE OCCURS 15 TIMES PIC X(40).

    1000-LOOP.
    READ DWB000
    AT END ...
    END-READ.
    READ DWB000-RECORD.
    IF WS-ARTNO IS EQUAL DWB000-ARTNO THEN
    PERFORM VARYING WS-COUNTER FROM 2 BY 1 UTIL WS-COUNTER EQUAL 15
    MOVE WS-LINE (WS-COUNTER) TO WS-LINE (WS-COUNTER - 1)
    END-PERFORM
    MOVE DWB000-RECORD TO WS-LINE (15)
    END-IF.
    GO TO 1000-LOOP.

    Finally I get 15 empty lines. My intention was to push the LINEs
    downwards and move the currently found record into the highest line...

    And idea why that doesn't work? Or, is there another approach to
    accomplish it?

    I'm working with GnuCobol on FreeBSD, if that's important.

    TIA
    Volker

    I would first SORT the file around & then read first 15 ;-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Volker Englisch@21:1/5 to Volker Englisch on Wed Jul 5 17:56:05 2023
    Volker Englisch schrieb am 05.07.2023:
    PERFORM VARYING WS-COUNTER FROM 2 BY 1 UTIL WS-COUNTER EQUAL 15
    ^^^^^
    GREATER
    MOVE WS-LINE (WS-COUNTER) TO WS-LINE (WS-COUNTER - 1)
    END-PERFORM
    MOVE DWB000-RECORD TO WS-LINE (15)
    END-IF.
    GO TO 1000-LOOP.

    With a GREATER instead of EQUAL it runs the way it should.
    Logical blackout of myself...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vincent Coen@21:1/5 to All on Wed Jul 5 19:23:19 2023
    Hello Volker!

    Wednesday July 05 2023 10:54, Volker Englisch wrote to All:

    I would have said the easiest is to use OPEN REVERSED.
    Then read first 15 records.

    There again I am lazy.

    Vince


    Hello all together!

    I need to retrieve the last matching records from a serial file. I
    tried it this way:

    01 WS-LINES.
    05 WS-LINE OCCURS 15 TIMES PIC X(40).

    1000-LOOP.
    READ DWB000
    AT END ...
    END-READ.
    READ DWB000-RECORD.
    IF WS-ARTNO IS EQUAL DWB000-ARTNO THEN
    PERFORM VARYING WS-COUNTER FROM 2 BY 1 UTIL WS-COUNTER EQUAL 15
    MOVE WS-LINE (WS-COUNTER) TO WS-LINE (WS-COUNTER - 1)
    END-PERFORM
    MOVE DWB000-RECORD TO WS-LINE (15)
    END-IF.
    GO TO 1000-LOOP.

    Finally I get 15 empty lines. My intention was to push the LINEs
    downwards and move the currently found record into the highest line...

    And idea why that doesn't work? Or, is there another approach to
    accomplish it?

    I'm working with GnuCobol on FreeBSD, if that's important.

    TIA
    Volker





    Vincent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Volker Englisch@21:1/5 to Joe on Wed Jul 5 22:09:59 2023
    Joe schrieb am 05.07.2023:
    On Wed, 5 Jul 2023 11:54:22 +0200, Volker Englisch <eh41@selene.inka.de> wrote:

    I need to retrieve the last matching records from a serial file. I
    tried it this way:

    01 WS-LINES.
    05 WS-LINE OCCURS 15 TIMES PIC X(40).

    1000-LOOP.
    READ DWB000
    AT END ...
    END-READ.
    READ DWB000-RECORD.
    IF WS-ARTNO IS EQUAL DWB000-ARTNO THEN
    PERFORM VARYING WS-COUNTER FROM 2 BY 1 UTIL WS-COUNTER EQUAL 15
    MOVE WS-LINE (WS-COUNTER) TO WS-LINE (WS-COUNTER - 1)
    END-PERFORM
    MOVE DWB000-RECORD TO WS-LINE (15)
    END-IF.
    GO TO 1000-LOOP.

    Finally I get 15 empty lines. My intention was to push the LINEs
    downwards and move the currently found record into the highest line...

    I would first SORT the file around & then read first 15 ;-)

    Well, the records are already in a date-wise sequence. Thanks for the
    tip though

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Joe@21:1/5 to Vincent Coen on Fri Jul 7 13:39:58 2023
    On Wed, 05 Jul 2023 19:23:19 +0100, "Vincent Coen" <VBCoen@gmail.com> wrote:

    Hello Volker!

    Wednesday July 05 2023 10:54, Volker Englisch wrote to All:

    I would have said the easiest is to use OPEN REVERSED.

    Vince


    Didn't even know such a thing existed. Must a modern extention.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bill@21:1/5 to Joe on Fri Jul 7 12:42:26 2023
    On 7/7/2023 9:39 AM, Joe wrote:
    On Wed, 05 Jul 2023 19:23:19 +0100, "Vincent Coen" <VBCoen@gmail.com> wrote:

    Hello Volker!

    Wednesday July 05 2023 10:54, Volker Englisch wrote to All:

    I would have said the easiest is to use OPEN REVERSED.

    Vince


    Didn't even know such a thing existed. Must a modern extention.

    Caution!!
    The original poster said he was using GnuCOBOL. Unless it has changed
    since I grabbed it the Programmers Manual says "REVERSED" is
    syntactically recognized but otherwise non-functional.

    bill

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Volker Englisch@21:1/5 to Vincent Coen on Fri Jul 7 19:16:30 2023
    Hi Vince!

    Vincent Coen schrieb am 05.07.2023:
    Hello Volker!

    Wednesday July 05 2023 10:54, Volker Englisch wrote to All:

    I would have said the easiest is to use OPEN REVERSED.
    Then read first 15 records.

    Unfortunately my compiler doesn't support OPEN REVERSED :-(

    From the manual: "The [...] REVERSE clause is syntactically
    recognized but otherwise non-functional."

    Volker

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rick Smith@21:1/5 to Joe on Fri Jul 7 14:58:49 2023
    On Friday, July 7, 2023 at 9:40:02 AM UTC-4, Joe wrote:
    On Wed, 05 Jul 2023 19:23:19 +0100, "Vincent Coen" <VBC...@gmail.com> wrote:

    Hello Volker!

    Wednesday July 05 2023 10:54, Volker Englisch wrote to All:

    I would have said the easiest is to use OPEN REVERSED.

    Vince


    Didn't even know such a thing existed. Must a modern extention.

    REVERSED was available in the COBOL 60 Report.

    "6. The REVERSED option can only be used on single reel input files."

    1. OPEN INPUT file-name REVERSED

    2. READ file-name

    Retrieves the last record.

    REVERSED was made obsolete in COBOL 85. and removed from COBOL 2002.

    Beginning with the 2002 standard, one could get the same effect by:

    1. OPEN INPUT file-name

    2. START file-name LAST

    3. READ file-name PREVIOUS

    For START ... LAST, an INVALID KEY means there are no records in the file.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vincent Coen@21:1/5 to Joe on Sat Jul 8 00:06:56 2023
    Hello Joe!

    Friday July 07 2023 14:39, Joe wrote to All:

    On Wed, 05 Jul 2023 19:23:19 +0100, "Vincent Coen" <VBCoen@gmail.com>
    wrote:

    Hello Volker!

    Wednesday July 05 2023 10:54, Volker Englisch wrote to All:

    I would have said the easiest is to use OPEN REVERSED.

    Vince


    Didn't even know such a thing existed. Must a modern extention.


    Not that modern, but has been in GnuCobol for some time.

    I also see that it is in Micro Focus Workbench v3.3 dated 1993 via the
    pocket guide or is that too modern :)

    Vincent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to Vincent Coen on Sat Jul 8 01:08:14 2023
    In article <1688771216@f1.n250.z2.fidonet.ftn>,
    Vincent Coen <VBCoen@gmail.com> wrote:
    Hello Joe!

    Friday July 07 2023 14:39, Joe wrote to All:

    On Wed, 05 Jul 2023 19:23:19 +0100, "Vincent Coen" <VBCoen@gmail.com> wrote:

    Hello Volker!

    Wednesday July 05 2023 10:54, Volker Englisch wrote to All:

    I would have said the easiest is to use OPEN REVERSED.

    Vince


    Didn't even know such a thing existed. Must a modern extention.


    Not that modern, but has been in GnuCobol for some time.

    I also see that it is in Micro Focus Workbench v3.3 dated 1993 via the
    pocket guide or is that too modern :)

    1993? That's only thirty years ago... let's not be hasty!

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vincent Coen@21:1/5 to Rick Smith on Sat Jul 8 15:22:20 2023
    Hello Rick!

    Friday July 07 2023 22:58, Rick Smith wrote to All:

    On Friday, July 7, 2023 at 9:40:02 AM UTC-4, Joe wrote:
    On Wed, 05 Jul 2023 19:23:19 +0100, "Vincent Coen"
    <VBC...@gmail.com> wrote:
    Hello Volker!

    Wednesday July 05 2023 10:54, Volker Englisch wrote to All:

    I would have said the easiest is to use OPEN REVERSED.

    Vince


    Didn't even know such a thing existed. Must a modern extention.

    REVERSED was available in the COBOL 60 Report.

    "6. The REVERSED option can only be used on single reel input files."

    1. OPEN INPUT file-name REVERSED

    2. READ file-name

    Retrieves the last record.

    REVERSED was made obsolete in COBOL 85. and removed from COBOL 2002.

    Beginning with the 2002 standard, one could get the same effect by:

    1. OPEN INPUT file-name

    2. START file-name LAST

    3. READ file-name PREVIOUS

    For START ... LAST, an INVALID KEY means there are no records in the
    file.


    That will not work as p/o specified file is sequential and according to PG
    for START :

    --
    To use this statement, file-name-1 must be an ORGANIZATION RELATIVE (see [ORGANIZATION RELATIVE], page 107) or ORGANIZATION INDEXED (see
    [ORGANIZATION INDEXED], page 109) file that must have been defined with an ACCESS MODE DYNAMIC or ACCESS MODE SEQUENTIAL in its SELECT statement (see [SELECT],
    --

    So ISAM files only.

    There is nothing in the 'NEWS' file to indicate otherwise as of Friday.

    Nor for that matter usage of REVERSED so that is in but ignored so that
    will not work with GC. I did look for the tests to see if it was in and is
    so but that could just be to confirm that the compiler would ignore it.
    Nope, just looked at the tests input file and it is marked as :
    obsolete and not implemented.

    Sorry about that.

    I cannot see any thing that replaces it in any way unless someone
    implements START for sequential files or OPEN INPUT AT END for the same.

    Looks like only option is as p/o had created by creating a table holding 15 records with a double perform to process it.

    So much for my lazy way :(
    My apologies for my stupid idea.

    Vincent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to rs847925@gmail.com on Mon Jul 10 21:10:33 2023
    In article <b4414af4-46a1-4220-ac23-4fed3498a0bdn@googlegroups.com>,
    Rick Smith <rs847925@gmail.com> wrote:
    On Wednesday, July 5, 2023 at 12:07:08???PM UTC-4, Volker Englisch wrote:
    Volker Englisch schrieb am 05.07.2023:
    PERFORM VARYING WS-COUNTER FROM 2 BY 1 UTIL WS-COUNTER EQUAL 15
    ^^^^^
    GREATER
    MOVE WS-LINE (WS-COUNTER) TO WS-LINE (WS-COUNTER - 1)
    END-PERFORM
    MOVE DWB000-RECORD TO WS-LINE (15)
    END-IF.
    GO TO 1000-LOOP.

    With a GREATER instead of EQUAL it runs the way it should.
    Logical blackout of myself...

    The use of shift and insert may be very inefficient.

    Not for testing 'who can write two-year programmer code'.

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rick Smith@21:1/5 to Volker Englisch on Mon Jul 10 13:21:02 2023
    On Wednesday, July 5, 2023 at 12:07:08 PM UTC-4, Volker Englisch wrote:
    Volker Englisch schrieb am 05.07.2023:
    PERFORM VARYING WS-COUNTER FROM 2 BY 1 UTIL WS-COUNTER EQUAL 15
    ^^^^^
    GREATER
    MOVE WS-LINE (WS-COUNTER) TO WS-LINE (WS-COUNTER - 1)
    END-PERFORM
    MOVE DWB000-RECORD TO WS-LINE (15)
    END-IF.
    GO TO 1000-LOOP.

    With a GREATER instead of EQUAL it runs the way it should.
    Logical blackout of myself...

    The use of shift and insert may be very inefficient.

    I recommend using a circular buffer instead. It will save
    14 moves times the number of input records.

    With a circular buffer, each record is inserted into the next
    slot in the table replacing the previous unneeded record,
    rather than shifting. When all input records have been
    processed, the table used as the buffer may then be copied
    or further processed to put the records into their correct
    order.

    For this example, I use n to hold the next position in the
    buffer for a table of 15 records. Note that n will range from
    1 through 15 due to the mod operation in increment-n.

    ---

    01 input-record pic x(30).
    01 output-record pic x(30).
    01 n comp pic 9(4) value 1.
    01 buffer.
    02 buffer-entry pic x(30) occurs 15.

    insert-record.
    move input-record to buffer-entry (n)
    perform increment-n
    .

    get-record.
    move buffer-entry (n) to output-record
    perform increment-n
    .

    increment-n.
    compute n = function mod (n 15) + 1
    .

    ---

    After inserting the last record, n points to the first of
    the 15 records to be processed, so no adjustment to n is
    needed when changing from insert-record to get-record.

    This is essentially a first-in-first-out (FIFO) queue with
    no checks for overflow.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)