Hello again.
I want to express my thanks to everyone for the help previously given to me. As you know, I am learning COBOL alone, reading books and manuals and taking some questions with you. Despite my efforts, there are times when I cannot resolve small details and I resort to some form of assistance.
I am using the OpenCobolIDE 4.7.6 environment on Windows 10 with GnuCOBOL updated to version 3.1-rc1.0.
The program to follow when in SEQUENTIAL mode reports success in recording the record in the created file, but when in RANDOM mode it informs that the record already exists and returns error code 24. What am I doing wrong?
IDENTIFICATIONDIVISION.PROGRAM-ID.FILEMNGR.ENVIRONMENTDIVISION.CONFIGURATIONSECTION.INPUT-OUTPUTSECTION.FILE-CONTROL.SELECTFD-FILEINASSIGNTO"FILERAN.DTR"ORGANIZATIONISRELATIVEACCESSMODEISRANDOMRELATIVEKEYISWS-NUM-REGFILESTATUSISWS-GET-ERROR.DATADIVISION.FILESECTION.FDFD-FILEIN.01FS-CADFUN.05F001-CODFUNPICX(09).05F002-NAMEPICX(40).WORKING-STORAGESECTION.01TB-VIRTUAL.05TB-CADFUN.10LS-CODFUNPICX(09).10LS-NAMEPICX(40).77WS-GET-ERRORPICXX.77WS-NUM-REGPIC9(4).77WS-ANSPICAVALUE"Y".PROCEDUREDIVISION.OPENOUTPUTFD-FILEINDISPLAY"DATA INPUT"DISPLAY"----------"IFWS-GET-ERROR="00"PERFORMFOREVERDISPLAYX"0D"DISPLAY"Code ID .: "WITHNOADVANCINGACCEPTLS-CODFUNDISPLAY"Name ....: "WITHNOADVANCINGACCEPTLS-NAMEWRITEFS-CADFUNFROMTB-CADFUNINVALIDKEYDISPLAYX"0D"DISPLAY"ERROR CODE: "WS-GET-ERRORDISPLAY"Existing record."NOTINVALIDKEYDISPLAYX"0D"DISPLAY"Successfully registered."END-WRITEDISPLAYX"0D"DISPLAY"More data? (Y) for YES: "WITHNOADVANCINGACCEPTWS-ANSIFFUNCTIONUPPER-CASE(WS-ANS)NOT="Y"EXITPERFORMEND-IFEND-PERFORMEND-IF.CLOSEFD-FILEIN.STOPRUN.ENDPROGRAMFILEMNGR.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Where are you creating the keyed value in WS-NUM-REG ?
Vince
On 13/07/2020 12:12, Augusto Manzano wrote:
Hello again.
I want to express my thanks to everyone for the help previously given
to me. As you know, I am learning COBOL alone, reading books and
manuals and taking some questions with you. Despite my efforts, there
are times when I cannot resolve small details and I resort to some
form of assistance.
I am using the OpenCobolIDE 4.7.6 environment on Windows 10 with
GnuCOBOL updated to version 3.1-rc1.0.
The program to follow when in SEQUENTIAL mode reports success in
recording the record in the created file, but when in RANDOM mode it
informs that the record already exists and returns error code 24. What
am I doing wrong?
IDENTIFICATIONDIVISION.PROGRAM-ID.FILEMNGR.ENVIRONMENTDIVISION.CONFIGURATIONSECTION.INPUT-OUTPUTSECTION.FILE-CONTROL.SELECTFD-FILEINASSIGNTO"FILERAN.DTR"ORGANIZATIONISRELATIVEACCESSMODEISRANDOMRELATIVEKEYISWS-NUM-REGFILESTATUSISWS-GET-ERROR.DATADIVISION.FILESECTION.FDFD-FILEIN.01FS-CADFUN.05F001-CODFUNPICX(09).05F002-NAMEPICX(40).WORKING-STORAGESECTION.01TB-VIRTUAL.05TB-CADFUN.10LS-CODFUNPICX(09).10LS-NAMEPICX(40).77WS-GET-ERRORPICXX.77WS-NUM-REGPIC9(4).77WS-ANSPICAVALUE"Y".PROCEDUREDIVISION.OPENOUTPUTFD-FILEINDISPLAY"DATA INPUT"DISPLAY"----------"IFWS-GET-ERROR="00"PERFORMFOREVERDISPLAYX"0D"DISPLAY"Code ID .: "WITHNOADVANCINGACCEPTLS-CODFUNDISPLAY"Name ....: "WITHNOADVANCINGACCEPTLS-NAMEWRITEFS-CADFUNFROMTB-CADFUNINVALIDKEYDISPLAYX"0D"DISPLAY"ERROR CODE: "WS-GET-ERRORDISPLAY"Existing record."NOTINVALIDKEYDISPLAYX"0D"DISPLAY"Successfully registered."END-WRITEDISPLAYX"0D"DISPLAY"More data? (Y) for YES: "WITHNOADVANCINGACCEPTWS-ANSIFFUNCTIONUPPER-CASE(WS-ANS)NOT="Y"EXITPERFORMEND-IFEND-PERFORMEND-IF.CLOSEFD-FILEIN.STOPRUN.ENDPROGRAMFILEMNGR.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello again.
I want to express my thanks to everyone for the help previously given to me. As you know, I am learning COBOL alone, reading books and manuals and taking some questions with you. Despite my efforts, there are times when I cannot resolve small details and I resort to some form of assistance.
I am using the OpenCobolIDE 4.7.6 environment on Windows 10 with GnuCOBOL updated to version 3.1-rc1.0.
The program to follow when in SEQUENTIAL mode reports success in recording the record in the created file, but when in RANDOM mode it informs that the record already exists and returns error code 24. What am I doing wrong?
Where are you creating the keyed value in WS-NUM-REG ?
Vince
On 13/07/2020 12:12, Augusto Manzano wrote:
Hi, thanks for the feedback.
That's my question, too. I've been researching and looking for examples of use for days. And I can't find any information to clarify.
I am learning COBOL on my own and sometimes I feel frustrated at not being able to see examples of using file access and manipulation techniques.
Change definition to :
77 WS-NUM-REG PIC 9(4) value zero.
BEFORE writing the record out do :
add 1 to WS-Num-Reg.
That will fix it assuming you really want a random type key as against a ISAM one.
Hello, Vicent.
Thank you very much for your time, assistance and clarification. It helped a lot.
Here it is working.