View previous topic :: View next topic |
Author |
Message |
shuko Beginner
Joined: 08 Nov 2005 Posts: 73 Topics: 20
|
Posted: Wed Nov 12, 2008 3:11 pm Post subject: COBOL compare two internal tables |
|
|
Hello
I have two internal tables and I want to compare these two tables
If the name and value in both the tables and the Tab1Count and Tab2Count are also the same then set Flag = Y.
If Table 1 does not match Table 2 either because difference in
Name and/or values or the Tab1count and Tab2Count are different
then set the Flag =N and just display the difference in Name and Value
The Tab1Count/Tab2Count will not be larger than 500. Is it better to have
a binary or sequential search?
In Table 1 the tab1Count = 100 (could be more or less)
Code: |
move space to Flag
PERFORM WITH TEST BEFORE
VARYING n1 FROM 1 BY 1 UNTIL
n1 > Tab1Count
DISPLAY n1 ') '
NAME_TAB1 (n1)
VALUE_TAB1 (n1)
END-PERFORM
|
In Table 2 the tab2Count = 100 (could be more or less)
Code: |
PERFORM WITH TEST BEFORE
VARYING n2 FROM 1 BY 1 UNTIL
n2 > Tab2Count
DISPLAY n2 ') '
NAME_TAB2 (n2)
VALUE_TAB2 (n2)
END-PERFORM
|
Thank you |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Thu Nov 13, 2008 12:27 am Post subject: |
|
|
I'm not sure what you're trying to do but comparing Tab1Count to Tab2Count will immediately tell you if you've met one of your criteria. Set the flag to N and you're done. If the counts are equal, I guess you'd want to sequentially go through each table at the same time comparing name and value of Table 1 to name and value of Table 2. If you get an "unequal" before end of tables, your flag will be set to N, otherwise Y. Binary or sequential searches don't enter the picture. _________________ ....Terry |
|
Back to top |
|
|
shuko Beginner
Joined: 08 Nov 2005 Posts: 73 Topics: 20
|
Posted: Thu Nov 13, 2008 5:07 am Post subject: |
|
|
To set the flag to Y when the Tab1Count and the Tab2Count are the same is easy.
It could be possible that the Tab1Count and Tab2count are the same but the Name and/or values are different or the Table1 will have
more names and values than Table2 or vice versa.
What I want to do is, consider Table1 as the master table and compare it with table2. If any of the names and or Values in Table1 are different to that in Table2 then just display the missing names/values in Table1 and Table2 if any.
Is it possible to have a code example for this.
Thank you |
|
Back to top |
|
|
Dibakar Advanced
Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Thu Nov 13, 2008 7:21 am Post subject: |
|
|
If table1 is
and table2 is
would you consider them same or different? |
|
Back to top |
|
|
shuko Beginner
Joined: 08 Nov 2005 Posts: 73 Topics: 20
|
Posted: Thu Nov 13, 2008 9:32 am Post subject: |
|
|
I would consider your example to be the same. I have a few examples here
Example 1
Code: |
Table1
Name Value
-----------------------
Bill XY
John YZ
Table 2
Name value
------------------------
John YZ
Bill XY
|
Example 1 is the same
Example 2
Code: |
Table 1
Name value
Bill XY
John YZ
Table 2
Name value
Sharon XY
John YZ
|
Example 2 is different
Example 3
Code: |
Table1
Name value
Bill XY
John YZ
Jeremy AB
Table 2
Name value
Bill XY
John YZ
|
Example 3 is also different. |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Thu Nov 13, 2008 10:50 am Post subject: |
|
|
Given those rules, both internal tables must be in the same sequence. If they are loaded at run time, sort the source of them before loading them in your program, or use an internal sort (bubble, shell, or whatever) to sort them after they've been loaded. Then proceed to compare identical occurrences as I initially mentioned. You can get by without the sort (with more effort and less efficiency) by sequentially going through Table 1 and "looking" for a match in Table 2, then flagging both occurrences when a match is found. For that method you'll need an additional field in each of the tables to hold your flags so you can check at the end to see if ALL occurrences in Table 1 found a match in Table 2 without reusing a Table 2 occurrence. _________________ ....Terry |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Nov 13, 2008 1:07 pm Post subject: |
|
|
Ideally I would load only 1 table(ordered by the key) and while loading the second internal table I would perform a search on table 1 and if found I would update the flags itself while loading the second table.
Kolusu |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Thu Nov 13, 2008 10:23 pm Post subject: |
|
|
Out of curiousity, what is the source of these 2 tables? Are they loaded dynamically from files? If so, why can't you do your comparison before your program loads them into internal tables? If you require the internal tables, what do you do with them after your compare criteria is done? Maybe there's a better approach to accomplish your task. _________________ ....Terry |
|
Back to top |
|
|
shuko Beginner
Joined: 08 Nov 2005 Posts: 73 Topics: 20
|
Posted: Fri Nov 14, 2008 2:23 am Post subject: |
|
|
The information for these two tables are got from two seperate Modules
in the main program. The main program has to do this comparison and reach a decision. |
|
Back to top |
|
|
shuko Beginner
Joined: 08 Nov 2005 Posts: 73 Topics: 20
|
Posted: Sun Nov 16, 2008 7:27 am Post subject: |
|
|
I have a solution now. I search the contents of table1 with Table2 and vice versa and set the flag accordingly.
Thank you |
|
Back to top |
|
|
|
|