Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OPEN EXTEND in Microfocus Cobol under XP 4

Status
Not open for further replies.

Traveldixie

Programmer
Jul 31, 2003
14
BE
Hello all,

I'm a starter in cobol-programming but I do feel something is weird about this problem.
Please forgive me for the lenghty program as I don't know how to show you otherwise my problem with it...
I'm working on an Athlon with XP as OS and I'm using the Microfocus compiler with that.
Usually I'm starting it up using the workbench (WB.EXE).
This time however, for some reason it seems to me as if XP is not letting me work with Indexed Files under cobol. This is the first time I have to work with these kind of files and while compiling the cobol-editor window will crash and close on me giving me an error message in windows, something like "could not find requested COM1-port. closing program" As far as I know I never asked for any COM-port...only to OPEN an indexed file with OPEN I-O... Some people I've talked to so far are telling me that "cobol don't match with XP"...but that's not a good enough answer for me, they never tell me why or what I should do or when exactly there are problems with it, or what guarantee I have that it will work if I would use Win9X (which I really would like to prevent..).
I found a way to (temporarily?) circumvent this annoyance by running the Microfocus-editor not using the Workbench but directly using the EDITOR.EXE. For some weird reason I could start programming and compiling and even running my growing program this way, even using OPEN I-O commands...

I'm saying this because maybe all this has something to do with my real problem now :

I will copy the whole program here as is...I hope someone has the time to check it out...of course I'll reward you for your time.


IDENTIFICATION DIVISION.
PROGRAM-ID. Boek-File-Operations.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. PC.
OBJECT-COMPUTER. PC.

INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT BOEK-FILE ASSIGN TO "s2svhbk.isq"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS BK-KEY
ALTERNATE KEY IS BK-ISBN
ALTERNATE KEY IS BK-TITEL.


SELECT CLASSIFICATIE-FILE ASSIGN TO "classif.isq"
ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.

FD BOEK-FILE.
01 BK-RECORD.
05 BK-KEY PIC X(06).
05 BK-TITEL PIC X(30).
05 BK-AUTEUR.
10 BK-AUTEUR-AN PIC X(20).
10 BK-AUTEUR-VN PIC X(20).
05 BK-ISBN PIC X(13).
05 BK-UITGEVERIJ PIC X(20).
05 BK-UITGIFTE-JAAR PIC 9(04).
05 BK-CLASSIF PIC X(04).
05 BK-AANT-PAG PIC 9(04).

FD CLASSIFICATIE-FILE.
01 CLASSIF-RECORD.
05 CL-CODE PIC X(04).
05 CL-DETAIL PIC X(50).

WORKING-STORAGE SECTION.

01 WS-BK-RECORD.
05 WS-BK-KEY PIC X(06).
05 WS-BK-TITEL PIC X(30).
05 WS-BK-AUTEUR.
10 WS-BK-AUTEUR-AN PIC X(20).
10 WS-BK-AUTEUR-VN PIC X(20).
05 WS-BK-ISBN PIC X(13).
05 WS-BK-UITGEVERIJ PIC X(20).
05 WS-BK-UITGIFTE-JAAR PIC 9(04).
05 WS-BK-CLASSIF PIC X(04).
05 WS-BK-AANT-PAG PIC zzz9.

01 WS-CLASSIF-RECORD.
05 WS-CL-CODE PIC X(04).
05 WS-CL-DETAIL PIC X(50).

01 ISBNNUMBERS.
05 CYPHER PIC 9 OCCURS 12 VALUE ALL ZEROES.
05 CYPHLET PIC X VALUE ALL ZEROES.

01 ISBNRESULT.
05 RESULT PIC 99 OCCURS 10 VALUE ALL ZEROES.

01 DATUM.
05 jaar PIC 99.
05 maand PIC 99.
05 dag PIC 99.

