Large File merging with condition

I have 3 files . 2 files have millions of records.These 2 files have one ( empnumber) common record field. i want to put those records in 3rd file , such that which records having same number in key field (empnumber)in these two files ?

Showing Answers 1 - 27 of 27 Answers

Rams

  • Nov 11th, 2005
 

Hello,

Please follow the below steps.

Step 1 : Sort file1 and file2 based on empnumber

Step 2 : Write a program such that the program logic should compare the empnumber of both sorted-files and for matching empnumbers write the corresponding records into third file

Note : This is the one of the ways you can meet the solution. Thanks.

  Was this answer useful?  Yes

Abhishek Ule

  • Nov 15th, 2005
 

This can be done by IBM utility ICETOOL

  Was this answer useful?  Yes

vishnu kumar gupta

  • Nov 13th, 2006
 

I think this can be achieved by include or exclude conditional statement in A JCL itself.

  Was this answer useful?  Yes

ajayre

  • Jul 9th, 2007
 

HI ,This can be done in the same JCL .1.Sort first two files and then merge both the records based on EMPNUMBER ok. For Merging of Two Datasets they should have same Record length as Well as Same Record Format and more over the Records in Both Datasets Should be Sorted prior to Merge.If we take same Record Structure as an Example if Two data sets with above record format are to be MERGED then SORT CARD Should look as MERGE FIELDS=( starting position,length, A (asending/des),),FORMAT=CH OUTREC FIELDS=(,same as above) now all matched records will be written into third file. OR If the format is different etc....Ex 1: record one lokks like name salary accno empnumber ajaykumar 20000 12345 23456 Record 2: name empnumber salary department ..... rajesh 23546 10,000 .........inthese case at the time of sorting both files use the below code and write into onother file sortfields=copy . out fileds = ( empnumber position and length from the input record and then remaining record .....)In this outrec field you can give any filed first ,, based on the order which you specified record will be written in to the out file.the first record shoud be like : out rec=(empnu start,length ,type, name ,-----------------------, salr.................................) here you need to give position and length okIn the same manner write the second recod in to onother file as first filed shound be empnumber .now you can merge both records and then write in to second file .Still if you have any doubts let me know .2.If format and length or different then you need write a program like below .read both files and move to working storage variables and the match it and write in to third record

  Was this answer useful?  Yes

We can achieve this by using the Sort Join (in a JCL). The following steps in a sort card will move all the records from the two files having the same emp no into the third file:
STEP001    SORT
SORTNJF1   DD DSN=INPUT1,DISP=SHR

SORTNJF2   DD DSN=INPUT2,DISP=SHR


SORTOF1    DD DSN=OUTPUT1,DISP=(NEW,CATLG,DELETE)

SYSIN DD *
JOINKEYS FILE1 = (1,3,CH) --Assuming emp no is of len 3,starting in position 1 of file1

JOINKEYS FILE2 = (1,3,CH) --Assuming emp no is of len 3,starting in position 1 of file2


REFORMAT FIELDS = (F1:1,100,F2:4,50) -- copies the rcords from both the input files into the output (from pos 1 of i/p file1 and position 4 of i/p file2
SORT FIELDS = (1,3,CH,A)  -- sorts the output file based on the empno

OUTFIL FILES = 1
/*

  Was this answer useful?  Yes

subrahmanyam.b

  • Nov 16th, 2007
 

Hi abhishek,

As per ur coments this can be solved by ICETOOL,
Can you please explain with more details to resolve this problem by ICETOOL.

Thanks
subbu

  Was this answer useful?  Yes

Try


PROCEDURE DIVISION.
       OPEN INPUT FILE1, FILE2.
       DISPLAY FS1, FS2.
       OPEN OUTPUT FILE3.
       DISPLAY FS3.
       PERFORM UNTIL EOF = 'YES'
       READ FILE1 AT END MOVE 'YES' TO EOF
                              PERFORM CLOSE-PARA
       NOT AT END
       READ FILE2 AT END MOVE 'YES' TO EOF
                              PERFORM CLOSE-PARA 
       NOT AT END
       IF  EMPNO1 = EMPNO2
       MOVE
             REC1 TO REC3
             WRITE REC3
       MOVE
              REC2  TO REC3
             WRITE REC3
       END-PERFORM.
CLOSE-PARA.
        CLOSE FILE1, FILE2, FILE3.
        STOP RUN.

  Was this answer useful?  Yes

depak_83

  • Jul 16th, 2008
 

You can use the bleow sort card in your JCL

//SYSIN    DD   *                 
  MERGE FIELDS=(21,11,A),FORMAT=BI
  SUM FIELDS=NONE                 
/*                                                  

21 - Starting position of the EMP field
11- is the length of the field.

This would merge the 2 files based on the EMP number into the 3rd file

  Was this answer useful?  Yes

AJAY KUMAR ANDE

  • Aug 23rd, 2011
 

Using cobol we can perform

TAKE TWO INPUT FILES, AND ONE OUTPUT FILE, READ TWO FILES, APPLY 'IF' CONDITION ,IF IT MATCHES WRITE INTO OUTPUT FILE.

Code
  1. fd in-file1

  2.  01 rec1

  3.   02 si-no1 pic x(4)

  4.   02 name pic x(10)

  5.  

  6. fd in-file2

  7.  01 rec2

  8.   02 si-no2 pic x(4)

  9.   02 des pic x(5)

  10.   02 sal pic x(6)

  11.  

  12. fd out-file

  13.  01 rec3

  14.   02 x pic x(80)

  15.  

  16. fd remaining-file

  17.  01 rec4

  18.   02 x pic x(80)

  19.  

  20. proceure division

  21. open input in-file1

  22. open input in-file2

  23. open output out-file

  24.  

  25. read rec1

  26. read rec2

  27.  

  28. if si-no1 = si-no2

  29. write rec3

  30. else write rec4

  Was this answer useful?  Yes

Jitendra Kumar Rathour

  • Oct 17th, 2011
 

it will be done by the ICETOOL and the DFSORT...............

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions