My req is to compare the INFILE3 and INFILE4 and generate the output file OUTFIL2 when there are any inserts/updates happened in the INFILE3.
Code:
FILE INFILE3
IN-RECORD-1 01 30082 A
IN-PDF-UPN1 01 09 N
IN-PDF-MEM-OF-UPN1 11 09 N
IN-PDF-BU1 21 40 A
IN-PDF-PRI-PROD-CD1 62 20 A
IN-PDF-PROD-CODE1 83 30000 A
FILE INFILE4
IN-RECORD-2 01 30082 A
IN-PDF-UPN2 01 09 N
IN-PDF-MEM-OF-UPN2 11 09 N
IN-PDF-BU2 21 40 A
IN-PDF-PRI-PROD-CD2 62 20 A
IN-PDF-PROD-CODE2 83 30000 A
FILE OUTFIL2
OUT-RECORD 01 30084 A
OUT-PDF-UPN 01 09 N
OUT-PDF-FILLER-1 10 01 A
OUT-PDF-MEM-OF-UPN 11 09 N
OUT-PDF-FILLER-2 20 01 A
OUT-PDF-BU 21 40 A
OUT-PDF-FILLER-3 61 01 A
OUT-PDF-PRI-PROD-CD 62 20 A
OUT-PDF-FILLER-4 82 01 A
OUT-PDF-PROD-CODE 83 30000 A
OUT-PDF-UPDATE-FLAG 30082 02 A
FILE SORT3 F 30082 VIRTUAL
ST-PDF-UPN1 01 09 N
ST-PDF-MEM-OF-UPN1 11 09 N
ST-PDF-BU1 21 40 A
ST-PDF-PRI-PROD-CD1 62 20 A
ST-PDF-PROD-CODE1 83 30000 A
*
FILE SORT4 F 30082 VIRTUAL
ST-PDF-UPN2 01 09 N
ST-PDF-MEM-OF-UPN2 11 09 N
ST-PDF-BU2 21 40 A
ST-PDF-PRI-PROD-CD2 62 20 A
ST-PDF-PROD-CODE2 83 30000 A
SORT INFILE3 TO SORT3 USING (IN-PDF-UPN1, IN-PDF-MEM-OF-UPN1, +
IN-PDF-BU1)
SORT INFILE4 TO SORT4 USING (IN-PDF-UPN2, IN-PDF-MEM-OF-UPN2, +
IN-PDF-BU2)
JOB INPUT (SORT3 KEY(ST-PDF-UPN1, ST-PDF-MEM-OF-UPN1, +
ST-PDF-BU1), +
SORT4 KEY(ST-PDF-UPN2, ST-PDF-MEM-OF-UPN2, +
ST-PDF-BU2))
IF MATCHED
IF (ST-PDF-UPN1 = ST-PDF-UPN2) AND +
(ST-PDF-MEM-OF-UPN1 = ST-PDF-MEM-OF-UPN2) AND +
(ST-PDF-BU1 = ST-PDF-BU2) AND +
(ST-PDF-PRI-PROD-CD1 = ST-PDF-PRI-PROD-CD2) AND +
(ST-PDF-PROD-CODE1 = ST-PDF-PROD-CODE2)
The issue here is the fields OUT-PDF-PRI-PROD-CD , OUT-PDF-PROD-CODE are not getting populated correctly when the successive records are read. Since these are not initialized after each successive fetch the output OUTFIL2 values overriden in the fileds OUT-PDF-PRI-PROD-CD , OUT-PDF-PROD-CODE. pls help to get this fixed.
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
Hello,
When posting code and/or jcl and/or data, use copy/paste and the code tag to preserve alignment and improve readability. Your code was "Code'd" but did not align because you added spaces manually. There is a Preview feature so you can see your post as it will appear to the forum. When the post appears as you want, Submit.
You need to post some sample data from the input files and the output that is happening now. You also need to post the expected output when the sample data is processed.
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
Code:
IF MATCHED
IF (ST-PDF-UPN1 = ST-PDF-UPN2) AND +
(ST-PDF-MEM-OF-UPN1 = ST-PDF-MEM-OF-UPN2) AND +
(ST-PDF-BU1 = ST-PDF-BU2) AND +
(ST-PDF-PRI-PROD-CD1 = ST-PDF-PRI-PROD-CD2) AND +
(ST-PDF-PROD-CODE1 = ST-PDF-PROD-CODE2)
The first 3 compares are part of your match keys, why dont you
make the other 2 compares also part of your match keys?
Then you could do something like :
Code:
IF MATCHED
END-IF
IF NOT SORT3
END-IF
IF NOT SORT4
END-IF
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
Thirumurgann wrote:
Hi,
I could nt use the other two fileds as keys since thier record length exceeds 255.
Thanks,
Thiru
Of course, overlooked that.
Beside in case of a match you only have to compare the last 2 fields
for a record match. But because you cannot sort on the large field
how can you guarantee that there will be any match.
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
Hello,
Quote:
I will take care going forward.
The Code tag should also be used for data and jcl. I'm not sure exactly how your most recent post is supposed to line up and i deleted the duplicate. . .
Quote:
This could be implemented in easytrieve???
Unless i've misunderstood the requirement this should be doable with Easytrieve.
If you actually write the match code (rather than using the builtin feature) you may have more success. Done properly, this looks like a normal 2-file match/merge exercise.
The input and the output files have record length greater than 30,000.
Thats what made me complex to handle. since i could nt sort all the 5 fields present in the file. Just i am handling the record with first 3 fields as key. Then what happen's is the record's fectched in to the host variables are being overlapped in the second fetch. I tried to initialize the host variable's
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
A010 INVALID FILE REFERENCE - SORT3
That occurs if there is no match and SORT4 is the active file.
So you can do the following :
Code:
IF MATCHED
compare the 2 fields not belonging to the keys
do some processing if equal
do some processing if not equal
END-IF
IF SORT3
do some processing with the SORT3 fields
END-IF
IF SORT4
do some processing with the SORT4 fields
END-IF
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Thirumurgann wrote:
Hi Dick,
The input and the output files have record length greater than 30,000.
Thats what made me complex to handle. since i could nt sort all the 5 fields present in the file. Just i am handling the record with first 3 fields as key. Then what happen's is the record's fectched in to the host variables are being overlapped in the second fetch. I tried to initialize the host variable's
But it dint work. I am getting
A010 INVALID FILE REFERENCE - SORT3
Then i tried with initializing the output fields after every record fetch. I dint get any compilation errors and still i get the records overridden.
Thanks,
Thiru
Thiru,
There is no sign of DB2 anywhere in your program. You are using non-database files. Files have records. You do not use "host variables". You do not "fetch".
The length of the record is giving you problems, and you are using your DASD very inefficiently. What is the "design" reason behind this?
All the initialisation you show above is unnecessary. The fields you initiliase are the target of an assignment, so previous contents are absolutely irrelevant.
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
Hello,
How many records does each input file have?
It appears that the 30k fields are not part of the match, but rather are just along for the ride so they shouldnot add to the complexity of the match.
Is there some reason the choice was made to do all of the sorting within the Easytrieve code? This is is a very bad choice for other than small files. . .
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
This will get you a VIRTUAL file with variable length records. You don't need to specify blocking for a virtual file - if my memory is holding-up on this.
[code]FILE SORT3 V 30082 VIRTUAL[/cod]
That is not the end of your problem.
Now your file is variable, but your data definition is not, and if you use that definition you will be looking "beyond the end of the record".
What about your output files? Are they variable? If so, what about your update/insert indicator which is stuck way down the end of the record.
To either proceed with an Easytrieve solution or start with a SORT one, we need answers to the questions already asked.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
I can elaborate on the problem, at least. Sort of, because we are still short of answers....
You are matching two files.
If the records are identical, you ignore them.
If the keys are the same but the data not, you extract the "latest" with an indicator saying "Update".
If the keys do not match, and it is the "latest" you extract with an indicator saying "Insert".
The "data" part of your record is variable in length (making the who record variable in length).
Your first problem is what to do with the Update/Insert marker. You are putting it after the variable part of the record, either forcing the record to a maximum, or making you use a different method to ensure it is located after the existing data (and making your output record longer by two bytes).
To do your comparison, you must ensure that you only compare data that is actually within your record.
Easytrieve now supports variable-length fields. You'll have to look that up.
Easytrieve will also use the current record on a file, with the correct length, when you use the "filename" - like MOVE filename TO a data-name or another-filename. Or IF filename EQ another-filename.
Look at the manual for RECORD-LENGTH for how to set and extend your output lenghts for a variable-length record.
This will move current record of SORTF3 to record-area for OUTFIL2.
Code:
MOVE SORTF3 TO OUTFIL2
This will rest the entire record on SORTF3 against the entire record on SORTF4.
Code:
IF SORTF3 EQ SORFT4
For a variable output file you need to set the record-length.
Special thanks to you guys...When i am clu less BILL and Dick helped me a lot to complete this deliverable on the time. BILL patiently explained me. Hats off BILL.... You rock...
Thanks,
Thiru
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Thiru, I'm glad it helped.
Please take the time it has saved you to fully understand the code you have. Document as necessary. When one of your colleagues picks up the code next time, they need to know what is going on.
seagull wrote:
It looks to me like the best option is to put the SORT into a separate step ahead of the easytrieve, and then code the match logic yourself.
It would be possible, I'm sure, for the full solution to be done with a SORT/xxxTOOL.
With no duplicates on either file, the Easytrieve file matching is a simple process. The problem was in how to compare variable-length data.
Although I am one for KISS, and would not myself code an "internal SORT" in Cobol, Easytrieve handles things differently. Each SORT and JOB is a seperate entity, which can share file definitions and "working storage" definitions. The Easytrieve "Virtual File Manager" provides a convenient method of defining and using "temporary" files, and even tables for binary searches. If the VIRTUAL file can be fitted into memory, it will be. This means you can define a load of temporary files to simplify the processing without having to include them in the JCL.
The Easytrieve SORT just uses the installed SORT product. With no record selection, it will run fairly well, though I don't know who is handling the IO for the input file (for the VIRTUAL, it is obviously Easytrieve).
For the solution, either "as is" in Easytrieve, or one with SORT/xxxTOOL. If the input files are "big", I would do the sorts seperately for the Easytrieve.