77 keuze PIC 9 VALUE 0.
88 keuze-geldig VALUE 1 THROUGH 3.
77 nieuwrecnr PIC 9(06) VALUE 0.
77 eof PIC 9 VALUE 0.
77 groupid PIC 9(05).
77 pub PIC 9(07).
77 titleid PIC 9(06).
77 chk PIC 9(01).
77 isbnchk PIC 9 VALUE 0.
77 counter PIC 9(02) VALUE 1.
77 ptr1 PIC 9 VALUE 1.
77 ptr2 PIC 9 VALUE 1.
77 ptr3 PIC 9 VALUE 1.
77 ptr4 PIC 9 VALUE 1.
77 cijferplaats PIC 99 VALUE 1.
77 weight PIC 99 VALUE 10.
77 factor PIC 99.
77 endresult PIC 999 VALUE ALL ZEROES.
77 quotient PIC 99.
77 remains PIC 99.
77 digit PIC 99.
77 huidigjaar PIC 9999.
77 datchk PIC 9 VALUE 0.
77 classchk PIC 9 VALUE 0.
77 nogeen PIC X.
77 keyok PIC 9 VALUE 0.

PROCEDURE DIVISION.
000-Start.
INITIALIZE nieuwrecnr
INITIALIZE eof
OPEN I-O BOEK-FILE
PERFORM WITH TEST AFTER UNTIL eof = 1
READ BOEK-FILE NEXT AT END MOVE 1 TO eof
END-READ
COMPUTE nieuwrecnr = nieuwrecnr + 1
END-PERFORM
DISPLAY nieuwrecnr
CLOSE BOEK-FILE
PERFORM 100-OPKEUZE
STOP RUN
.

100-OPKEUZE.
INITIALIZE keuze
INITIALIZE isbnchk
INITIALIZE WS-BK-RECORD
DISPLAY AT 0101 SPACES
DISPLAY AT 0101 "1. Invoeren record"
DISPLAY AT 0201 "2. Wijzigen record"
DISPLAY AT 0301 "3. Verwijderen record"
DISPLAY AT 0501 "Welke operatie?(1-3)"
DISPLAY AT 1001 "9 sluiten"
PERFORM WITH TEST BEFORE UNTIL keuze-geldig
ACCEPT keuze AT 0521 WITH AUTO
EVALUATE keuze
WHEN 1 PERFORM 1000-INVOEREN
WHEN 2 PERFORM 2000-WIJZIGEN
WHEN 3 PERFORM 3000-VERWIJDEREN
WHEN 9 STOP RUN
END-EVALUATE
END-PERFORM
.

1000-INVOEREN.
INITIALIZE isbnchk, datchk, classchk
DISPLAY AT 0101 SPACES
EVALUATE keuze
WHEN 1 DISPLAY AT 0101
"VUL DE GEGEVENS VAN IN TE VOEREN BOEK IN: "
DISPLAY AT 0201
"------------------------------------------"
INITIALIZE WS-BK-RECORD
WHEN 2 DISPLAY AT 0101
"VUL DE TE WIJZIGEN GEGEVENS IN: "
DISPLAY AT 0201
"--------------------------------"
* WHEN 3 DISPLAY AT 0101
* "GEEF DE GEGEVENS VOOR TE VERWIJDEREN RECORD: "
* DISPLAY AT 0201
* "---------------------------------------------"
END-EVALUATE
DISPLAY AT 0401 "Titel: "
ACCEPT WS-BK-TITEL AT 0408 WITH REQUIRED
DISPLAY AT 0501 "Auteur: Achternaam: "
ACCEPT WS-BK-AUTEUR-AN AT 0521
DISPLAY AT 0545 "Voornaam: "
ACCEPT WS-BK-AUTEUR-VN AT 0555
DISPLAY AT 0601 "ISBN: "
PERFORM UNTIL isbnchk = 1
ACCEPT WS-BK-ISBN AT 0607 WITH REQUIRED FULL
DISPLAY AT 0621 SPACES
PERFORM 5000-ISBN-CONTROLE
END-PERFORM
DISPLAY AT 0701 "Uitgeverij: "
ACCEPT WS-BK-UITGEVERIJ AT 0713
DISPLAY AT 0801 "Jaar van uitgifte: "
PERFORM UNTIL datchk = 1
ACCEPT WS-BK-UITGIFTE-JAAR AT 0820
DISPLAY AT 0825 SPACES
PERFORM 5100-JAAR-CONTROLE
END-PERFORM
DISPLAY AT 0901 "Classificatie-code: "
PERFORM 5200-CLASSIFICATIE-ACCEPT
DISPLAY AT 1101 "Aantal pagina's: "
ACCEPT WS-BK-AANT-PAG AT 1118 WITH REQUIRED
INITIALIZE nogeen
EVALUATE keuze
WHEN 1 PERFORM 6000-WRITEAWAY
DISPLAY AT 2501 "Nog een record invoeren? (J/N)"
ACCEPT nogeen AT 2532 WITH AUTO REQUIRED
IF nogeen = "j" OR "J" THEN
INITIALIZE WS-BK-RECORD
PERFORM 1000-INVOEREN
ELSE PERFORM 100-OPKEUZE
END-IF

