sjrcreation wrote:Zio69 wrote:Unfortunately the array needs to be sorted by its key and no duplicates are allowed
hi Zio69 are you sure about the above..
with "older releases" (until 6.3-6.4) I'm 200% sure: if there's a duplicate or the tables aren't sorted you get a "A007 TABLE INPUT IS NOT IN SEQUENCE - file-name" error (see Reference Guide - Appendix B - Diagnostic). If you were talking about COBOL, then of course there's no
SYSTEM error... but try a SEARCH ALL on an array that is not in sequence and tell me what happens!
sjrcreation wrote:so what will be the best approach for this ??
As BillyBoyo said, Synchronized processing... something like:
SORT file1 TO VFILE1 USING sort-key1
SORT file2 TO VFILE2 USING sort-key2
*
JOB INPUT (VFILE1 KEY sort-key1 VFILE2 KEY sort-key2)
IF MATCHED
AMOUNT1 = AMOUNT1 + AMOUNT2
PUT output-file FROM VFILE1
ELSE
IF FILE1
PUT output-file FROM VFILE2
END-IF
END-IF
where VFILEn is a VIRTUAL file with the same layout as the corresponding "phisical" file. BTW, when 2 or more files have the same layout, you only need to code the fields int the FIRST file; afterwards you can code COPY. I.e.
FILE VFILE1 VIRTUAL F(xx)
COPY FILE1