I am new to COBOL. Can anyone tell me the program to compare two files (File 1 and File 2) and write matching records to a file (Outfile 1) and unmatched to another File (Outfile 2) in mainframe.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You could search-engine for "cobol two file match". Bear in mind, it is the internet, so there will be a fair amount of cr... variance in quality out there. If you find something you feel comfortable with, post the link or the code here, and we can comment :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to do a file SORT with INPUT PROCEDURE and OUTPUT PROCEDURE. In order to expedite testing I'm not using any files, except the Sort Work File itself. I'm trying to populate a Sort Record from an array of records, RELEASE each one in turn. When the SORT is complete, I want to display each sorted record to simplify checking the results. I'm having trpuble in connecting all the dots required for the sort process. Here's my code. See the comments, please.
DATADIVISION.FILESECTION.SD SORT-FILE.01 SORT-RECORD.03 SR-SEASONPIC 9.03 SR-IDPIC 999.03 DATA PIC X(34).PROCEDUREDIVISION.SETENVIRONMENT "TEMP"TO "C:\TEMP-FOLDER".*> My C:\TEMP-FOLDER EXISTS.SORT SORT-FILEON ASCENDINGKEY SR-SEASONASCENDINGKEY SR-IDINPUTPROCEDURE 0100-INPUTTHRU 0199-EXITOUTPUTPROCEDURE 0200-OUTPUTTHRU 0299-EXIT.0100-INPUT.*> PERFORM A LOOP TO POPULATE SORT-RECORD, *> THEN RELEASE IT TO THE SORT. RELEASE SORT-RECORD*> IGET:*> "error: permanent file error (status = 30) for file SORT-FILE*> ('SORT-FILE') on RELEASE.END-PERFORM.0199-EXIT.EXIT.0200-OUTPUT.MOVE 1 TO OUT-SUB.RETURN SORT-FILEINTO WS-COPY-TABLE(OUT-SUB)ATEND GOTO 0300-DISPLAYEND-RETURN.ADD 1 TO OUT-SUB.0299-EXIT.EXIT.
Prog Guide says I need to SET ENVIRONMENT for a temporary folder. I tried to use TMPDIR, then TMP, then TEMP with the same results, but I prefer to use my own folder. So, what works?
Last edit: Simon Sobisch 2020-08-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You've left out important parts of the program, so it's difficult to diagnose your problem. The error status 30 is probably complaining about the sort file name, which should have been defined something like:
If I recall, if the file name is invalid, or the file exists, but is incompatible with the access mode, you will get error status 30.
I also note that you have "at end go to 0300-display" following your return statement. If 0300-display is outside the scope of the perform (0200-output thru 0299-exit) your program will not work properly. NEVER use go to to leave the range of a perform loop.
Last edit: Simon Sobisch 2020-08-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2020-08-11
NEVER use go to to leave the range of a perform loop
That was one my my first lessons. Screws up all sorts of things.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2020-08-10
What I'm trying to resolve is the assignment of my choice of file name, i.e. "SORT-FILE", to a folder on the C-drive. I don't know whether I'm allowed to use my own file name or if I must use some reserved word file name (undocumented). I understand INPUT-OUTPUT SECTION & FILE-CONTROL precede the SELECT statement. Also, I've used ASSIGN TO EXTERNAL DISK with a full drive\folder\filename.extension successfully in the past(without the need for "jcl"); but this is the first time I've tried to use SORT file.
Now that we're past that, I take it that setting a TEMP variable in the Evironment is a way to communicate to the SORT where to create the work file (which I'm trying to specify). If that's true, then I don't uinderstand why "jcl" should be involved. Please illuminate.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You've still left out the information we need to answer your question.
The "Select" statement specifies the (path and) name of the file, or an environmental variable that can be set to that name, or a data item that can be set to that name. What do you have in your select statement?
"SORT-FILE" is the name that you reference in the COBOL program for OPEN, READ, and CLOSE statements, NOT the name of the physical file.
If you code the select statement EXACTLY as I've shown above, and include the "Set" statement EXACTLY as shown above in the bat/cmd file that runs the program, your program should work (assuming it is otherwise sound). Alternately you can change "SRTWORK" to whatever you choose in both the program and bat/cmd file, and it should still work.
You can also omit the set statement, and it should create a sort work file by that name (i.e. SRTWORK) in the default path.
Setting an environmental variable is "jcl".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Note that the source (input file) for the sort is not that large 5 Mb and the in and out files are similar. There is no working files present after the program finishes.
There is no JCL for micros based computers under Windows or Linux that help control usage of file processing well not unless you wish to make a drive or similar online say via a tape cartridge.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"Keep it simple". I agree, which is why I wonder why you find all that code necessary, instead of the two lines of code (select and set) shown above that work for me in every Cobol program using a sort file.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to avoid adding elements outside the source file. I want the user to compile the program and run it. So I'm learning I need to take Linux/Unix into consideration, as well. I' m just an unwashed Windosian with 40+ yrs financial applications experience on mainframes, mostly. When somebody says "JCL" my mind freezes over.
Anyhow, I've tried various approaches to the problem and it persists. If it's any help. I'm using GnuCOBOL 3.1-rel candidate on Windows-10. I'll try to attach my source file (.txt) in Landscape mode.
Once again, you have not provided enough information to solve your problem. I tried to compile your program, so I could see what was happening, and advise you how to fix the error. The program file you gave us has multiple errors that will prevent compilation, and is missing various needed data definitions.
Once you make all the changes needed for a clean compile, I suggest that you put a display at (what is now) line 44, and you will probably discover that SORTWK does not contain what you think it does (assuming it even exists, because you haven't defined it). Furthermore, it is NOT the same as SORT-WK, which is what the file open routine will be looking for, according to the code you now have. (Note that, when you use "STRING", you have to clear the unused part of the data field first, because it will not be space filled. That may be you problem (besides a program that won't compile)).
I'm not sure what you are trying to do. Simply say "SELECT SORT-FILE ASSIGN TO "SORTWK", and let the program create SORTWK in the default directory. (It's only a temporary file, so why worry abut the directory?) Or point the select statement to a working-storage variable, and create a proper path name. It isn't that complicated.
How did you use mainframes for 40 years without using JCL (or batch or command files, as they are called in Windoze)?
Last edit: cdg 2020-08-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I had to use JCL on the mainframes. Yes, I had to use bat files in DOS. I don't remember much about either of them, frankly. It's a relief.
Anyhow, I straightened myself out and I managed to get past the RELEASE problem. I followed Vincent's suggestion. That's a relief, too.
Now I have a problem with the OUTPUT procedure. Looks like I'm getting back only the second half of the sorted file. When something like that happened on a mainframe it usually meant the record/blocking factors were wonky. My counters show me that all the records were RELEASED in the INPUT procedure.
If I can't dope this out tomorrow I'll send the whole .cbl file and you can check out this weekend.
And thanks to you both for your patience and your help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry to take so much time getting back to you. Family activity over the weekend, won't you know. Anyhow, all problems solved. Both methods of ASSIGNing file names (DISK or symbolic filename populated with drive:\path\filename.ext) are successful. The symbolic method would be useful when ACCEPTing an ASSIGNment from the user at runtime. Amazingly, I found an example of SORT in the Programmer's Guide. Can you find it? I've attached the source file. It's Free Format. Landscape format works best with Notepad. Thanks, everyone, for your patience and your priceless assistance. 'Til next time.
View and moderate all "Help getting started" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
I am new to COBOL. Can anyone tell me the program to compare two files (File 1 and File 2) and write matching records to a file (Outfile 1) and unmatched to another File (Outfile 2) in mainframe.
See attached.
You could search-engine for "cobol two file match". Bear in mind, it is the internet, so there will be a fair amount of cr... variance in quality out there. If you find something you feel comfortable with, post the link or the code here, and we can comment :-)
I'm trying to do a file SORT with INPUT PROCEDURE and OUTPUT PROCEDURE. In order to expedite testing I'm not using any files, except the Sort Work File itself. I'm trying to populate a Sort Record from an array of records, RELEASE each one in turn. When the SORT is complete, I want to display each sorted record to simplify checking the results. I'm having trpuble in connecting all the dots required for the sort process. Here's my code. See the comments, please.
Prog Guide says I need to
SET ENVIRONMENT
for a temporary folder. I tried to useTMPDIR
, thenTMP
, thenTEMP
with the same results, but I prefer to use my own folder. So, what works?Last edit: Simon Sobisch 2020-08-11
You've left out important parts of the program, so it's difficult to diagnose your problem. The error status 30 is probably complaining about the sort file name, which should have been defined something like:
with something like the following in your "jcl":
If I recall, if the file name is invalid, or the file exists, but is incompatible with the access mode, you will get error status 30.
I also note that you have "at end go to 0300-display" following your return statement. If 0300-display is outside the scope of the perform (0200-output thru 0299-exit) your program will not work properly. NEVER use
go to
to leave the range of a perform loop.Last edit: Simon Sobisch 2020-08-11
That was one my my first lessons. Screws up all sorts of things.
What I'm trying to resolve is the assignment of my choice of file name, i.e. "SORT-FILE", to a folder on the C-drive. I don't know whether I'm allowed to use my own file name or if I must use some reserved word file name (undocumented). I understand INPUT-OUTPUT SECTION & FILE-CONTROL precede the SELECT statement. Also, I've used ASSIGN TO EXTERNAL DISK with a full drive\folder\filename.extension successfully in the past(without the need for "jcl"); but this is the first time I've tried to use SORT file.
Now that we're past that, I take it that setting a TEMP variable in the Evironment is a way to communicate to the SORT where to create the work file (which I'm trying to specify). If that's true, then I don't uinderstand why "jcl" should be involved. Please illuminate.
You've still left out the information we need to answer your question.
The "Select" statement specifies the (path and) name of the file, or an environmental variable that can be set to that name, or a data item that can be set to that name. What do you have in your select statement?
"SORT-FILE" is the name that you reference in the COBOL program for OPEN, READ, and CLOSE statements, NOT the name of the physical file.
If you code the select statement EXACTLY as I've shown above, and include the "Set" statement EXACTLY as shown above in the bat/cmd file that runs the program, your program should work (assuming it is otherwise sound). Alternately you can change "SRTWORK" to whatever you choose in both the program and bat/cmd file, and it should still work.
You can also omit the set statement, and it should create a sort work file by that name (i.e. SRTWORK) in the default path.
Setting an environmental variable is "jcl".
In most of my sort processes within a Cobol program I use my defaults as set up in .bashrc
This shows :
export TMPDIR=~/tmp
there is also a export TMP=/tmp
In th sort file settings it is :
*>
In PD for this file I have :
Where both in and out files are defined. There are many other sorts but most of these are table sorts as a JIC as they should be already but . . .
.Now just after program start I have :
Note that the source (input file) for the sort is not that large 5 Mb and the in and out files are similar. There is no working files present after the program finishes.
There is no JCL for micros based computers under Windows or Linux that help control usage of file processing well not unless you wish to make a drive or similar online say via a tape cartridge.
The last point don't make things more complex than needed i.e., stick to the KISS methodology.
Because the program is multi platform.
I think the easiest way is to setup the file name via environment (outside of the COBOL program) in this case. This leaves all the setup external.
I'm trying to avoid adding elements outside the source file. I want the user to compile the program and run it. So I'm learning I need to take Linux/Unix into consideration, as well. I' m just an unwashed Windosian with 40+ yrs financial applications experience on mainframes, mostly. When somebody says "JCL" my mind freezes over.
Anyhow, I've tried various approaches to the problem and it persists. If it's any help. I'm using GnuCOBOL 3.1-rel candidate on Windows-10. I'll try to attach my source file (.txt) in Landscape mode.
Once again, you have not provided enough information to solve your problem. I tried to compile your program, so I could see what was happening, and advise you how to fix the error. The program file you gave us has multiple errors that will prevent compilation, and is missing various needed data definitions.
Once you make all the changes needed for a clean compile, I suggest that you put a display at (what is now) line 44, and you will probably discover that SORTWK does not contain what you think it does (assuming it even exists, because you haven't defined it). Furthermore, it is NOT the same as SORT-WK, which is what the file open routine will be looking for, according to the code you now have. (Note that, when you use "STRING", you have to clear the unused part of the data field first, because it will not be space filled. That may be you problem (besides a program that won't compile)).
I'm not sure what you are trying to do. Simply say "SELECT SORT-FILE ASSIGN TO "SORTWK", and let the program create SORTWK in the default directory. (It's only a temporary file, so why worry abut the directory?) Or point the select statement to a working-storage variable, and create a proper path name. It isn't that complicated.
How did you use mainframes for 40 years without using JCL (or batch or command files, as they are called in Windoze)?
Last edit: cdg 2020-08-13
Yes, I had to use JCL on the mainframes. Yes, I had to use bat files in DOS. I don't remember much about either of them, frankly. It's a relief.
Anyhow, I straightened myself out and I managed to get past the RELEASE problem. I followed Vincent's suggestion. That's a relief, too.
Now I have a problem with the OUTPUT procedure. Looks like I'm getting back only the second half of the sorted file. When something like that happened on a mainframe it usually meant the record/blocking factors were wonky. My counters show me that all the records were RELEASED in the INPUT procedure.
If I can't dope this out tomorrow I'll send the whole .cbl file and you can check out this weekend.
And thanks to you both for your patience and your help.
Sorry to take so much time getting back to you. Family activity over the weekend, won't you know. Anyhow, all problems solved. Both methods of ASSIGNing file names (DISK or symbolic filename populated with drive:\path\filename.ext) are successful. The symbolic method would be useful when ACCEPTing an ASSIGNment from the user at runtime. Amazingly, I found an example of SORT in the Programmer's Guide. Can you find it? I've attached the source file. It's Free Format. Landscape format works best with Notepad. Thanks, everyone, for your patience and your priceless assistance. 'Til next time.