WHEN 2 PERFORM 7000-REWRITEAWAY
DISPLAY AT 2501 "Nog een record wijzigen? (J/N)"
ACCEPT nogeen AT 2532 WITH AUTO REQUIRED
IF nogeen = "j" OR "J" THEN
INITIALIZE WS-BK-RECORD
PERFORM 2000-WIJZIGEN
ELSE PERFORM 100-OPKEUZE
END-IF

END-EVALUATE


.

2000-WIJZIGEN.

DISPLAY AT 1010 "WE GAAN WIJZIGEN"
INITIALIZE BK-KEY
DISPLAY AT 0101 "Geef te wijzigen boeknummer: "
DISPLAY AT 0201 "Geef te wijzigen ISBN-nummer: "
DISPLAY AT 0301 "Geef te wijzigen titel: "
OPEN I-O BOEK-FILE
PERFORM UNTIL keyok=1
* ACCEPT WS-BK-KEY AT 0132 WITH PROMPT FULL
ACCEPT BK-KEY AT 0132 WITH PROMPT FULL

* MOVE WS-BK-KEY TO BK-KEY
IF BK-KEY NOT=" " THEN
READ BOEK-FILE RECORD INTO WS-BK-RECORD
INVALID KEY DISPLAY AT 0139 "Boeknummer onbekend"
MOVE 0 TO keyok
NOT INVALID KEY MOVE 1 TO keyok
PERFORM 1000-INVOEREN
END-READ
ELSE ACCEPT BK-ISBN AT 0231 WITH FULL
IF BK-ISBN NOT=" " THEN
READ BOEK-FILE INTO WS-BK-RECORD KEY IS BK-ISBN
INVALID KEY DISPLAY AT 0245 "ISBN-nummer onbekend"
MOVE 0 TO keyok
NOT INVALID KEY MOVE 1 TO keyok
PERFORM 1000-INVOEREN
END-READ
ELSE ACCEPT BK-TITEL AT 0325
IF BK-TITEL NOT=" " THEN
READ BOEK-FILE INTO WS-BK-RECORD KEY IS BK-TITEL
INVALID KEY DISPLAY AT 0357 "Boektitel onbekend"
MOVE 0 TO keyok
NOT INVALID KEY MOVE 1 TO keyok
PERFORM 1000-INVOEREN
END-READ
ELSE DISPLAY AT 1001 "Wilt u dit menu verlaten?(j/n)"
INITIALIZE nogeen
ACCEPT nogeen AT 1032
INITIALIZE BK-KEY BK-ISBN BK-TITEL
IF nogeen="J" OR "j" THEN MOVE 0 TO keyok
ELSE PERFORM 100-OPKEUZE
END-IF
END-IF

