I have already performed several tests, consulted manuals on COBOL and all the guidelines I found do not lead me to the intended objective. There is someone who can help. Thanks in advance.
Here is the code I am having problems with:
IDENTIFICATIONDIVISION.PROGRAM-ID.LARQSQIX.ENVIRONMENTDIVISION.CONFIGURATIONSECTION.REPOSITORY.FUNCTIONALLINTRINSIC.INPUT-OUTPUTSECTION.FILE-CONTROL.SELECTFD-VIRTUALASSIGNTO"FILESEI.DAT"ORGANIZATIONISINDEXEDACCESSISSEQUENTIALRECORDKEYISF001-EMPCODALTERNATEKEYISF003-DEPMTWITHDUPLICATESFILESTATUSISWS-PICK-ERRO.DATADIVISION.FILESECTION.FDFD-VIRTUAL.01FS-EMPREG.05F001-EMPCODPICX(09).05F002-NAMEPICX(40).05F003-DEPMTPIC99.WORKING-STORAGESECTION.77WS-PICK-ERROPICXX.LOCAL-STORAGESECTION.01TB-VIRTUAL.05TB-EMPREG.10LS-EMPCODPICX(09).10LS-NAMEPICX(40).10LS-DEPMTPIC99.77LS-ENTERPICX.77LS-ANSRPICAVALUE"Y".77LS-EOFPICXVALUE"F".PROCEDUREDIVISION.*Input:dataOPENEXTENDFD-VIRTUAL.IFWS-PICK-ERRO="35"OPENOUTPUTFD-VIRTUALEND-IFDISPLAY"EMPLOYEE REGISTRATION"DISPLAY"---------------------"IFWS-PICK-ERRO="00"PERFORMFOREVERDISPLAYX"0D"DISPLAY"Code ........: "WITHNOADVANCINGACCEPTLS-EMPCODDISPLAY"Name ........: "WITHNOADVANCINGACCEPTLS-NAMEDISPLAY"Department ..: "WITHNOADVANCINGACCEPTLS-DEPMTWRITEFS-EMPREGFROMTB-EMPREGINVALIDKEYDISPLAYX"0D"DISPLAY"Existing record."NOTINVALIDKEYDISPLAYX"0D"DISPLAY"Data registered successfully."END-WRITEDISPLAYX"0D"DISPLAY"More recors (Y) for YES "WITHNOADVANCINGDISPLAY"- any key for NOT: "WITHNOADVANCINGACCEPTLS-ANSRIFUPPER-CASE(LS-ANSR)NOT="Y"EXITPERFORMEND-IFEND-PERFORMEND-IF.CLOSEFD-VIRTUAL.*Outuput:dataDISPLAYLOW-VALUESOPENINPUTFD-VIRTUAL.PERFORMUNTILLS-EOF="T"MOVELS-DEPMTTOF003-DEPMTSTARTFD-VIRTUALINVALIDKEYCLOSEFD-VIRTUALSTOPRUNEND-STARTREADFD-VIRTUALATENDMOVE"T"TOLS-EOFEND-READMOVELS-DEPMTTOF003-DEPMTSTARTFD-VIRTUALKEYIS>F003-DEPMTEND-STARTREADFD-VIRTUALINTOTB-EMPREGATENDMOVE"T"TOLS-EOFNOTATENDWRITEFS-EMPREGFROMTB-EMPREGDISPLAYLS-DEPMT" - "LS-EMPCOD" - "LS-NAMEEND-READEND-PERFORMCLOSEFD-VIRTUAL.DISPLAYX"0D".DISPLAY"Press <ENTER> to finish... "WITHNOADVANCING.ACCEPTLS-ENTER.STOPRUN.900-MENSAGEMSECTION.DISPLAY"New search: (Y) for YES "WITHNOADVANCING.DISPLAY"- any key for NOT: "WITHNOADVANCING.ACCEPTLS-ANSR.EXIT.ENDPROGRAMLARQSQIX.
Use ACCESS IS DYNAMIC (Not Sequential)
OPEN I-O (not Extend)
Afte each file operation test the status code.
Test Ws-Pick-Errno after each file operation.
Doing so will enable you to ascertain what wrong, when.
I believe you have open input and will execute
WRITE FS-EMPREG FROM TB-EMPREG
That won't work
Test the status code
Last edit: Ralph Linkletter 2020-07-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ISAM sequential writes are certainly ok.
However I think that ISAM sequential writes require an ascending key sequence.
I may be wrong on that, but it sure makes a difference in load time for an ISAM file.
You need to routinely check status codes. That is almost a required practice.
I think you will see status code '02' indicating a duplicate entry in the alternate index.
That is ok. More or less informative. Only germane if duplicates are allowed in the alternate index.
Is your example program recursive ? That is does the program call itself ?
If not why the local storage ?
Ralph
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
One other reason to consider LOCAL-STORAGE: if the program leaves this memory is always de-allocated - that's quite useful if you don't need to preserve it during runs.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is no other reason. It is a personal custom that I have. I prefer to use local variables in any language I use or learn. But if this is not a good habit for COBOL I modify it and start using WORKING-STORAGE. I appreciate the guidance and note. In your experience, as I am new to COBOL, what better attitude?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is completely no bad habbit, just uncommon to many COBOLeros (and not compatible with old compilers).
My personal take: If the program is called very often: keep most in WORKING-STORAGE to prevent regular allocation/deallocation, as a general rule: for big data you don't need most of the time the program runs: use BASED variables with a manual ALLOCATE / FREE (= scope the variable's data allocation); but especially with COBOL you'll find a lot of different "tastes" and when working with COBOL often also have some local rules what do (not) do/use.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, this is implemented in GnuCOBOL since quite a long time.
Note: this doesn't do anything about the allocation though - you still would to have to do a CANCEL and run with COB_PHYSICAL_CANCEL=1 to free the memory on program exit.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello again.
I'm having a problem that I'm not able to solve. I want to separate a data group by category.
Reference: GnuCOBOL 2.0 with OpenCobolIDE 4.7.6.
If the file contains the data:
Should present:
But it presents
I have already performed several tests, consulted manuals on COBOL and all the guidelines I found do not lead me to the intended objective. There is someone who can help. Thanks in advance.
Here is the code I am having problems with:
Use ACCESS IS DYNAMIC (Not Sequential)
OPEN I-O (not Extend)
Afte each file operation test the status code.
Test Ws-Pick-Errno after each file operation.
Doing so will enable you to ascertain what wrong, when.
I believe you have open input and will execute
WRITE FS-EMPREG FROM TB-EMPREG
That won't work
Test the status code
Last edit: Ralph Linkletter 2020-07-01
I highly suggest to exchange the very outdated GnuCOBOL version from 2016.
To do so:
Hello, Simon Sobisch.
Thank you for your collaboration. Yes, I will do the update. At the moment, I still need to keep version 2.0 in use.
First of all thank you very much, Ralph Linkletter.
So it is not possible to do this type of operation with SEQUENTIAL? Interesting!!!
I may be mistaken, but this information is not very clear in the manuals.
ISAM sequential writes are certainly ok.
However I think that ISAM sequential writes require an ascending key sequence.
I may be wrong on that, but it sure makes a difference in load time for an ISAM file.
You need to routinely check status codes. That is almost a required practice.
I think you will see status code '02' indicating a duplicate entry in the alternate index.
That is ok. More or less informative. Only germane if duplicates are allowed in the alternate index.
Is your example program recursive ? That is does the program call itself ?
If not why the local storage ?
Ralph
Hello Ralph.
Thanks again. The program is not recursive. Local use is just a personal habit.
One other reason to consider
LOCAL-STORAGE: if the program leaves this memory is always de-allocated - that's quite useful if you don't need to preserve it during runs.Hello, Simon Sobisch.
There is no other reason. It is a personal custom that I have. I prefer to use local variables in any language I use or learn. But if this is not a good habit for COBOL I modify it and start using WORKING-STORAGE. I appreciate the guidance and note. In your experience, as I am new to COBOL, what better attitude?
It is completely no bad habbit, just uncommon to many COBOLeros (and not compatible with old compilers).
My personal take: If the program is called very often: keep most in
WORKING-STORAGEto prevent regular allocation/deallocation, as a general rule: for big data you don't need most of the time the program runs: useBASEDvariables with a manualALLOCATE/FREE(= scope the variable's data allocation); but especially with COBOL you'll find a lot of different "tastes" and when working with COBOL often also have some local rules what do (not) do/use.I will change this habit, even if it is not a bad thing. Thanks for the guidance and time dedicated to me.
As I said, I'm new to COBOL, I'm still a long way from being a COBOLero, but with the help of friendly people to get there.
Another way to always have the working-storage variables in their initial state with each run is to specify:
This works in other compilers (e.g. Realia COBOL),
I don't know if it has been implemented in GnuCOBOL or not yet.
Yes, this is implemented in GnuCOBOL since quite a long time.
Note: this doesn't do anything about the allocation though - you still would to have to do a
CANCELand run withCOB_PHYSICAL_CANCEL=1to free the memory on program exit.Hi, Simon.
Interesting!!!
Hello, Eugenio Di Lorenzo.
Thank you for this guidance. I consulted the GnuCOBOL 2.0 manual and the INITIAL clause is included in PROGRAM-ID.