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
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.
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
On Wed, 5 Jul 2023 11:54:22 +0200, Volker Englisch <eh41@selene.inka.de> wrote:
I would first SORT the file around & then read first 15 ;-)
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...
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
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.
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.
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.
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.
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 :)
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.
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.
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...
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 106:33:06 |
Calls: | 6,700 |
Files: | 12,232 |
Messages: | 5,350,363 |