by nosource » Fri Aug 28, 2009 9:48 pm
Not sure if you've solved this problem. If not, how about a slightly different design? I'd suggest using the automatic file synchronization.
Because sync processing needs the input files in the same sequence...
Read your INFILE file and output the record 'as is' Plus add one field, either at the beginning or end, where you put in a sequence number.
JOB INPUT INFILE
MOVE ' ' TO OUT-REC FILL X'40'. * clear output record
OUT-REC-PART1 = IN-REC
OUT-SEQ-NBR = INFILE:RECORD-COUNT
PUT OUTFILE
GO TO JOB
If your Master file is not sorted by CUST-ID... Define a VIRTUAL one (next to all of the other FILE stmts) and SORT it...
*----------------------------------------------------------------------*
* VIRTUAL MASTER FILE *
*----------------------------------------------------------------------*
FILE MSTRTEMP F 512 VIRTUAL
COPY MSTRFILE. * AUTOMATICALLY USES THE SAME LAYOUT AS MSTRFILE WITHOUT RECODING
SORT MSTRFILE TO MSTRTEMP USING (MSTR-CUST-ID)
Sort the OUTFILE (from above)... output will overlay itself.
SORT OUTFILE TO OUTFILE USING (OUT-CUST-ID)
Synchronize process the files...
JOB INPUT (OUTFILE KEY (OUT-CUST-ID) +
MSTRTEMP KEY (MSTR-CUST-ID) +
) +
START INIT-PROC +
FINISH TERM-PROC
IF MATCHED
OUT-CUST-ID = MSTRTEMP:MSTR-CUST-ID. * you have to qualify the MSTR-CUST-ID since it's defined in two FILEs.
END-IF
OUTFILE2-REC = OUTFILE-REC
PUT OUTFILE2-REC
GO TO JOB
Resort the resulting OUTFILE2 file by SEQ-NBR (your requirement was to have the resulting file the same sequence as it started out in)
SORT OUTFILE 2TO OUTFILE2 USING (OUT-SEQ-NBR)
Strip off the SEQ-NBR
JOB INPUT OUTFILE2
MOVE ' ' TO OUT2-REC FILL X'40'
OUT2-REC-PART1 = OUTFINAL-REC
PUT OUTFINAL
GO TO JOB
Hope this helps.