* REWRITE BOEK-FILE KEY = BK-KEY INVALID KEY DISPLAY AT
* 0139
* "Boeknummer onbekend"

CLOSE BOEK-FILE
.

3000-VERWIJDEREN.

DISPLAY AT 1010 "WE GAAN VERWIJDEREN".

5000-ISBN-CONTROLE.
INITIALIZE ISBNNUMBERS
INITIALIZE counter
INITIALIZE ptr1, ptr2, ptr3, ptr4
INITIALIZE groupid, pub, titleid, chk
INSPECT WS-BK-ISBN REPLACING ALL SPACES BY "-"
INSPECT WS-BK-ISBN TALLYING counter FOR ALL "-"
UNSTRING WS-BK-ISBN DELIMITED BY "-"
INTO groupid COUNT IN ptr1 pub COUNT IN ptr2 titleid
COUNT IN ptr3 chk COUNT IN ptr4
IF counter NOT=3 OR ptr1 > 5 OR ptr2 > 7 OR
ptr3 > 6 OR ptr4 > 1 THEN MOVE 0 TO isbnchk
DISPLAY AT 0621 "ONGELDIG ISBN-NUMMER"
ELSE PERFORM 5050-ISBNDIGITCHK
END-IF
.

5050-ISBNDIGITCHK.
MOVE WS-BK-ISBN TO ISBNNUMBERS
MOVE 10 TO weight
INITIALIZE ISBNRESULT
PERFORM 5080-CALCULUS WITH TEST AFTER
VARYING cijferplaats FROM 1 BY 1 UNTIL cijferplaats = 12
PERFORM 5090-ISBNRESULTING
.

5080-CALCULUS.
IF CYPHER(cijferplaats) IS NUMERIC
THEN COMPUTE RESULT(weight) =
CYPHER(cijferplaats)*weight
SUBTRACT 1 FROM weight
END-IF
.

5090-ISBNRESULTING.
MOVE 10 TO factor
INITIALIZE endresult
PERFORM WITH TEST BEFORE UNTIL factor = 1
COMPUTE endresult = endresult + RESULT(factor)
COMPUTE factor = factor - 1
END-PERFORM
IF CYPHLET = "X" OR "x" THEN MOVE 10 TO digit
ELSE MOVE CYPHLET TO digit
END-IF
ADD digit TO endresult
DIVIDE endresult BY 11 GIVING quotient REMAINDER remains
IF remains = 0 THEN MOVE 1 TO isbnchk
ELSE MOVE 0 TO isbnchk
DISPLAY AT 0627 "ISBN-CONTROLE KLOPT NIET"
END-IF
.

5100-JAAR-CONTROLE.
ACCEPT datum FROM DATE
STRING "20" jaar DELIMITED BY SIZE INTO huidigjaar
IF huidigjaar - WS-BK-UITGIFTE-JAAR < 0
THEN DISPLAY AT 0825 &quot;Ongeldig jaartal&quot;
MOVE 0 TO datchk
ELSE MOVE 1 TO datchk
.

5200-CLASSIFICATIE-ACCEPT.
ACCEPT WS-CL-CODE AT 0921
OPEN INPUT CLASSIFICATIE-FILE
IF WS-CL-CODE NOT=&quot; &quot; THEN
PERFORM 5250-CLASSIFICATIE-CONTROLE UNTIL classchk=1
END-IF
.

5250-CLASSIFICATIE-CONTROLE.
READ CLASSIFICATIE-FILE NEXT RECORD
AT END DISPLAY AT 0926 &quot;ONBESTAANDE CODE&quot;
CLOSE CLASSIFICATIE-FILE
PERFORM 5200-CLASSIFICATIE-ACCEPT

NOT AT END
IF WS-CL-CODE = CL-CODE
THEN MOVE WS-CL-CODE TO WS-BK-CLASSIF
THEN DISPLAY AT 0926 SPACES
DISPLAY AT 1001 &quot;Classificatiethema:&quot;CL-DETAIL
MOVE 1 TO classchk
CLOSE CLASSIFICATIE-FILE
END-IF
END-READ
.

