Skip to main content

Match_merge_logic

MATCH - MERGE     LOGIC

 

Match Merge logic is extensively used in COBOL programs to compare the data in two sequential files effectively. Only pre-requisite to for using this logic is, all input files to be in Sorted Order

 

Problem : I have 2 Sequential files File1  and File2.

                 If Record exists in both the files then write data into FILEA             

                 If Record exists only in File1 and not in File2 then write data into FILEB

                 If Record exists only in File2 and not in File1 then write data into FILEC

 

Solution: The effective way of solving above problem is, by using Match Merge Logic. Only pre-requisite to for using this logic is, all input files to be in Sorted Order.  First step sort I/P file

 

Explanation of Logic : Below listed are I/P and Output files data for say RollNo

 

File1                  File2                         FILEA                     FILEB                              FILEC

10                      10                               10                                

20                      20                               20

30                      50                                                               30

50                      60                               50                                                                     60

70                      99                                                                70

90                                                                                          90                                    99

 

         Open FILE1 and 2 in input mode, FileA, B, C in output mode

1.    Read File1     (Reads the record 10 )

2.    Read File2     (Reads the record 10 )

 

3.    Compare the Key Record of both Files  (File1-Rno = File 2-Rno).

a.      10 = 10; means record exists in both files)

b.    Write the  record in   FILE A

 

c.      As we need to advance further, repeat Step1  thru Step3

 

4.    When system reads the records  30 and 50, Step3 will Fail. So evaluate Step4

a.      If File1-Rno < File 2-Rno   (30 < 50)

b.      Record   30, which is > 20 and <50, means Rollno 30 is not present in FILE 2

c.      i.e., Record 30 exists only in File1

d.      Write the record into FILE B

e.      Now Read only FILE 1, and repeat thru step 3

 

5.    When system reads the records  70 and 60 from file1 and 2 respectively,  Step3,4 will Fail. So evaluate Step5

a.      If File1-Rno >  File 2-Rno   (70 > 50)

b.      Record  60 of file2, which is > 50 and <70, means Roll no 60 is not present in FILE 1

c.      i.e., Record 60 exists only in File2

d.      Write the record into FILE C

e.      Now Read only FILE 2, and repeat thru step 3

 

6.    Repeat above steps until end of both the files.

      Close all files

        

Advantages :  Open/close both file only once.

                        Faster


Comments

Joy said…
Thanks for the post

You can find some good Mainframe Techical Interview Question Answers on in the below link

Mainframe Interview Question Answers

Thanks
Joya
Freshers Jobs Chennai | Freshers Job Openings, Chennai Jobs, Government Jobs, Latest Jobs Chennai, MBA Jobs Chennai, IT Software Jobs Chennai, BPO jobs | Visit Automobile Jobs in Chennai

Popular posts from this blog

NULL VALUES and NULL INDICATORS in DB2

In DB2, the columns defined as NULL needs to be handled carefully else it will throw null exception error, in order to over come this error data type can be handled by using null indicator . NULL is stored using a special one-byte null indicator that is "attached" to every nullable column. If the column is set to NULL, then the indicator field is used to record this. Using NULL will never save space in a DB2 database design - in fact, it will always add an extra byte for every column that can be NULL. The byte is used whether or not the column is actually set to NULL. The indicator variable is transparent to an end user Consider below Table : Create Table SAMP_TAB SN CHAR (10) SNAME CHAR (10) STATUS CHAR (2) NOT NULL BY DEFAULT CITY CHAR (10) NOT NULL Note :: Unless you specify NOT NULL, the default is to allow for NULL In above table SN and SNAME columns holds null values by default, in order to handle these null variables we need to have NULL-INDICATORS declares in the Pro

Mainframe Written test @ Accenture

1. What r the 2 function we can get by using INSPECT verb? (c) A. file handling, error handling B. opening a file, closing a file. C. char counting, replacing. D. none of the above 2. Indicate which of the following is not true about the formal parameters in a subroutine? (c) A. every formal parameter must appear in the linkage section of the subroutine B. every formal parameter must appear in the using phrase of the procedure division header of the subroutine C. A formal parameter name can appear more than once in the using phrases of the procedure division header of the subroutine. D. A formal parameter can not be declared with value clause in a subroutine 3. What is the value of A? (B) 01 A pic 9(3). Move 100 to A. Perform 1000-para thru 1000-exit. Display the value of a=A Stop run. 1000-para. If A=100 Perform 1000-exit Else Move 150 to A End-if. Move 200 to A. 1000-exit. Exit. a.100 b.200 c.150 d. none of the above is correct. 4. What is the value of B? (A) Move 1 to A Evaluate tr

How to Solve SOC7 Abend - with screen shots

Below process helps to find out the statement, caused the SOC7 error. Check the Sysout of RUNJCL . This shows the error statement and lists offset value Take the Offset Value 000003C0 Got to respective Compilation Job listing, check the sysprint Search for the offset value 0003C0 (delete +00 -- initial 3 letters of Offset value and search for it) check below 2 screen shots This Offset value is listed under line no 0045 – which refers to Move statement. Take this no. 045 and find for it in same sysprint. This points to the exact statement, caused SOC7 T his 045 pints to the Move statement 1526, this is the exact line in the program Check for the above line no. In source program . This points to the statement highlighted below . Check the statement, variable check-4, which is added to check-6. These are having different Picture clause. check-4 is alfhanumaric, holding some junk data, when this data is moved to Chcek-6 variable(of comp-3) creates SOC7 error. This is just an example to e