The following shows how you can compare all fields in two
different asfiles with the same file layout.
The two asfiles cm1 and cm2 both use the cust_mstr file
definition.
cm1.cm_code = "IBT001";
sys.read_file(cm1,F_LOOKUP);
cm2.cm_code = "IBT002";
sys.read_file(cm2,F_LOOKUP);
while (1) {
if ((ret=sys.cmp_file(cm1,fldname1,val1,cm2,fldname2,val2))==0)
break; /* no more different fields */
if (ret == -1) {
sys.err_msg("Incompatible rcd types");
sys.err_msg("cmp failed",fldname1,val1,fldname2,val2);
break;
}
sys.err_msg("cmp failed",fldname1,val1,fldname2,val2);
/* make next cmp ok on this fld - may not work as expected
* due to fldname1 overflowing the display format
*/
sys.put_fmtfield("cm2",fldname2,val1);
}
The following is another way of doing the same thing, except sys.copy_fields()
is used instead of sys.put_fmtfield()
This is more accurate since sys.put_fmtfield() will not always make
the value of fldname2 equal to the value of fldname1 due to the
value not fitting in the display format.
cm1.cm_code = "IBT001";
sys.read_file(cm1,F_LOOKUP);
cm2.cm_code = "IBT002";
sys.read_file(cm2,F_LOOKUP);
while (1) {
if ((ret=sys.cmp_file(cm1,fldname1,val1,cm2,fldname2,val2))==0)
break; /* no more different fields */
if (ret == -1) {
sys.err_msg("Incompatible rcd types");
sys.err_msg("cmp failed",fldname1,val1,fldname2,val2);
break;
}
sys.err_msg("cmp failed",fldname1,val1,fldname2,val2);
/* make next cmp ok on this fld */
fldidx = sys.get_cdef(cm1,fldname1);
sys.copy_fields(cm1,fldidx,cm2,fldidx,1);
}