6000-WRITEAWAY.
MOVE nieuwrecnr TO WS-BK-KEY
MOVE WS-BK-RECORD TO BK-RECORD
* WRITE BK-RECORD FROM WS-BK-RECORD
OPEN EXTEND BOEK-FILE
WRITE BK-RECORD FROM WS-BK-RECORD
END-WRITE
ADD 1 TO nieuwrecnr
CLOSE BOEK-FILE
.

7000-REWRITEAWAY.
OPEN I-O BOEK-FILE
REWRITE BK-RECORD FROM WS-BK-RECORD
END-REWRITE
CLOSE BOEK-FILE
.




The goal of this program is a normal insert of records in a indexed file using keys. The operation &quot;1.Invoeren&quot; is responsible for this (2. : edit 3.: delete record from file).
Choosing 1 in the main menu will allow the user to insert a record in this file &quot;s2svhbk2.isq&quot;.
After filling in all the fields, the program is supposed to write away this record during the 6000-WRITEAWAY-procedure. And here is my problem that I don't understand : all the record information is moved into BK-RECORD without problem. Then I OPEN EXTEND the file in the hope that when I WRITE on it, it will automatically write/add the held record at the end of the file (right..?). But that doesn't happen... what does happen is that the first record will be written no problem. the second as well, but when I'm ready to write the third record, it will NOT add itself after the second record on the file, but simply overwrite the second record...so instead of getting record numbers 000001 000002 000003...I will get 000001 000003...while I'm positive that 000002 had been written correctly in the previous loop..so I don't know if this has to do with the inability of XP to accept OPEN EXTEND commands on indexed cobol files or any of the sort. I really have no idea how to approach this matter. Or am I completely wrong in the use of the OPEN EXTEND..?

Already in advance any help is greatly appreciated!!!

Have a nice day also!
 
Indexed files do not have to be opened in Extend mode. You can simply open them in I-O and continue writing to them.

ON Indexed files:

Open Output -- creates a new Indexed file and only allows write.

Open Input -- Opens existing file and only allows reading.

Open I-O -- Opens existing file and allows Read, Write and ReWrite.

When I have more time I will look further at your program. Maybe this information will give you some help.
 
While I cannot help with this particular problem directly, I can offer some encouragement for you regarding, &quot;cobol don't match with XP&quot;. Whoever is telling you this can be described in one very good English word: ignorant. The definition for this word is: lacking in education (especially in some particular subject area). I run COBOL on my Windows XP virtually every day. [smile]

How about reducing this problem a bit to something like:
Code:
PROCEDURE DIVISION.
A.
    OPEN EXTEND BOEK-FILE
    WRITE BK-RECORD FROM ALL &quot;1&quot;
    CLOSE BOEK-FILE
    OPEN EXTEND BOEK-FILE
    WRITE BK-RECORD FROM ALL &quot;2&quot;
    CLOSE BOEK-FILE
    OPEN EXTEND BOEK-FILE
    WRITE BK-RECORD FROM ALL &quot;3&quot;
    CLOSE BOEK-FILE
    STOP RUN.

If this fails, then you need to get the vendor to provide a solution.

If this does not fail, then you have a logic problem, perhaps.


Tom Morrison
 
Hello etom,
thank you for replying so fast..
I've tried :
OPEN I-O
result is the same as the extend...I've entered 8 boeks in one run, hoping to get 8 records..but what I get is only the first and the last (although with correct contents) records, one after the other. It really looks like the second record is constantly being rewritten...
I simply don't get it..if there is an eof mistake or such then why the first is never &quot;attacked&quot; by it..
it looks to me that I'm simply opening, writing, and closing, and these commands right after one another...or am I losing my mind *and* my sight at the same time? heh..

