View previous topic :: View next topic
|
Author |
Message |
lucky.rohith Currently Banned New User
Joined: 06 Aug 2006 Posts: 10
|
|
|
|
Hi,
IN C-language v can read contents of a file from the end using pointers.
Is ther any possibility of reading contents of a file from end in COBOL?
If its ther how v hav to do it? |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
I'm going to say No,
Reading a file from the back to the front in COBOL cannot be done within the normal confines of the COBOL language.
I believe it should be technically possible, but far outside acceptability. You would have to have an in-depth knowledge of the Operating System Control Blocks, and run these using pointers. Then you should be able to set the current record pointer to the last record and read it. This is NOT something to do using COBOL.
Another way would be to call an assembler subroutine to do the read for you. But, then it?s not COBOL, is it.
Dave |
|
Back to top |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
hello rohit
This question is asked by me early in the forum but not much old entry check out for the replay's
from the replays i found that there is no function in the vs cobol 2 to read file from bottom but there are options in some cobol compilers .
you can sort the file using some index field in the file using sort verb to the desending order and make the new file and then read the new file |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Hi
You can read backwards.
for eg. If organization is Indexed, you can use the following method.
intialize key-1.
start file1 key > key-1.
p1.
read previous record.
if file-status = 10
perform close-files
stop run.
go to p1.
Regards
Aji Cherian |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Hi,
There is a mistake in my previous post. Please see the modified code below.
intialize key-1.
start file1 key > key-1.
p1.
read previous record.
if file-status = 46
perform close-files
stop run.
go to p1.
Regards
Aji Cherian |
|
Back to top |
|
|
cheetz007
New User
Joined: 10 Aug 2006 Posts: 23
|
|
|
|
Or, put another way, unless the file is indexed, no you can't do it. The best way to do it if the file is not indexed is to use a sort to add a key to the file and then sort it in reverse order and then just read it normally.
Of course, if it's a small file, you can just read the lot into some kind of table and then process it that way, but this way leads to madness! First answer seems to be the most common practice. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Aji,
Would you be so kind as to enlighten us as to where in the COBOL manual I can read about READ PREVIOUS?
I have included a link to the COBOL MANUAL for you convenience.
Dave |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Aji,
The READ PREV is a function of IBM's CICS. While it appears that it's a COBOL function in that it uses COBOL-like syntax the function is only supported when using CICS.
I don't know this as a fact but I'm sure CICS uses assembler language to satisfy the request. |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
hi
There is a connection, for reading the previous record the correct syntax is
Read <file-name> previous record.
regards
Aji Cherian |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
|
|
Hi
There is a mistake in my code once again. Sorry. Please go through the code below.
intialize key-1.
move high-values to key-1
start file1 key > key-1.
p1.
read <file1> previous record.
if file-status = 46
perform close-files
stop run.
go to p1.
Regards
Aji Cherian |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Aji Cherian, you are one hard person to convince that there is no ?READ PREVIOUS? in COBOL. Even the COBOL manual was given to you as a link, but you persist. As Jack said, CICS does have some syntax to support ?READ PREVIOUS? that looks like COBOL, but It?s not, it?s a CICS command. Or maybe you are using a NON-IBM compiler that does support it, but this is an IBM VS COBOL II forum, and IBM VS COBOL II, or any other IBM COBOL does NOT support ?READ PREVIOUS?. Please read the manual.
However, there is one statement you made in your last post that I fully support.
Quote: |
There is a mistake in my code once again |
Dave |
|
Back to top |
|
|
Aji
New User
Joined: 03 Feb 2006 Posts: 53 Location: Mumbai
|
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Well Aji,
I gave you the benifit of the doubt and thought that there might be undocumented options, so I compiled a small program.
Code: |
PP 5655-G53 IBM ENTERPRISE COBOL FOR Z/OS AND OS/390 3.1.0 TEST01 DATE 08
LINEID PL SL ----+-*A-1-B--+----2----+----3----+----4----+----5----+----6---
000001 000100 IDENTIFICATION DIVISION.
000002 000200 PROGRAM-ID. TEST01.
000003 000300 AUTHOR. DAVIDATK.
000004 000400 INSTALLATION.
000005 000500 DATE-WRITTEN. MAY 2006.
000006** 000500 DATE-COMPILED. 08/29/06.
000007 000700
000008 001200*********************************************************
000009 003100 ENVIRONMENT DIVISION.
000010** 001400 CONFIGURATION SECTION.
000011 001500 SOURCE-COMPUTER. IBM-3090.
000012 001600 OBJECT-COMPUTER. IBM-3090.
000013 003200 INPUT-OUTPUT SECTION.
000014 003300 FILE-CONTROL.
000015** 002000
000016 002001 SELECT TEST-FLAT ASSIGN TO TESTFLAT.
000017 002010
000018 002011 SELECT TEST-INDX ASSIGN TO TESTINDX
000019 002013 ORGANIZATION IS INDEXED
000020 002014 ACCESS IS DYNAMIC
000021 002016 RECORD KEY IS KEY-1.
000022** 002010
000023 004300 DATA DIVISION.
000024 004400 FILE SECTION.
000025** 002300
000026 002301 FD TEST-FLAT
000027 002302 LABEL RECORDS ARE STANDARD
000028 002303 BLOCK CONTAINS 0 RECORDS.
000029 002304 01 TEST-FLAT-REC PIC X(80).
000030 002310
000031 002311 FD TEST-INDX
000032 002312 LABEL RECORDS ARE STANDARD.
000033 002313 01 TEXT-INDX-REC.
000034 002314 05 KEY-1 PIC X(10).
000035 002315 05 FILLER PIC X(70).
000036 002316
000037 002320
000038 005800 WORKING-STORAGE SECTION.
000039** 002940
000040** 002405
000041** 002402 LINKAGE SECTION.
000042 002430
000043 004020 PROCEDURE DIVISION.
000044** 002600
000045 004111 PROGRAM-START.
000046 004124
000047** 004113 OPEN INPUT TEST-FLAT
000048 004114 TEST-INDX.
000049 004178
000050** 004116 READ TEST-FLAT.
000051 004134
000052** 004118 READ TEST-FLAT NEXT.
000053** 004118
000054 004120 READ TEST-FLAT PREVIOUS.
==000054==> IGYPS2072-S "PREVIOUS" WAS INVALID. SKIPPED TO THE NEXT VERB, PERIOD OR
PROCEDURE-NAME DEFINITION.
PP 5655-G53 IBM ENTERPRISE COBOL FOR Z/OS AND OS/390 3.1.0 TEST01 DATE 08
LINEID PL SL ----+-*A-1-B--+----2----+----3----+----4----+----5----+----6---
000055** 004120
000056 004122 CLOSE TEST-FLAT.
000057** 004120
000058 004131 INITIALIZE KEY-1.
000059 004132 MOVE HIGH-VALUES TO KEY-1.
000060 004133 START TEST-INDX KEY > KEY-1.
000061 004134
000062 004135 READ TEST-INDX NEXT RECORD.
000063 004136
000064 004137 READ TEST-INDX PREVIOUS RECORD.
==000064==> IGYPS2072-S "PREVIOUS" WAS INVALID. SKIPPED TO THE NEXT VERB, PERIOD OR
PROCEDURE-NAME DEFINITION.
000065 004138
000066 004140 GOBACK.
000067 004300
|
Dave |
|
Back to top |
|
|
raghunathns
Active User
Joined: 08 Dec 2005 Posts: 127 Location: rochester
|
|
|
|
in cobol we can read previous
the file should be an indexed file (i.e ksds-vsam)
normal sequential file we cant. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
raghunathns,
If you look at the example given above, you will find that there is a 'Flat' file and an 'INDEXED' file given.
The compiler seems to not like the READ <file> PREVIOUS for either of them.
I submit the same request to you as to Aji, show me in the IBM COBOL Manual where the 'READ <file> PREVIOUS RECORD' can be found.
Not by the proof that Aji gave for 'READ <file> PREVIOUS' being valid by showing my where it is not in the manual.
I have included a link to the COBOL MANUAL for you convenience also..
Dave |
|
Back to top |
|
|
raghunathns
Active User
Joined: 08 Dec 2005 Posts: 127 Location: rochester
|
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
raghunathns,
I'll give you partial credit for your post as I over-generalized when I spoke of IBM COBOL. You showed me where ?READ PREVIOUS RECORD? is a valid IBM Extension in the COBOL/VSE manual. But, it is not valid in VS COBOL II, Enterprise COBOL, and this is not a COBOL/VSE forum.
You did a good job in pointing this out, I?ll reply to this type of post more accurately next time.
Dave |
|
Back to top |
|
|
|