I'll try Mr Morrison's advice now..I'll let you know :)
and yea I heard about the concept of 'ignorant' it's what's any computer can make even the smartest human being feel like, or so it seems..:)

Thanks for your support I'm in dire need of that too..
 
...and this while Mr Morrison's advice works..(under EDITOR, not under WB.EXE...)

I get indeed 3 lines as expected.. 1 with 1 1 with 2 1 with 3..

so &quot;where oh where&quot; has my logic gone in my program..
 
just a comment...: it seems as if my last record doesn't get an &quot;end-of-record&quot; symbol or so..= or the last line doesn't get a &quot;begin-of-new-record&quot; ...
the data I got from Mr Morrison remain intact..but the following line (=record) is always rewriting itself on that spot..

1111111111
2222222222
3333333333
-changing record with each input-

 
One thing I see. All the documentation I have looked at indicates you can not ReWrite or Delete a record you have not yet read. IN 7000-REWRITEAWAY you must open your file, read the record you plan on changing, modify it and then re-write it. I also see you are not performing any error checking. Use of the File Status clause on your select statement will supply you with return codes from your IO that you can then look at to see if the operation was successful. At minimum, you should use the Invalid Key clause on your Writes and ReWrites to an Index file. You could be getting errors like duplicate keys, etc.

Another issue you may be having. Your index file has alternate keys. Depending on you compiler (not familar with Micorfocus) it may not allow duplicate alternate keys as the default. Not sure what the default is in Microfocus. If duplicate keys are not allowed, then all keys, primary and alternate must be unique before the write or rewrite command can be successful. If duplicate alternate keys are desired, try adding the &quot;With Duplicates&quot; clause on your alternate keys.

As far as why your workbench will not operate properly under XP, you will have to check with the Vendor. Do you have the most current version of the compiler. Is the version you have compatable with XP. Although most things will work under XP some vendors have had to make adjustments to their software for XP and either produced a new release or supplied downloadable patches to correct the problem. Can not help with this issue.
 
1) Some versions of Workbench require a &quot;dongle&quot;. This may be your problem.

2) Standard COBOL allows REWRITE without READ. Some dialects may not, but Micro Focus does.

3) Comments about duplicate keys are correct.
 
First of all, I do not know how or where to thank you enough for finding the time to help me here..
And just to let you know : it had indeed something to do with duplicate keys that are overwritten each time when one of the alternate keys were the same. To make it &quot;easy&quot; for me while testing I inserted data with all different names (titlenames, authornames) each time, but with always *only* 2 same ISBN-numbers (one I knew by heart by now and an all zeroes one..) ...at first I had not put it as an alternate key so it worked fine..
As for your tips on error checking, I have already followed your advice on that too.. :)
The comment on the need of being read first before rewriting, I would think webrabbit was right, there doesn't seem to be a need of reading first.....

If I may..what's a &quot;dongle&quot;..?

Thanks again for all the help!!



 
Dongle = Hardware-Lock, (Zo'n ^%$#-ding tussen je printerpoort en de printerkabel waardoor b.v. Acad 12 (non-US) 't wel doet, c.q. beveiligd is, waardoor soms de printer aan moet staan om de software te laten zien dat de dongle erin zit...) (Sorry non-Dutchies ;-))

HTH
TonHu
 
From the NetExpress V4 LRM (and I beleive this is REQUIRED of any ANSI'85 conforming compiler)General Rules 12 and 13 for indexed files:

&quot;12) For a file in sequential access mode, the record to be replaced is specified by the value contained in the prime record key. When the REWRITE statement is executed, the value contained in the prime record data item of the record to be replaced must be equal to the value of the prime record key of the last record read from this file.

13) For a file in random or dynamic access mode, the record to be replaced is specified by the prime record key data item.&quot;

***

I also think that whether duplicate alternate record keys are or are not allowed DOES depend on the Select/Assign clause specification - for Micro Focus - like all other conforming compilers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top